@@ -634,27 +634,21 @@ def _determine_reduce_only_str(self, order: Order) -> str | None:
634
634
def _get_position_side_from_position_id (
635
635
self ,
636
636
position_id : PositionId | None ,
637
+ exec_spawn_id : ClientOrderId | None ,
637
638
) -> BinanceFuturesPositionSide | None :
638
- """
639
- Parse the position side from the position ID.
640
-
641
- Parameters
642
- ----------
643
- position_id : PositionId | None
644
- The position ID, can be `None`.
645
- Position ID must end with either 'LONG' or 'SHORT' for Binance Futures Hedge position mode.
646
-
647
- Returns
648
- -------
649
- BinanceFuturesPositionSide | None
639
+ # Position ID must end with either 'LONG', 'SHORT' or 'BOTH' for Binance Futures Hedge position mode
650
640
651
- """
652
641
position_side = None
653
642
if self ._binance_account_type .is_spot_or_margin : # Spot or Margin mode
654
643
return position_side
655
644
elif not self ._is_dual_side_position : # One-way position mode
656
645
return BinanceFuturesPositionSide .BOTH
657
646
647
+ if position_id is None and exec_spawn_id is not None :
648
+ primary_order = self ._cache .order (exec_spawn_id )
649
+ if primary_order is not None :
650
+ position_id = primary_order .position_id
651
+
658
652
# For Binance Futures Hedge mode, the position side must be specified in the position_id
659
653
PyCondition .not_none (position_id , "position_id" )
660
654
position_side = self ._enum_parser .parse_position_id_to_binance_futures_position_side (
@@ -670,7 +664,10 @@ def _get_position_side_from_position_id(
670
664
return position_side
671
665
672
666
async def _submit_order (self , command : SubmitOrder ) -> None :
673
- position_side = self ._get_position_side_from_position_id (command .position_id )
667
+ position_side = self ._get_position_side_from_position_id (
668
+ position_id = command .position_id ,
669
+ exec_spawn_id = command .order .exec_spawn_id ,
670
+ )
674
671
await self ._submit_order_inner (command .order , position_side )
675
672
676
673
async def _submit_order_inner (
@@ -790,7 +787,11 @@ async def _submit_stop_limit_order(
790
787
)
791
788
792
789
async def _submit_order_list (self , command : SubmitOrderList ) -> None :
793
- position_side = self ._get_position_side_from_position_id (command .position_id )
790
+ position_side = self ._get_position_side_from_position_id (
791
+ position_id = command .position_id ,
792
+ exec_spawn_id = None ,
793
+ )
794
+
794
795
for order in command .order_list .orders :
795
796
self .generate_order_submitted (
796
797
strategy_id = order .strategy_id ,
0 commit comments