From 00be2f29bca5d4548925165726c9323c9ecd0ee5 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Thu, 22 Aug 2024 19:47:02 +0200 Subject: [PATCH 1/2] [OKX] update leverage parser --- Trading/Exchange/binance/binance_exchange.py | 2 -- Trading/Exchange/okx/okx_exchange.py | 20 +++++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Trading/Exchange/binance/binance_exchange.py b/Trading/Exchange/binance/binance_exchange.py index c8d5c3942..14a9ca660 100644 --- a/Trading/Exchange/binance/binance_exchange.py +++ b/Trading/Exchange/binance/binance_exchange.py @@ -291,8 +291,6 @@ def parse_position(self, fixed, force_empty=False, **kwargs): return None def parse_leverage(self, fixed, **kwargs): - # WARNING no CCXT standard leverage parsing logic - # HAS TO BE IMPLEMENTED IN EACH EXCHANGE IMPLEMENTATION parsed = super().parse_leverage(fixed, **kwargs) # on binance fixed is a parsed position parsed[trading_enums.ExchangeConstantsLeveragePropertyColumns.LEVERAGE.value] = \ diff --git a/Trading/Exchange/okx/okx_exchange.py b/Trading/Exchange/okx/okx_exchange.py index 797fa437c..c2ee21099 100644 --- a/Trading/Exchange/okx/okx_exchange.py +++ b/Trading/Exchange/okx/okx_exchange.py @@ -22,6 +22,7 @@ import octobot_trading.constants as constants import octobot_trading.errors as trading_errors import octobot_trading.exchanges.connectors.ccxt.enums as ccxt_enums +import octobot_trading.exchanges.connectors.ccxt.constants as ccxt_constants import octobot_trading.exchanges.connectors.ccxt.ccxt_connector as ccxt_connector import octobot_trading.personal_data as trading_personal_data @@ -412,12 +413,12 @@ async def get_position(self, symbol: str, **kwargs: dict) -> dict: async def _update_position_with_leverage_data(self, symbol, position): leverage_data = await self.get_symbol_leverage(symbol) - raw_data = leverage_data[trading_enums.ExchangeConstantsLeveragePropertyColumns.RAW.value] adapter = self.connector.adapter + OKX_info = leverage_data[ccxt_constants.CCXT_INFO] position[trading_enums.ExchangeConstantsPositionColumns.POSITION_MODE.value] = \ - adapter.parse_position_mode(raw_data[adapter.OKX_POS_SIDE]) + adapter.parse_position_mode(OKX_info[0][adapter.OKX_POS_SIDE]) position[trading_enums.ExchangeConstantsPositionColumns.MARGIN_TYPE.value] = \ - adapter.parse_margin_type(raw_data[adapter.OKX_MARGIN_MODE]) + adapter.parse_margin_type(leverage_data[ccxt_enums.ExchangeLeverageCCXTColumns.MARGIN_MODE.value]) position[trading_enums.ExchangeConstantsPositionColumns.LEVERAGE.value] = \ leverage_data[trading_enums.ExchangeConstantsLeveragePropertyColumns.LEVERAGE.value] @@ -530,16 +531,13 @@ def parse_position_mode(self, position_mode): return trading_enums.PositionMode.HEDGE def parse_leverage(self, fixed, **kwargs): - # WARNING no CCXT standard leverage parsing logic - # HAS TO BE IMPLEMENTED IN EACH EXCHANGE IMPLEMENTATION - fixed = fixed[self.DATA][0] # okx is returning a list, use the 1 element only fixed = super().parse_leverage(fixed, **kwargs) + leverages = [ + fixed[ccxt_enums.ExchangeLeverageCCXTColumns.LONG_LEVERAGE.value], + fixed[ccxt_enums.ExchangeLeverageCCXTColumns.SHORT_LEVERAGE.value], + ] fixed[trading_enums.ExchangeConstantsLeveragePropertyColumns.LEVERAGE.value] = \ - self.safe_decimal( - fixed[trading_enums.ExchangeConstantsLeveragePropertyColumns.RAW.value], - self.OKX_LEVER, - constants.DEFAULT_SYMBOL_LEVERAGE, - ) + decimal.Decimal(str(leverages[0] or leverages[1])) return fixed def parse_funding_rate(self, fixed, from_ticker=False, **kwargs): From e3518b5bc2725a815e444b6b7c98e3a984623da9 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Sun, 25 Aug 2024 17:24:37 +0200 Subject: [PATCH 2/2] [Binance] set SUPPORTS_CUSTOM_LIMIT_ORDER_BOOK_FETCH --- Trading/Exchange/binance/binance_exchange.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Trading/Exchange/binance/binance_exchange.py b/Trading/Exchange/binance/binance_exchange.py index 14a9ca660..ea581b5ae 100644 --- a/Trading/Exchange/binance/binance_exchange.py +++ b/Trading/Exchange/binance/binance_exchange.py @@ -37,6 +37,8 @@ class Binance(exchanges.RestExchange): SUPPORTS_SET_MARGIN_TYPE_ON_OPEN_POSITIONS = False # set False when the exchange refuses to change margin type # when an associated position is open # binance {"code":-4048,"msg":"Margin type cannot be changed if there exists position."} + # Set True when the "limit" param when fetching order books is taken into account + SUPPORTS_CUSTOM_LIMIT_ORDER_BOOK_FETCH = True # should be overridden locally to match exchange support SUPPORTED_ELEMENTS = {