Skip to content

Commit

Permalink
Merge pull request #1340 from Drakkar-Software/dev
Browse files Browse the repository at this point in the history
Dev merge
  • Loading branch information
GuillaumeDSM authored Aug 25, 2024
2 parents 7c5a61c + e3518b5 commit 0fe5786
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Trading/Exchange/binance/binance_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -291,8 +293,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] = \
Expand Down
20 changes: 9 additions & 11 deletions Trading/Exchange/okx/okx_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0fe5786

Please sign in to comment.