@@ -203,3 +203,63 @@ async def test_ws_futures_create_cancel_algo_order(futuresClientAsync):
203203 )
204204
205205 assert cancel_result ["algoId" ] == order ["algoId" ]
206+
207+
208+ @pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "websockets_proxy Python 3.8+" )
209+ @pytest .mark .asyncio ()
210+ async def test_ws_futures_create_conditional_order_auto_routing (futuresClientAsync ):
211+ """Test that conditional order types are automatically routed to algo endpoint"""
212+ ticker = await futuresClientAsync .ws_futures_get_order_book_ticker (symbol = "LTCUSDT" )
213+ positions = await futuresClientAsync .ws_futures_v2_account_position (symbol = "LTCUSDT" )
214+
215+ # Create a STOP_MARKET order using ws_futures_create_order
216+ # It should automatically route to the algo endpoint
217+ # Use a price above current market price for BUY STOP
218+ trigger_price = float (ticker ["askPrice" ]) * 1.5
219+ order = await futuresClientAsync .ws_futures_create_order (
220+ symbol = ticker ["symbol" ],
221+ side = "BUY" ,
222+ positionSide = positions [0 ]["positionSide" ],
223+ type = "STOP_MARKET" ,
224+ quantity = 1 ,
225+ triggerPrice = trigger_price ,
226+ )
227+
228+ assert order ["symbol" ] == ticker ["symbol" ]
229+ assert "algoId" in order
230+ assert order ["algoType" ] == "CONDITIONAL"
231+
232+ # Cancel the order using algoId
233+ cancel_result = await futuresClientAsync .ws_futures_cancel_order (
234+ symbol = ticker ["symbol" ], algoId = order ["algoId" ]
235+ )
236+ assert cancel_result ["algoId" ] == order ["algoId" ]
237+
238+
239+ @pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "websockets_proxy Python 3.8+" )
240+ @pytest .mark .asyncio ()
241+ async def test_ws_futures_conditional_order_with_stop_price (futuresClientAsync ):
242+ """Test that stopPrice is converted to triggerPrice for conditional orders"""
243+ ticker = await futuresClientAsync .ws_futures_get_order_book_ticker (symbol = "LTCUSDT" )
244+ positions = await futuresClientAsync .ws_futures_v2_account_position (symbol = "LTCUSDT" )
245+
246+ # Create a TAKE_PROFIT_MARKET order with stopPrice (should be converted to triggerPrice)
247+ # Use a price above current market price for SELL TAKE_PROFIT
248+ trigger_price = float (ticker ["askPrice" ]) * 1.5
249+ order = await futuresClientAsync .ws_futures_create_order (
250+ symbol = ticker ["symbol" ],
251+ side = "SELL" ,
252+ positionSide = positions [0 ]["positionSide" ],
253+ type = "TAKE_PROFIT_MARKET" ,
254+ quantity = 1 ,
255+ stopPrice = trigger_price , # This should be converted to triggerPrice
256+ )
257+
258+ assert order ["symbol" ] == ticker ["symbol" ]
259+ assert "algoId" in order
260+ assert order ["algoType" ] == "CONDITIONAL"
261+
262+ # Cancel the order
263+ await futuresClientAsync .ws_futures_cancel_order (
264+ symbol = ticker ["symbol" ], algoId = order ["algoId" ]
265+ )
0 commit comments