From 4ef45314ddde0f4d5ab02ef1d56694d3f4a228c4 Mon Sep 17 00:00:00 2001 From: "Jakub Werner (jakubikan)" Date: Fri, 22 Mar 2024 20:18:52 +0100 Subject: [PATCH] JW: adding first draft for deslist schedule --- freqtrade/exchange/binance.py | 41 ++++++++++++++++++++++++++++++++++ tests/exchange/test_binance.py | 8 +++++++ 2 files changed, 49 insertions(+) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index 89b983d91..def3b91a8 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -217,3 +217,44 @@ class Binance(Exchange): raise OperationalException(e) from e else: return {} + + def get_spot_delist_schedule(self, refresh: bool) -> list: + """ + Calculates bid/ask target + bid rate - between current ask price and last price + ask rate - either using ticker bid or first bid based on orderbook + or remain static in any other case since it's not updating. + :param pair: Pair to get rate for + :param refresh: allow cached data + :param side: "buy" or "sell" + :return: float: Price + :raises PricingError if orderbook price could not be determined. + """ + if not refresh: + with self._cache_lock: + rate = cache_rate.get(pair) + # Check if cache has been invalidated + if rate: + logger.debug(f"Using cached {side} rate for {pair}.") + return rate + + + if conf_strategy.get('use_order_book', False): + + order_book_top = conf_strategy.get('order_book_top', 1) + if order_book is None: + order_book = self.fetch_l2_order_book(pair, order_book_top) + rate = self._get_rate_from_ob(pair, side, order_book, name, price_side, + order_book_top) + else: + logger.debug(f"Using Last {price_side.capitalize()} / Last Price") + if ticker is None: + 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 delistings \ No newline at end of file diff --git a/tests/exchange/test_binance.py b/tests/exchange/test_binance.py index 625033645..ac87c0ca3 100644 --- a/tests/exchange/test_binance.py +++ b/tests/exchange/test_binance.py @@ -617,3 +617,11 @@ def test_get_maintenance_ratio_and_amt_binance( exchange._leverage_tiers = leverage_tiers (result_ratio, result_amt) = exchange.get_maintenance_ratio_and_amt(pair, nominal_value) assert (round(result_ratio, 8), round(result_amt, 8)) == (mm_ratio, amt) + + +def test_get_spot_delist_schedule(mocker, default_conf) -> None: + exchange = get_patched_exchange(mocker, default_conf, id='binance') + exchange._api.sapi_get_spot_delist_schedule = get_mock_coro([{'delistTime': '1712113200000', 'symbols': ['DREPBTC', 'DREPUSDT', 'MOBBTC', 'MOBUSDT', 'PNTUSDT']}]) + + + assert exchange.get_spot_delist_schedule(True) == ['DREP/BTC', 'DREP/USDT', 'MOB/BTC', 'MOB/USDT', 'PNT/USDT'] \ No newline at end of file