Commit a76774b
fix conditional swap order (#1639)
* add timeout to jobs
* feat: Add support for Binance USDS-M Futures conditional/algo orders
This update adds support for Binance's new algo order endpoints for conditional orders, which will be mandatory after 2025-12-09 for order types: STOP, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET, and TRAILING_STOP_MARKET.
Changes:
- Added new order status enums: ACCEPTED, TRIGGERING, TRIGGERED, FINISHED
- Added new dedicated algo order methods:
* futures_create_algo_order() / async
* futures_get_algo_order() / async
* futures_get_all_algo_orders() / async
* futures_get_open_algo_orders() / async
* futures_cancel_algo_order() / async
* futures_cancel_all_algo_open_orders() / async
- Updated existing futures order methods to auto-detect and route conditional orders:
* futures_create_order() now automatically routes conditional order types to algo endpoint
* futures_get_order() supports 'conditional' parameter and algoId/clientAlgoId
* futures_get_all_orders() supports 'conditional' parameter
* futures_get_open_orders() supports 'conditional' parameter
* futures_cancel_order() supports 'conditional' parameter and algoId/clientAlgoId
* futures_cancel_all_open_orders() supports 'conditional' parameter
- Applied same changes to both sync (client.py) and async (async_client.py) clients
References:
- https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Algo-Order
- https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Algo-Order
- https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Algo-Order
* test: Add comprehensive tests for algo/conditional orders
Added tests for both sync and async clients covering:
- Creating algo orders via dedicated method
- Auto-routing conditional orders in futures_create_order
- Getting specific algo orders
- Getting all algo orders history
- Getting open algo orders
- Canceling algo orders
- Canceling all algo open orders
- Using conditional parameter with existing methods
Tests validate both the new dedicated algo order methods and the
backward-compatible conditional parameter on existing methods.
* fix: Use lowercase 'triggerprice' parameter for algo orders
The Binance API expects the trigger price parameter to be lowercase
'triggerprice' not camelCase 'triggerPrice'. Updated both client
implementations and tests to use the correct parameter name.
Changes:
- Updated futures_create_order to convert triggerPrice -> triggerprice
- Added handling for both camelCase and lowercase input
- Updated all tests to use lowercase 'triggerprice' parameter
- Fixes APIError: Mandatory parameter 'triggerprice' was not sent
This ensures compatibility with Binance's algo order endpoints which
expect lowercase parameter names for trigger prices.
* fix: Revert to camelCase 'triggerPrice' per official API docs
After reviewing the official Binance API documentation at:
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Algo-Order
The parameter is clearly documented as 'triggerPrice' (camelCase), not 'triggerprice' (lowercase).
Example from API docs:
- Parameter: triggerPrice (DECIMAL, NO)
- Response field: "triggerPrice": "750.000"
Changes:
- Reverted futures_create_order to use triggerPrice (camelCase)
- Updated tests to use triggerPrice (camelCase)
- Removed incorrect lowercase conversion
The API error message may display parameter names in lowercase, but the
actual parameter expected by the API is camelCase as documented.
* fix tests
* update websockets
* fix tests
* add tests
* default algoType
* update readme
* fix test id
* skip test
* fix linting
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: carlosmiei <43336371+carlosmiei@users.noreply.github.com>1 parent d549914 commit a76774b
File tree
10 files changed
+836
-29
lines changed- binance
- tests
10 files changed
+836
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
166 | 166 | | |
167 | 167 | | |
168 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
169 | 181 | | |
170 | 182 | | |
171 | 183 | | |
| |||
254 | 266 | | |
255 | 267 | | |
256 | 268 | | |
| 269 | + | |
257 | 270 | | |
258 | 271 | | |
259 | 272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1888 | 1888 | | |
1889 | 1889 | | |
1890 | 1890 | | |
1891 | | - | |
1892 | | - | |
1893 | | - | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
1894 | 1917 | | |
1895 | 1918 | | |
1896 | 1919 | | |
| |||
1971 | 1994 | | |
1972 | 1995 | | |
1973 | 1996 | | |
| 1997 | + | |
| 1998 | + | |
1974 | 1999 | | |
1975 | 2000 | | |
1976 | 2001 | | |
| |||
1987 | 2012 | | |
1988 | 2013 | | |
1989 | 2014 | | |
1990 | | - | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
1991 | 2027 | | |
1992 | 2028 | | |
1993 | | - | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
1994 | 2037 | | |
1995 | 2038 | | |
1996 | | - | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
1997 | 2047 | | |
1998 | 2048 | | |
1999 | | - | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
2000 | 2061 | | |
2001 | 2062 | | |
2002 | | - | |
2003 | | - | |
2004 | | - | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
2005 | 2075 | | |
2006 | 2076 | | |
2007 | 2077 | | |
| |||
2021 | 2091 | | |
2022 | 2092 | | |
2023 | 2093 | | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
2024 | 2132 | | |
2025 | 2133 | | |
2026 | 2134 | | |
| |||
3973 | 4081 | | |
3974 | 4082 | | |
3975 | 4083 | | |
| 4084 | + | |
| 4085 | + | |
| 4086 | + | |
| 4087 | + | |
| 4088 | + | |
| 4089 | + | |
| 4090 | + | |
| 4091 | + | |
| 4092 | + | |
| 4093 | + | |
| 4094 | + | |
3976 | 4095 | | |
3977 | 4096 | | |
3978 | 4097 | | |
| |||
0 commit comments