Extract get_rate_from_ticker from get_rate method

This commit is contained in:
Matthias
2023-05-29 17:27:11 +02:00
parent f074383d6a
commit af1dbf7dff
+16 -8
View File
@@ -1669,12 +1669,26 @@ class Exchange:
order_book_top = conf_strategy.get('order_book_top', 1) order_book_top = conf_strategy.get('order_book_top', 1)
if order_book is None: if order_book is None:
order_book = self.fetch_l2_order_book(pair, order_book_top) order_book = self.fetch_l2_order_book(pair, order_book_top)
rate = self.get_rate_from_ob(pair, side, order_book, name, price_side, rate = self._get_rate_from_ob(pair, side, order_book, name, price_side,
order_book_top) order_book_top)
else: else:
logger.debug(f"Using Last {price_side_word} / Last Price") logger.debug(f"Using Last {price_side_word} / Last Price")
if ticker is None: if ticker is None:
ticker = self.fetch_ticker(pair) ticker = self.fetch_ticker(pair)
rate = self._get_rate_from_ticker(side, ticker, conf_strategy, price_side)
if rate is None:
raise PricingError(f"{name}-Rate for {pair} was empty.")
with self._cache_lock:
cache_rate[pair] = rate
return rate
def _get_rate_from_ticker(self, side: EntryExit, ticker: Ticker, conf_strategy: Dict[str, Any],
price_side: BidAsk) -> Optional[float]:
"""
Get rate from ticker.
"""
ticker_rate = ticker[price_side] ticker_rate = ticker[price_side]
if ticker['last'] and ticker_rate: if ticker['last'] and ticker_rate:
if side == 'entry' and ticker_rate > ticker['last']: if side == 'entry' and ticker_rate > ticker['last']:
@@ -1684,15 +1698,9 @@ class Exchange:
balance = conf_strategy.get('price_last_balance', 0.0) balance = conf_strategy.get('price_last_balance', 0.0)
ticker_rate = ticker_rate - balance * (ticker_rate - ticker['last']) ticker_rate = ticker_rate - balance * (ticker_rate - ticker['last'])
rate = ticker_rate rate = ticker_rate
if rate is None:
raise PricingError(f"{name}-Rate for {pair} was empty.")
with self._cache_lock:
cache_rate[pair] = rate
return rate return rate
def get_rate_from_ob(self, pair: str, side: EntryExit, order_book: OrderBook, name: str, def _get_rate_from_ob(self, pair: str, side: EntryExit, order_book: OrderBook, name: str,
price_side: BidAsk, order_book_top: int) -> float: price_side: BidAsk, order_book_top: int) -> float:
""" """
Get rate from orderbook Get rate from orderbook