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
|
from typing import Dict, List, Tuple
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
|
import pandas as pd
|
||||||
from pandas import DataFrame, to_datetime
|
from pandas import DataFrame, to_datetime
|
||||||
|
|
||||||
from freqtrade import constants
|
from freqtrade import constants
|
||||||
@ -269,3 +270,30 @@ class Analyze(object):
|
|||||||
return roi_rate
|
return roi_rate
|
||||||
break
|
break
|
||||||
return sell_rate
|
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
|
limit = limitx
|
||||||
break
|
break
|
||||||
|
|
||||||
return _API.fetch_order_book(pair, limit)
|
return _API.fetch_l2_order_book(pair, limit)
|
||||||
except ccxt.NotSupported as e:
|
except ccxt.NotSupported as e:
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f'Exchange {_API.name} does not support fetching order book.'
|
f'Exchange {_API.name} does not support fetching order book.'
|
||||||
|
@ -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):
|
if 'ask_strategy' in self.config and self.config['ask_strategy'].get('use_book_order', False):
|
||||||
logger.info('Using order book for selling...')
|
logger.info('Using order book for selling...')
|
||||||
|
|
||||||
# logger.debug('Order book %s',orderBook)
|
# logger.debug('Order book %s',orderBook)
|
||||||
orderBook_min = self.config['ask_strategy']['book_order_min']
|
orderBook_min = self.config['ask_strategy'].get('book_order_min', 1)
|
||||||
orderBook_max = self.config['ask_strategy']['book_order_max']
|
orderBook_max = self.config['ask_strategy'].get('book_order_max', 1)
|
||||||
|
|
||||||
orderBook = exchange.get_order_book(trade.pair, orderBook_max)
|
orderBook = exchange.get_order_book(trade.pair, orderBook_max)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user