Use generator to generate sell price scaffold testing
This commit is contained in:
parent
e1cb6f4ae3
commit
8edc3eb5fb
@ -619,6 +619,15 @@ class FreqtradeBot:
|
||||
|
||||
return trades_closed
|
||||
|
||||
def _order_book_gen(self, pair: str, side: str, order_book_max: int = 1,
|
||||
order_book_min: int = 1):
|
||||
"""
|
||||
Helper generator to query orderbook in loop (used for early sell-order placing)
|
||||
"""
|
||||
order_book = self.exchange.get_order_book(pair, order_book_max)
|
||||
for i in range(order_book_min, order_book_max + 1):
|
||||
yield order_book[side][i - 1][0]
|
||||
|
||||
def get_sell_rate(self, pair: str, refresh: bool) -> float:
|
||||
"""
|
||||
Get sell rate - either using get-ticker bid or first bid based on orderbook
|
||||
@ -639,9 +648,10 @@ class FreqtradeBot:
|
||||
config_ask_strategy = self.config.get('ask_strategy', {})
|
||||
if config_ask_strategy.get('use_order_book', False):
|
||||
logger.debug('Using order book to get sell rate')
|
||||
rate = next(self._order_book_gen(pair, f"{config_ask_strategy['price_side']}s"))
|
||||
|
||||
order_book = self.exchange.get_order_book(pair, 1)
|
||||
rate = order_book[f"{config_ask_strategy['price_side']}s"][0][0]
|
||||
# order_book = self.exchange.get_order_book(pair, 1)
|
||||
# rate = order_book[f"{config_ask_strategy['price_side']}s"][0][0]
|
||||
|
||||
else:
|
||||
rate = self.exchange.fetch_ticker(pair)[config_ask_strategy['price_side']]
|
||||
@ -674,12 +684,12 @@ class FreqtradeBot:
|
||||
order_book_min = config_ask_strategy.get('order_book_min', 1)
|
||||
order_book_max = config_ask_strategy.get('order_book_max', 1)
|
||||
|
||||
order_book = self.exchange.get_order_book(trade.pair, order_book_max)
|
||||
|
||||
order_book = self._order_book_gen(trade.pair, f"{config_ask_strategy['price_side']}s",
|
||||
order_book_min=order_book_min,
|
||||
order_book_max=order_book_max)
|
||||
for i in range(order_book_min, order_book_max + 1):
|
||||
order_book_rate = order_book['asks'][i - 1][0]
|
||||
logger.debug(' order book asks top %s: %0.8f', i, order_book_rate)
|
||||
sell_rate = order_book_rate
|
||||
sell_rate = next(order_book)
|
||||
logger.debug(' order book asks top %s: %0.8f', i, sell_rate)
|
||||
|
||||
if self._check_and_execute_sell(trade, sell_rate, buy, sell):
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user