@@ -788,20 +788,17 @@ async def set_position_tpsl(
788788
789789 # Add take profit order if specified
790790 if tp_px is not None :
791- # For TP orders, use tick-aligned aggressive price
792- # If closing long (sell), use very low price; if closing short (buy), use very high price
793- slippage = 0.5 # 50% slippage for very aggressive pricing
794- aggressive_px = self ._slippage_price (coin , not is_long , slippage )
795-
791+ # For TP orders, use limit order at trigger price
792+ # This ensures the order fills at or better than the TP price
796793 tp_order = {
797794 "coin" : coin ,
798795 "is_buy" : not is_long ,
799796 "sz" : float (position_size ),
800- "limit_px" : aggressive_px , # Tick-aligned aggressive price for market execution
797+ "limit_px" : float ( tp_px ) , # Limit price = trigger price for TP
801798 "order_type" : {
802799 "trigger" : {
803800 "triggerPx" : float (tp_px ),
804- "isMarket" : True ,
801+ "isMarket" : False , # Use limit order for TP
805802 "tpsl" : "tp" ,
806803 }
807804 },
@@ -812,19 +809,17 @@ async def set_position_tpsl(
812809
813810 # Add stop loss order if specified
814811 if sl_px is not None :
815- # For SL orders, use tick-aligned aggressive price
816- slippage = 0.5 # 50% slippage for very aggressive pricing
817- aggressive_px = self ._slippage_price (coin , not is_long , slippage )
818-
812+ # For SL orders, use market order for fast execution
813+ # No limit_px needed when isMarket=True
819814 sl_order = {
820815 "coin" : coin ,
821816 "is_buy" : not is_long ,
822817 "sz" : float (position_size ),
823- "limit_px" : aggressive_px , # Tick-aligned aggressive price for market execution
818+ "limit_px" : float ( sl_px ) , # Use trigger price as limit_px
824819 "order_type" : {
825820 "trigger" : {
826821 "triggerPx" : float (sl_px ),
827- "isMarket" : True ,
822+ "isMarket" : True , # Use market order for SL
828823 "tpsl" : "sl" ,
829824 }
830825 },
0 commit comments