mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-04-30 14:12:13 +00:00
Extract get_rate_from_ticker from get_rate method
This commit is contained in:
@@ -1669,21 +1669,13 @@ 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)
|
||||||
ticker_rate = ticker[price_side]
|
rate = self._get_rate_from_ticker(side, ticker, conf_strategy, price_side)
|
||||||
if ticker['last'] and ticker_rate:
|
|
||||||
if side == 'entry' and ticker_rate > ticker['last']:
|
|
||||||
balance = conf_strategy.get('price_last_balance', 0.0)
|
|
||||||
ticker_rate = ticker_rate + balance * (ticker['last'] - ticker_rate)
|
|
||||||
elif side == 'exit' and ticker_rate < ticker['last']:
|
|
||||||
balance = conf_strategy.get('price_last_balance', 0.0)
|
|
||||||
ticker_rate = ticker_rate - balance * (ticker_rate - ticker['last'])
|
|
||||||
rate = ticker_rate
|
|
||||||
|
|
||||||
if rate is None:
|
if rate is None:
|
||||||
raise PricingError(f"{name}-Rate for {pair} was empty.")
|
raise PricingError(f"{name}-Rate for {pair} was empty.")
|
||||||
@@ -1692,8 +1684,24 @@ class Exchange:
|
|||||||
|
|
||||||
return rate
|
return rate
|
||||||
|
|
||||||
def get_rate_from_ob(self, pair: str, side: EntryExit, order_book: OrderBook, name: str,
|
def _get_rate_from_ticker(self, side: EntryExit, ticker: Ticker, conf_strategy: Dict[str, Any],
|
||||||
price_side: BidAsk, order_book_top: int) -> float:
|
price_side: BidAsk) -> Optional[float]:
|
||||||
|
"""
|
||||||
|
Get rate from ticker.
|
||||||
|
"""
|
||||||
|
ticker_rate = ticker[price_side]
|
||||||
|
if ticker['last'] and ticker_rate:
|
||||||
|
if side == 'entry' and ticker_rate > ticker['last']:
|
||||||
|
balance = conf_strategy.get('price_last_balance', 0.0)
|
||||||
|
ticker_rate = ticker_rate + balance * (ticker['last'] - ticker_rate)
|
||||||
|
elif side == 'exit' and ticker_rate < ticker['last']:
|
||||||
|
balance = conf_strategy.get('price_last_balance', 0.0)
|
||||||
|
ticker_rate = ticker_rate - balance * (ticker_rate - ticker['last'])
|
||||||
|
rate = ticker_rate
|
||||||
|
return rate
|
||||||
|
|
||||||
|
def _get_rate_from_ob(self, pair: str, side: EntryExit, order_book: OrderBook, name: str,
|
||||||
|
price_side: BidAsk, order_book_top: int) -> float:
|
||||||
"""
|
"""
|
||||||
Get rate from orderbook
|
Get rate from orderbook
|
||||||
:raises: PricingError if rate could not be determined.
|
:raises: PricingError if rate could not be determined.
|
||||||
|
|||||||
Reference in New Issue
Block a user