book order preparation for strategy use
This commit is contained in:
parent
9813c3c039
commit
66ed99cf3c
@ -7,6 +7,7 @@ from enum import Enum
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
import arrow
|
||||
import pandas as pd
|
||||
from pandas import DataFrame, to_datetime
|
||||
|
||||
from freqtrade import constants
|
||||
@ -269,3 +270,30 @@ class Analyze(object):
|
||||
return roi_rate
|
||||
break
|
||||
return sell_rate
|
||||
|
||||
def order_book_to_dataframe(data: list) -> DataFrame:
|
||||
"""
|
||||
Gets order book list, returns dataframe with below format
|
||||
-------------------------------------------------------------------
|
||||
bids b_size a_sum asks a_size a_sum
|
||||
-------------------------------------------------------------------
|
||||
"""
|
||||
cols = ['bids', 'b_size']
|
||||
bids_frame = DataFrame(data['bids'], columns=cols)
|
||||
# add cumulative sum column
|
||||
bids_frame['b_sum'] = bids_frame['b_size'].cumsum()
|
||||
cols2 = ['asks', 'a_size']
|
||||
asks_frame = DataFrame(data['asks'], columns=cols2)
|
||||
# add cumulative sum column
|
||||
asks_frame['a_sum'] = asks_frame['a_size'].cumsum()
|
||||
|
||||
frame = pd.concat([bids_frame['b_sum'], bids_frame['b_size'], bids_frame['bids'], \
|
||||
asks_frame['asks'], asks_frame['a_size'], asks_frame['a_sum']], axis=1, \
|
||||
keys=['b_sum', 'b_size', 'bids', 'asks', 'a_size', 'a_sum'])
|
||||
|
||||
return frame
|
||||
|
||||
def order_book_dom() -> DataFrame:
|
||||
# https://stackoverflow.com/questions/36835793/pandas-group-by-consecutive-ranges
|
||||
return DataFrame
|
||||
|
||||
|
@ -254,7 +254,7 @@ def get_order_book(pair: str, limit: Optional[int] = 100) -> dict:
|
||||
limit = limitx
|
||||
break
|
||||
|
||||
return _API.fetch_order_book(pair, limit)
|
||||
return _API.fetch_l2_order_book(pair, limit)
|
||||
except ccxt.NotSupported as e:
|
||||
raise OperationalException(
|
||||
f'Exchange {_API.name} does not support fetching order book.'
|
||||
|
@ -264,7 +264,7 @@ class FreqtradeBot(object):
|
||||
if 'use_book_order' in self.config['bid_strategy'] and self.config['bid_strategy'].get('use_book_order', False):
|
||||
logger.info('Getting price from Order Book')
|
||||
orderBook_top = self.config.get('bid_strategy', {}).get('book_order_top', 1)
|
||||
orderBook = exchange.get_order_book(pair, orderBook_top)
|
||||
orderBook = exchange.get_order_book(pair, orderBook_top)
|
||||
# top 1 = index 0
|
||||
orderBook_rate = orderBook['bids'][orderBook_top - 1][0]
|
||||
orderBook_rate = orderBook_rate + 0.00000001
|
||||
@ -476,10 +476,9 @@ with limit `{buy_limit:.8f} ({stake_amount:.6f} \
|
||||
|
||||
if 'ask_strategy' in self.config and self.config['ask_strategy'].get('use_book_order', False):
|
||||
logger.info('Using order book for selling...')
|
||||
|
||||
# logger.debug('Order book %s',orderBook)
|
||||
orderBook_min = self.config['ask_strategy']['book_order_min']
|
||||
orderBook_max = self.config['ask_strategy']['book_order_max']
|
||||
orderBook_min = self.config['ask_strategy'].get('book_order_min', 1)
|
||||
orderBook_max = self.config['ask_strategy'].get('book_order_max', 1)
|
||||
|
||||
orderBook = exchange.get_order_book(trade.pair, orderBook_max)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user