@@ -1906,9 +1906,32 @@ async def futures_loan_interest_history(self, **params):
19061906 )
19071907
19081908 async def futures_create_order (self , ** params ):
1909- if "newClientOrderId" not in params :
1910- params ["newClientOrderId" ] = self .CONTRACT_ORDER_PREFIX + self .uuid22 ()
1911- return await self ._request_futures_api ("post" , "order" , True , data = params )
1909+ # Check if this is a conditional order type that needs to use algo endpoint
1910+ order_type = params .get ("type" , "" ).upper ()
1911+ conditional_types = [
1912+ "STOP" ,
1913+ "STOP_MARKET" ,
1914+ "TAKE_PROFIT" ,
1915+ "TAKE_PROFIT_MARKET" ,
1916+ "TRAILING_STOP_MARKET" ,
1917+ ]
1918+
1919+ if order_type in conditional_types :
1920+ # Route to algo order endpoint
1921+ if "clientAlgoId" not in params :
1922+ params ["clientAlgoId" ] = self .CONTRACT_ORDER_PREFIX + self .uuid22 ()
1923+ # Remove newClientOrderId if it was added by default
1924+ params .pop ("newClientOrderId" , None )
1925+ params ["algoType" ] = "CONDITIONAL"
1926+ # Convert stopPrice to triggerPrice for algo orders (camelCase per API docs)
1927+ if "stopPrice" in params and "triggerPrice" not in params :
1928+ params ["triggerPrice" ] = params .pop ("stopPrice" )
1929+ return await self ._request_futures_api ("post" , "algoOrder" , True , data = params )
1930+ else :
1931+ # Use regular order endpoint
1932+ if "newClientOrderId" not in params :
1933+ params ["newClientOrderId" ] = self .CONTRACT_ORDER_PREFIX + self .uuid22 ()
1934+ return await self ._request_futures_api ("post" , "order" , True , data = params )
19121935
19131936 async def futures_limit_order (self , ** params ):
19141937 """Send in a new futures limit order.
@@ -1989,6 +2012,8 @@ async def futures_modify_order(self, **params):
19892012 """
19902013 return await self ._request_futures_api ("put" , "order" , True , data = params )
19912014
2015+ futures_modify_order .__doc__ = Client .futures_modify_order .__doc__
2016+
19922017 async def futures_create_test_order (self , ** params ):
19932018 return await self ._request_futures_api ("post" , "order/test" , True , data = params )
19942019
@@ -2005,21 +2030,66 @@ async def futures_place_batch_order(self, **params):
20052030 )
20062031
20072032 async def futures_get_order (self , ** params ):
2008- return await self ._request_futures_api ("get" , "order" , True , data = params )
2033+ # Check if this is a request for a conditional/algo order
2034+ is_conditional = params .pop ("conditional" , False )
2035+ # Also check if algoId or clientAlgoId is provided
2036+ if "algoId" in params or "clientAlgoId" in params :
2037+ is_conditional = True
2038+
2039+ if is_conditional :
2040+ return await self ._request_futures_api ("get" , "algoOrder" , True , data = params )
2041+ else :
2042+ return await self ._request_futures_api ("get" , "order" , True , data = params )
2043+
2044+ futures_get_order .__doc__ = Client .futures_get_order .__doc__
20092045
20102046 async def futures_get_open_orders (self , ** params ):
2011- return await self ._request_futures_api ("get" , "openOrders" , True , data = params )
2047+ is_conditional = params .pop ("conditional" , False )
2048+
2049+ if is_conditional :
2050+ return await self ._request_futures_api ("get" , "openAlgoOrders" , True , data = params )
2051+ else :
2052+ return await self ._request_futures_api ("get" , "openOrders" , True , data = params )
2053+
2054+ futures_get_open_orders .__doc__ = Client .futures_get_open_orders .__doc__
20122055
20132056 async def futures_get_all_orders (self , ** params ):
2014- return await self ._request_futures_api ("get" , "allOrders" , True , data = params )
2057+ is_conditional = params .pop ("conditional" , False )
2058+
2059+ if is_conditional :
2060+ return await self ._request_futures_api ("get" , "allAlgoOrders" , True , data = params )
2061+ else :
2062+ return await self ._request_futures_api ("get" , "allOrders" , True , data = params )
2063+
2064+ futures_get_all_orders .__doc__ = Client .futures_get_all_orders .__doc__
20152065
20162066 async def futures_cancel_order (self , ** params ):
2017- return await self ._request_futures_api ("delete" , "order" , True , data = params )
2067+ # Check if this is a request for a conditional/algo order
2068+ is_conditional = params .pop ("conditional" , False )
2069+ # Also check if algoId or clientAlgoId is provided
2070+ if "algoId" in params or "clientAlgoId" in params :
2071+ is_conditional = True
2072+
2073+ if is_conditional :
2074+ return await self ._request_futures_api ("delete" , "algoOrder" , True , data = params )
2075+ else :
2076+ return await self ._request_futures_api ("delete" , "order" , True , data = params )
2077+
2078+ futures_cancel_order .__doc__ = Client .futures_cancel_order .__doc__
20182079
20192080 async def futures_cancel_all_open_orders (self , ** params ):
2020- return await self ._request_futures_api (
2021- "delete" , "allOpenOrders" , True , data = params
2022- )
2081+ is_conditional = params .pop ("conditional" , False )
2082+
2083+ if is_conditional :
2084+ return await self ._request_futures_api (
2085+ "delete" , "algoOpenOrders" , True , data = params
2086+ )
2087+ else :
2088+ return await self ._request_futures_api (
2089+ "delete" , "allOpenOrders" , True , data = params
2090+ )
2091+
2092+ futures_cancel_all_open_orders .__doc__ = Client .futures_cancel_all_open_orders .__doc__
20232093
20242094 async def futures_cancel_orders (self , ** params ):
20252095 if params .get ("orderidlist" ):
@@ -2039,6 +2109,44 @@ async def futures_countdown_cancel_all(self, **params):
20392109 "post" , "countdownCancelAll" , True , data = params
20402110 )
20412111
2112+ # Algo Orders (Conditional Orders)
2113+
2114+ async def futures_create_algo_order (self , ** params ):
2115+ if "clientAlgoId" not in params :
2116+ params ["clientAlgoId" ] = self .CONTRACT_ORDER_PREFIX + self .uuid22 ()
2117+ if "algoType" not in params :
2118+ params ["algoType" ] = "CONDITIONAL"
2119+ return await self ._request_futures_api ("post" , "algoOrder" , True , data = params )
2120+
2121+ futures_create_algo_order .__doc__ = Client .futures_create_algo_order .__doc__
2122+
2123+ async def futures_cancel_algo_order (self , ** params ):
2124+ return await self ._request_futures_api ("delete" , "algoOrder" , True , data = params )
2125+
2126+ futures_cancel_algo_order .__doc__ = Client .futures_cancel_algo_order .__doc__
2127+
2128+ async def futures_cancel_all_algo_open_orders (self , ** params ):
2129+ return await self ._request_futures_api (
2130+ "delete" , "algoOpenOrders" , True , data = params
2131+ )
2132+
2133+ futures_cancel_all_algo_open_orders .__doc__ = Client .futures_cancel_all_algo_open_orders .__doc__
2134+
2135+ async def futures_get_algo_order (self , ** params ):
2136+ return await self ._request_futures_api ("get" , "algoOrder" , True , data = params )
2137+
2138+ futures_get_algo_order .__doc__ = Client .futures_get_algo_order .__doc__
2139+
2140+ async def futures_get_open_algo_orders (self , ** params ):
2141+ return await self ._request_futures_api ("get" , "openAlgoOrders" , True , data = params )
2142+
2143+ futures_get_open_algo_orders .__doc__ = Client .futures_get_open_algo_orders .__doc__
2144+
2145+ async def futures_get_all_algo_orders (self , ** params ):
2146+ return await self ._request_futures_api ("get" , "allAlgoOrders" , True , data = params )
2147+
2148+ futures_get_all_algo_orders .__doc__ = Client .futures_get_all_algo_orders .__doc__
2149+
20422150 async def futures_account_balance (self , ** params ):
20432151 return await self ._request_futures_api (
20442152 "get" , "balance" , True , version = 3 , data = params
@@ -3991,6 +4099,17 @@ async def ws_futures_account_status(self, **params):
39914099 """
39924100 return await self ._ws_futures_api_request ("account.status" , True , params )
39934101
4102+ async def ws_futures_create_algo_order (self , ** params ):
4103+ if "clientAlgoId" not in params :
4104+ params ["clientAlgoId" ] = self .CONTRACT_ORDER_PREFIX + self .uuid22 ()
4105+ return await self ._ws_futures_api_request ("algoOrder.place" , True , params )
4106+ ws_futures_create_algo_order .__doc__ = Client .ws_futures_create_algo_order .__doc__
4107+
4108+ async def ws_futures_cancel_algo_order (self , ** params ):
4109+ return await self ._ws_futures_api_request ("algoOrder.cancel" , True , params )
4110+
4111+ ws_futures_cancel_algo_order .__doc__ = Client .ws_futures_cancel_algo_order .__doc__
4112+
39944113 ####################################################
39954114 # Gift Card API Endpoints
39964115 ####################################################
0 commit comments