@@ -273,18 +273,33 @@ def parse_position(self, fixed, force_empty=False, **kwargs):
273273 # CCXT standard position parsing logic
274274 # if mode is enums.PositionMode.ONE_WAY:
275275 original_side = fixed .get (ccxt_enums .ExchangePositionCCXTColumns .SIDE .value )
276- position_side = enums .PositionSide .BOTH
277- # todo when handling cross positions
278- # side = fixed.get(ccxt_enums.ExchangePositionCCXTColumns.SIDE.value, enums.PositionSide.UNKNOWN.value)
279- # position_side = enums.PositionSide.LONG \
280- # if side == enums.PositionSide.LONG.value else enums.PositionSide.
281276 symbol = fixed .get (ccxt_enums .ExchangePositionCCXTColumns .SYMBOL .value )
282277 contract_size = decimal .Decimal (str (fixed .get (ccxt_enums .ExchangePositionCCXTColumns .CONTRACT_SIZE .value , 0 )))
283278 contracts = constants .ZERO if force_empty \
284279 else decimal .Decimal (str (fixed .get (ccxt_enums .ExchangePositionCCXTColumns .CONTRACTS .value , 0 )))
285280 is_empty = contracts == constants .ZERO
281+ position_mode = (
282+ enums .PositionMode .HEDGE if fixed .get (ccxt_enums .ExchangePositionCCXTColumns .HEDGED .value , False )
283+ else enums .PositionMode .ONE_WAY
284+ )
285+ if position_mode is enums .PositionMode .HEDGE :
286+ # todo when handling helge positions
287+ side = fixed .get (ccxt_enums .ExchangePositionCCXTColumns .SIDE .value , enums .PositionSide .UNKNOWN .value )
288+ position_side = enums .PositionSide .LONG \
289+ if side == enums .PositionSide .LONG .value else enums .PositionSide .SHORT
290+ log_func = self .logger .debug
291+ if is_empty :
292+ log_func = self .logger .error
293+ log_func (f"Unhandled { symbol } position mode ({ position_mode .value } ). This position can't be traded." )
294+ else :
295+ # One way position use BOTH side as there is always only one position per symbol.
296+ # This position can turn long and short
297+ position_side = enums .PositionSide .BOTH
286298 liquidation_price = fixed .get (ccxt_enums .ExchangePositionCCXTColumns .LIQUIDATION_PRICE .value , 0 )
287- if margin_type := fixed .get (ccxt_enums .ExchangePositionCCXTColumns .MARGIN_TYPE .value , None ):
299+ if margin_type := fixed .get (
300+ ccxt_enums .ExchangePositionCCXTColumns .MARGIN_TYPE .value ,
301+ fixed .get (ccxt_enums .ExchangePositionCCXTColumns .MARGIN_MODE .value , None ) # can also be contained in margin mode
302+ ):
288303 margin_type = enums .MarginType (margin_type )
289304 if force_empty or liquidation_price is None :
290305 liquidation_price = constants .NaN
@@ -306,9 +321,7 @@ def parse_position(self, fixed, force_empty=False, **kwargs):
306321 enums .ExchangeConstantsPositionColumns .LEVERAGE .value :
307322 self .safe_decimal (fixed , ccxt_enums .ExchangePositionCCXTColumns .LEVERAGE .value ,
308323 constants .DEFAULT_SYMBOL_LEVERAGE ),
309- enums .ExchangeConstantsPositionColumns .POSITION_MODE .value : None if is_empty else
310- enums .PositionMode .HEDGE if fixed .get (ccxt_enums .ExchangePositionCCXTColumns .HEDGED .value , True )
311- else enums .PositionMode .ONE_WAY ,
324+ enums .ExchangeConstantsPositionColumns .POSITION_MODE .value : position_mode ,
312325 # next values are always 0 when the position empty (0 contracts)
313326 enums .ExchangeConstantsPositionColumns .COLLATERAL .value : constants .ZERO if is_empty else
314327 decimal .Decimal (
@@ -319,6 +332,7 @@ def parse_position(self, fixed, force_empty=False, **kwargs):
319332 enums .ExchangeConstantsPositionColumns .INITIAL_MARGIN .value : constants .ZERO if is_empty else
320333 decimal .Decimal (
321334 f"{ fixed .get (ccxt_enums .ExchangePositionCCXTColumns .INITIAL_MARGIN .value , 0 ) or 0 } " ),
335+ enums .ExchangeConstantsPositionColumns .AUTO_DEPOSIT_MARGIN .value : False , # default value
322336 enums .ExchangeConstantsPositionColumns .UNREALIZED_PNL .value : constants .ZERO if is_empty else
323337 decimal .Decimal (
324338 f"{ fixed .get (ccxt_enums .ExchangePositionCCXTColumns .UNREALISED_PNL .value , 0 ) or 0 } " ),
0 commit comments