# Changelog (/docs/changelog)
v1.0.35 - 2026-02-16 [#v1035---2026-02-16]
**Added**
* chore: normalize package name by @carlosmiei in [#1653](https://github.com/sammchardy/python-binance/pull/1653)
* feat: upgrade margin socket to use websocket api by @pcriadoperez in [#1670](https://github.com/sammchardy/python-binance/pull/1670)
* feat: Update futures algo order API with new TP/SL parameters by @paul-lestyo in [#1672](https://github.com/sammchardy/python-binance/pull/1672)
**Fixed**
* fix: reconnects for websocket connection closed ok and ws-api by @pcriadoperez in [#1655](https://github.com/sammchardy/python-binance/pull/1655)
v1.0.34 - 2025-12-16 [#v1034---2025-12-16]
**Added**
* verbose mode for inspecting requests (`verbose=True`) (#1642)
* feat: add support for rpi orders (#1644)
* feat: update futures ticker endpoint to v2 (#1650)
* feat: add support for websocket algo orders (#1646)
* docs: add missing doc references from async client (#1651)
**Fixed**
* fix: remove duplicate import and replace `type()` with `isinstance()` (#1623)
* fix(client): use proper exception instead of assert for US endpoints (#1641)
v1.0.33 - 2025-12-06 [#v1033---2025-12-06]
**Fixed**
* fix: reconnect keep alive (#1637)
**Added**
* moved conditional orders to the new futures algo service (#1639)
v1.0.32 - 2025-11-03 [#v1032---2025-11-03]
**Fixed**
* signature encoding for non-ascii symbols in both private and public endpoints (#1619)
v1.0.31 - 2025-10-29 [#v1031---2025-10-29]
**Fixed**
* fix signature encoding for non-ascii symbols (#1612)
v1.0.30 - 2025-10-14 [#v1030---2025-10-14]
**Fixed**
* Set default `limit=None` for `futures_historical_klines*` (fetch full range by default) (#1607)
* fixed a typo in a method name (#1605)
* all links updated (#1600)
* throw `ReadLoopClosed` error if trying to connect once read loop is already closed (#1593)
* ensure spot v3 version (#1587)
**Added**
* Demo trading
* websocket userdatastream.signature support, deprecate listenkey for spot market
v1.0.29 - 2025-05-19 [#v1029---2025-05-19]
**Fixed**
* Ws testnet spot URLs update
v1.0.28 - 2025-02-27 [#v1028---2025-02-27]
**Added**
* Add `papi_get_rate_limit`
* Add docs for `create_oco_order`
* Add `uiKlines` support
* Add options websocket market streams
* Add dozens of missing endpoints
**Fixed**
* Ws API not allowing more than 100 requests
* Return empty json instead of throwing error on empty response
* `json_dumps` when using orjson
v1.0.27 - 2024-12-31 [#v1027---2024-12-31]
**Added**
* Add `futures_taker_long_short_ratio` endpoint
* Add portfolio margin user data streams
**Fixed**
* Close read loop before closing websocket
* Fix `threaded_stream`
* Closing keepAliveWebsocket fix
v1.0.26 - 2024-12-23 [#v1026---2024-12-23]
**Added**
* Websockets docs
* Support for microseconds time unit
* Futures data link endpoints
* Return type to `_get_account_socket`
* `futures_index_price_constituents` endpoint
**Fixed**
* `FuturesDepthCacheManager` and `OptionsDepthCacheManager` to `__init__`
* EDDSA random error
v1.0.25 - 2024-12-05 [#v1025---2024-12-05]
**Added**
* Borrow-repay endpoints
* `futures_mark_price_klines`
* `futures_index_price_klines` and `futures_premium_index_klines`
* `HistoricalKlinesType` enum enhanced
* Block trades endpoints
* dapi async endpoints
**Fixed**
* Removed unnecessary logs with `error` level
* Remove CANCEL `read_loop` error log
* Fix error type for when message queue is full
* Fixes that if first connect fails it would not throw
* Improves error handling passing to user error type
v1.0.24 - 2024-11-28 [#v1024---2024-11-28]
**Added**
* Exposed internal classes for easier subclassing
**Fixed**
* Fixed package outdated structure causing import errors
v1.0.23 - 2024-11-27 [#v1023---2024-11-27]
**Added**
* CRUD over Websockets (create/fetch/edit/cancel)
* orjson support
* Overridable `headers` per request
* Added default `recvWindow` parameter
* Proxy support for Websockets
* Gift card API
* `cancel_replace_order`, `cancel_all_open_orders` and `cancel_all_open_margin_orders`
* Missing `futures_modify_order` from async client
* Ruff format
* Missing endpoint for `futures_edit_order`
**Fixed**
* Updated `create_oco_order` endpoint
* Batch orders signature issue
* `fail_connection` issue related to the `websockets` upgrade
* `eddsa` signature issue
v1.0.22 - 2024-10-29 [#v1022---2024-10-29]
**Added**
* Futures all tickers stream
* Futures coin-m all tickers stream
**Fixed**
* Hang in the ThreadedApiManager
v1.0.21 - 2024-10-23 [#v1021---2024-10-23]
**Added**
* Some new endpoints
**Fixed**
* URL encoding for coin-m post endpoints
* Batch order endpoint
* Some minor bug fixes
v1.0.20 - 2024-10-22 [#v1020---2024-10-22]
**Added**
* EDDSA authentication
* Portfolio Margin endpoints
* Some new futures endpoints
* Proxy support for the AsyncClient
* Version override is possible now through `params`
**Fixed**
* Migrated `positionRisk` to v3
* Fixed `AttributeError("'Connect' object has no attribute 'protocol'")`
* Some minor bug fixes
v1.0.19 - 2023-08-11 [#v1019---2023-08-11]
**Added**
* Some new futures and margin endpoints
* Pass `session_params` to streams for AsyncClient
**Fixed**
* Removed debug statements
* Options testnet URL
* Accessing msg variable before assignment
v1.0.18 - 2023-08-09 [#v1018---2023-08-09]
**Added**
* `TRAILING_STOP_MARKET` option for orders
**Fixed**
* Futures API endpoint versions
* Margin endpoint request methods
v1.0.17 - 2023-02-21 [#v1017---2023-02-21]
**Added**
* RSA key authentication
* Support for api1-api4 base endpoints
* binance.us staking endpoints
* Options ticker by expiration socket
* Staking endpoints
* Pay and Convert endpoints
* Futures index info endpoint
* Open OCO Orders endpoint
* Param to pass session params to aiohttp.ClientSession
**Updated**
* Some margin endpoint versions
* Support testnet for more streams
**Fixed**
* Indefinite websocket reconnect loop
* Crash on parsing code from some errors
v1.0.16 - 2022-04-09 [#v1016---2022-04-09]
**Added**
* Pass limit param to all kline functions
* Increase default for kline functions from 500 to 1000
* Add `HistoricalKlinesType.FUTURES_COIN` as option
* Testnet URL for `coin_futures_socket`
**Updated**
* `round_step_size` more accurate
**Fixed**
* Remove deprecated loop param
* Websockets unpinned
* Hanging websockets in exiting state
* Check `start_ts` after `end_ts` for klines
* Multi assets margin params
v1.0.15 - 2021-09-27 [#v1015---2021-09-27]
**Added**
* Enable/disable margin account for symbol endpoints
* Top trader long/short positions endpoint
* Global long/short ratio endpoint
**Fixed**
* Fix websockets to 9.1
* Websocket reconnect updates
* Fix futures kline sockets
v1.0.14 - 2021-09-08 [#v1014---2021-09-08]
**Fixed**
* Websocket reconnecting
v1.0.13 - 2021-09-08 [#v1013---2021-09-08]
**Added**
* Futures Depth Cache Manager
* Futures kline websocket stream
* Coin Futures User websocket stream
* New Margin endpoints
* Margin OCO order endpoints
* Fiat endpoints
* C2C endpoints
* Account API permissions endpoint
**Fixed**
* Changed `asset` to `coin` in withdraw endpoint
v1.0.12 - 2021-06-03 [#v1012---2021-06-03]
**Added**
* Coin futures batch order function
**Fixed**
* Threaded websockets on python3.9
* Filter out None params in request kwargs
* Deconflict streams with same name on different websocket urls
* Reduce close timeout on websocket close
v1.0.10 - 2021-05-13 [#v1010---2021-05-13]
**Added**
* Futures multi-asset margin mode endpoints
* Optional symbol param to `get_all_tickers`
**Fixed**
* `start_multiplex_socket` remove lower case filter on stream names
v1.0.9 - 2021-05-12 [#v109---2021-05-12]
**Fixed**
* `start_book_ticker_socket` and `start_multiplex_socket` to call correct async function
v1.0.8 - 2021-05-11 [#v108---2021-05-11]
**Added**
* Old style websocket and depth cache managers as option without asyncio
**Fixed**
* Fixed issue with `get_historical_klines` in Client
* Remove print debug line
v1.0.7 [#v107]
**Fixed**
* Remove version param from `get_sub_account_assets`
v1.0.6 [#v106]
**Fixed**
* Fix time for authenticated stream keepalive
v1.0.5 [#v105]
**Fixed**
* Restored access to last response on client
v1.0.4 [#v104]
**Added**
* Futures Testnet support
* Kline type for fetching historical klines
**Fixed**
* Spot Testnet websocket URL
v1.0.3 [#v103]
**Added**
* Spot Testnet support
v1.0.2 [#v102]
**Added**
* Start of typing to client and websockets
**Fixed**
* `end_str`, limit, spot params in kline fetching
* Drop None values in params passed
v1.0.1 [#v101]
**Fixed**
* Restored params for Client and AsyncClient classes
v1.0.0 [#v100]
**Added**
* Async support for all REST endpoints
* USDM and Coin-M Futures websocket streams
* Websockets use same tld as Client
* Convert type option for DepthCache
**Breaking Changes**
* Supports only py3.6+
* All wapi calls changed to sapi
* Websockets have changed to use Asynchronous context managers
**Fixed**
* `get_historical_klines` params
v0.7.11 [#v0711]
**Added**
* Vanilla Options REST endpoints
* Vanilla Options websockets
* Futures order type enums
**Updated**
* Websocket keep-alive functions for different socket types
* Dependencies
**Fixed**
* Change to User-Agent to avoid connection issues
v0.7.5 - 2020-02-06 [#v075---2020-02-06]
**Added**
* Futures REST endpoints
* Lending REST endpoints
* OCO Orders function
* Average Price function `get_avg_price`
* Support for other domains (.us, .jp, etc)
**Fixed**
* Websocket keepalive callback not found
v0.7.4 - 2019-09-22 [#v074---2019-09-22]
**Added**
* Symbol book ticker websocket streams
* Margin websocket stream
**Updated**
* Can call Client without any params
* Make response a property of the Client class
**Fixed**
* Issue with None value params causing errors
v0.7.3 - 2019-08-12 [#v073---2019-08-12]
**Added**
* Sub account endpoints
* Dust transfer endpoint
* Asset dividend history endpoint
**Removed**
* Deprecated withdraw fee endpoint
v0.7.2 - 2019-08-01 [#v072---2019-08-01]
**Added**
* Margin trading endpoints
**Fixed**
* Depth cache clearing bug
v0.7.1 - 2019-01-23 [#v071---2019-01-23]
**Added**
* Limit param to DepthCacheManager
* Limit param to `get_historical_klines`
* `update_time` to DepthCache class
**Fixed**
* Super init in Websocket class
* Removal of request params from signature
* Empty set issue in `aggregate_trade_iter`
v0.7.0 - 2018-08-08 [#v070---2018-08-08]
**Added**
* `get_asset_details` endpoint
* `get_dust_log` endpoint
* `get_trade_fee` endpoint
* Ability for multiple DepthCacheManagers to share a BinanceSocketManager
* `get_historical_klines_generator` function
* Custom socket timeout param for BinanceSocketManager
**Updated**
* General dependency version
* Removed support for python3.3
**Fixed**
* Add a super init on BinanceClientProtocol
v0.6.0 - 2018-01-09 [#v060---2018-01-09]
**Added**
* `get_historical_klines` function
* Ability to override requests parameters globally
* Error on websocket disconnect
v0.5.0 - 2017-12-05 [#v050---2017-12-05]
**Added**
* Recent trades endpoint
* Historical trades endpoint
* Order response type option
* Check for invalid user stream listen key
v0.1.0 - 2017-08-16 [#v010---2017-08-16]
Websocket release
**Added**
* Websocket manager
* Order parameter validation
* Order and Symbol enums
* API Endpoints for Data Streams
v0.0.2 - 2017-08-14 [#v002---2017-08-14]
Initial version
**Added**
* General, Market Data and Account endpoints
# API Endpoints Reference (/docs/endpoints)
> :warning: **Disclaimer**:
> * Before using the endpoints, please check the [API documentation](https://binance-docs.github.io/apidocs/#change-log) to be informed about the latest changes or possible bugs/problems.
> * Not all parameters are mandatory. Some parameters are only mandatory in specific conditions/types. Check the official documentation the type of each parameter and to know if a parameter is mandatory or optional.
> * This documentation only includes methods in client.py file. Websocket methods haven't (yet) been covered.
[Spot/Margin/Saving/Mining Endpoints](https://binance-docs.github.io/apidocs/spot/en/) [#spotmarginsavingmining-endpoints]
* *Wallet Endpoints*
* **GET /sapi/v1/system/status** (Fetch system status.)
```python
client.get_system_status()
```
* **GET /sapi/v1/capital/config/getall (HMAC SHA256)** (Get information of coins (available for deposit and withdraw) for user.)
```python
client.get_all_coins_info()
```
* **GET /sapi/v1/accountSnapshot (HMAC SHA256)** (Daily Account Snapshot (USER\_DATA).)
```python
client.get_account_snapshot(type='SPOT')
```
* **POST /sapi/v1/account/disableFastWithdrawSwitch (HMAC SHA256)** (Disable Fast Withdraw Switch (USER\_DATA).)
```python
client.disable_fast_withdraw_switch(type='SPOT')
```
* **POST /sapi/v1/account/enableFastWithdrawSwitch (HMAC SHA256)** (Enable Fast Withdraw Switch (USER\_DATA).)
```python
client.enable_fast_withdraw_switch(type='SPOT')
```
* **POST /sapi/v1/capital/withdraw/apply (HMAC SHA256)** (Withdraw: Submit a withdraw request.)
```python
client.withdraw(coin,
withdrawOrderId,
network,
address,
addressTag,
amount,
transactionFeeFlag,
name,
recvWindow)
```
* **GET /sapi/v1/capital/deposit/hisrec (HMAC SHA256)** (Fetch Deposit History(supporting network) (USER\_DATA).)
```python
client.get_deposit_history(coin, status, startTime, endTime, recvWindow)
```
* **GET /sapi/v1/capital/withdraw/history (HMAC SHA256)** (Fetch Withdraw History (supporting network) (USER\_DATA).)
```python
client.get_withdraw_history(coin, status, startTime, endTime, recvWindow)
```
* **GET /sapi/v1/capital/deposit/address (HMAC SHA256)** (Fetch deposit address with network.)
```python
client.get_deposit_address(coin, status, recvWindow)
```
* **GET /sapi/v1/account/status** (Fetch account status detail.)
```python
client.get_account_status(recvWindow)
```
* **GET /sapi/account/apiTradingStatus** (Fetch account api trading status detail.)
```python
client.get_account_api_trading_status(recvWindow)
```
* **GET /sapi/v1/asset/dribblet (HMAC SHA256)** (DustLog: Fetch small amounts of assets exchanged BNB records.)
```python
client.get_dust_log(recvWindow)
```
* **Post /sapi/v1/asset/dust (HMAC SHA256)** (Dust Transfer: Convert dust assets to BNB.)
```python
client.transfer_dust(asset, recvWindow)
```
* **Get /sapi/v1/asset/assetDividend (HMAC SHA256)** (Query asset dividend record.)
```python
client.get_asset_dividend_history(asset, startTime, endTime, limit, recvWindow)
```
* **GET /sapi/v1/asset/assetDetail (HMAC SHA256)** (Fetch details of assets supported on Binance.)
```python
client.get_asset_details(recvWindow)
```
* **GET /sapi/v1/asset/tradeFee (HMAC SHA256)** (Fetch trade fee, values in percentage.)
```python
client.get_trade_fee(symbol, recvWindow)
```
* *Market Data Endpoints*
* **GET /api/v3/ping** (Test connectivity to the Rest API.)
```python
client.ping()
```
* **GET /api/v3/time** (Test connectivity to the Rest API and get the current server time.)
```python
client.get_server_time()
```
* **GET /api/v3/exchangeInfo** (Current exchange trading rules and symbol information.)
```python
client.get_exchange_info()
```
* **GET /api/v3/depth** (Get the Order Book for the market.)
```python
client.get_order_book(symbol, limit)
```
* **GET /api/v3/trades** (Get recent trades (up to last 500))
```python
client.get_recent_trades(symbol, limit)
```
* **GET /api/v3/historicalTrades** (Get older market trades.)
```python
client.get_historical_trades(symbol, limit, fromId)
```
* **GET /api/v3/aggTrades** (Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.)
```python
client.get_aggregate_trades(symbol, fromId, startTime, endTime, limit)
# Wrapper function: Iterate over aggregate trade data from (start_time or last_id) the end of the history so far:
client.aggregate_trade_iter(symbol, start_str, last_id)
```
* **GET /api/v3/klines** (Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.)
```python
client.get_klines(symbol, interval, startTime, endTime, limit)
# Wrapper function: Iterate over klines data from client.get_klines()
client.get_historical_klines(symbol, interval, start_str, end_str, limit)
```
* **GET /api/v3/avgPrice** (Current average price for a symbol.)
```python
client.get_avg_price(symbol)
```
* **GET /api/v3/ticker/24hr** (24 hour rolling window price change statistics. **Careful** when accessing this with no symbol.)
```python
client.get_ticker(symbol)
```
* **GET /api/v3/ticker/price** (Latest price for a symbol or symbols.)
```python
client.get_symbol_ticker(symbol)
```
* **GET /api/v3/ticker/bookTicker** (Best price/qty on the order book for a symbol or symbols.)
```python
client.get_orderbook_ticker(symbol)
```
* *Spot Account/Trade Endpoints*
* **POST /api/v3/order/test (HMAC SHA256)** (Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.)
```python
client.create_test_order(symbol,
side,
type,
timeInForce,
quantity,
quoteOrderQty,
price,
newClientOrderId,
stopPrice,
icebergQty,
newOrderRespType,
recvWindow)
```
* **POST /api/v3/order (HMAC SHA256)** (Send in a new order.)
```python
client.create_order(symbol,
side,
type,
timeInForce,
quantity,
quoteOrderQty,
price,
newClientOrderId,
stopPrice,
icebergQty,
newOrderRespType,
recvWindow)
## Wrapper functions:
# Send in a new limit order.
# Default parameters: timeInForce=Client.TIME_IN_FORCE_GTC, type=Client.ORDER_TYPE_LIMIT
client.order_limit(symbol,
side,
quantity,
price,
newClientOrderId,
stopPrice,
icebergQty,
newOrderRespType,
recvWindow)
# Send in a new limit buy order.
# Default parameters: timeInForce=Client.TIME_IN_FORCE_GTC, type=Client.ORDER_TYPE_LIMIT, side=Client.SIDE_BUY
client.order_limit_buy(symbol,
quantity,
price,
newClientOrderId,
stopPrice,
icebergQty,
newOrderRespType,
recvWindow)
# Send in a new limit sell order.
# Default parameters: timeInForce=Client.TIME_IN_FORCE_GTC, type=Client.ORDER_TYPE_LIMIT, side= Client.SIDE_SELL
client.order_limit_sell(symbol,
quantity,
price,
newClientOrderId,
stopPrice,
icebergQty,
newOrderRespType,
recvWindow)
# Send in a new market order.
# Default parameters: type=Client.ORDER_TYPE_MARKET
client.order_market(symbol,
side,
quantity,
quoteOrderQty,
newClientOrderId,
newOrderRespType,
recvWindow)
# Send in a new market buy order.
# Default parameters: type=Client.ORDER_TYPE_MARKET, side=Client.SIDE_BUY
client.order_market_buy(symbol,
quantity,
quoteOrderQty,
newClientOrderId,
newOrderRespType,
recvWindow)
# Send in a new market sell order.
# Default parameters: type=Client.ORDER_TYPE_MARKET, side=Client.SIDE_SELL
client.order_market_sell(symbol,
quantity,
quoteOrderQty,
newClientOrderId,
newOrderRespType,
recvWindow)
```
* **DELETE /api/v3/order (HMAC SHA256)** (Cancel an active order.)
```python
client.cancel_order(symbol, orderId, origClientOrderId, newClientOrderId, recvWindow)
```
* **DELETE api/v3/openOrders** (Cancels all active orders on a symbol. This includes OCO orders.)
> :warning: Not yet implemented
* **GET /api/v3/order (HMAC SHA256)** (Check an order's status.)
```python
client.get_order(symbol, orderId, origClientOrderId, recvWindow)
```
* **GET /api/v3/openOrders (HMAC SHA256)** (Get all open orders on a symbol. **Careful** when accessing this with no symbol.)
```python
client.get_open_orders(symbol, recvWindow)
```
* **GET /api/v3/allOrders (HMAC SHA256)** (Get all account orders; active, canceled, or filled.)
```python
client.get_all_orders(symbol, orderId, startTime, endTime, limit, recvWindow)
```
* **POST /api/v3/order/oco (HMAC SHA256)** (Send in a new OCO order)
```python
client.create_oco_order(symbol,
listClientOrderId,
side,
quantity,
limitClientOrderId,
price,
limitIcebergQty,
stopClientOrderId,
stopPrice,
stopLimitPrice,
stopIcebergQty,
stopLimitTimeInForce,
newOrderRespType,
recvWindow)
## Wrapper Functions:
# Send in a new OCO buy order. Default parameter: type=Client.SIDE_BUY
client.order_oco_buy(symbol,
listClientOrderId,
quantity,
limitClientOrderId,
price,
limitIcebergQty,
stopClientOrderId,
stopPrice,
stopLimitPrice,
stopIcebergQty,
stopLimitTimeInForce,
newOrderRespType,
recvWindow)
# Send in a new OCO sell order. Default parameter: type=Client.SIDE_SELL
client.order_oco_sell(symbol,
listClientOrderId,
quantity,
limitClientOrderId,
price,
limitIcebergQty,
stopClientOrderId,
stopPrice,
stopLimitPrice,
stopIcebergQty,
stopLimitTimeInForce,
newOrderRespType,
recvWindow)
```
* **DELETE /api/v3/orderList (HMAC SHA256)** (Cancel OCO: Cancel an entire Order List)
> :warning: Not yet implemented
* **GET /api/v3/orderList (HMAC SHA256)** (Query OCO: Retrieves a specific OCO based on provided optional parameters)
> :warning: Not yet implemented
* **GET /api/v3/allOrderList (HMAC SHA256)** (Retrieves all OCO based on provided optional parameters)
> :warning: Not yet implemented
* **GET /api/v3/openOrderList (HMAC SHA256)** (Query Open OCO (USER\_DATA))
> :warning: Not yet implemented
* **GET /api/v3/account (HMAC SHA256)** (Get current account information.)
```python
client.get_account(recvWindow)
```
* **GET /api/v3/myTrades (HMAC SHA256)** (Get trades for a specific account and symbol.)
```python
client.get_my_trades(symbol, startTime, endTime, fromId, limit, recvWindow)
```
* *Margin Account/Trade*
* **POST /sapi/v1/margin/transfer (HMAC SHA256)** (Execute transfer between margin account and spot account(MARGIN).)
```python
client.transfer_margin_to_spot(asset, amount, recvWindow)
client.transfer_spot_to_margin(asset, amount, recvWindow)
```
* **POST /sapi/v1/margin/loan (HMAC SHA256)** (Apply for a loan(MARGIN).)
```python
client.create_margin_loan(asset, isIsolated, symbol, amount, recvWindow)
```
* **POST /sapi/v1/margin/repay (HMAC SHA256)** (Repay loan for margin account (MARGIN).)
```python
client.repay_margin_loan(asset, isIsolated, symbol, amount, recvWindow)
```
* **GET /sapi/v1/margin/asset** (Query Margin Asset (MARKET\_DATA).)
```python
client.get_margin_asset(asset)
```
* **GET /sapi/v1/margin/pair** (Query Cross Margin Pair (MARKET\_DATA).)
```python
client.get_margin_symbol(symbol)
```
* **GET /sapi/v1/margin/allAssets** (Get All Cross Margin Assets (MARKET\_DATA).)
```python
client.get_margin_all_assets()
```
* **GET /sapi/v1/margin/allPairs** (Get All Cross Margin Pairs (MARKET\_DATA).)
```python
client.get_margin_all_pairs()
```
* **GET /sapi/v1/margin/priceIndex** (Query Margin PriceIndex (MARKET\_DATA).)
```python
client.get_margin_price_index(symbol)
```
* **POST /sapi/v1/margin/order (HMAC SHA256)** (Post a new order for margin account.)
```python
client.create_margin_order(symbol,
isIsolated,
side,
type,
quantity,
price,
stopPrice,
newClientOrderId,
icebergQty,
newOrderRespType,
sideEffectType,
timeInForce,
recvWindow)
```
* **DELETE /sapi/v1/margin/order (HMAC SHA256)** (Cancel an active order for margin account.)
```python
client.cancel_margin_order(symbol,
isIsolated,
orderId,
origClientOrderId,
newClientOrderId,
recvWindow)
```
* **GET /sapi/v1/margin/transfer (HMAC SHA256)** (Get Cross Margin Transfer History (USER\_DATA).)
```python
client.transfer_margin_to_spot(asset, amount, recvWindow)
client.transfer_spot_to_margin(asset, amount, recvWindow)
```
* **GET /sapi/v1/margin/loan (HMAC SHA256)** (Query Loan Record (USER\_DATA).)
```python
client.get_margin_loan_details(asset, isolatedSymbol, txId, startTime, endTime, current, size, recvWindow)
```
* **GET /sapi/v1/margin/repay (HMAC SHA256)** (Query repay record (USER\_DATA).)
```python
client.get_margin_repay_details(asset, isolatedSymbol, txId, startTime, endTime, current, size, recvWindow)
```
* **GET /sapi/v1/margin/interestHistory (HMAC SHA256)** (Get Interest History (USER\_DATA).)
```python
client.get_margin_interest_history(asset, isolatedSymbol, startTime, endTime, current, size, archived, recvWindow)
```
* **GET /sapi/v1/margin/forceLiquidationRec (HMAC SHA256)** (Get Force Liquidation Record (USER\_DATA).)
```python
client.get_margin_force_liquidation_rec(isolatedSymbol, startTime, endTime, current, size, recvWindow)
```
* **GET /sapi/v1/margin/account (HMAC SHA256)** (Query Cross Margin Account Details (USER\_DATA).)
```python
client.get_margin_account(recvWindow)
```
* **GET /sapi/v1/margin/order (HMAC SHA256)** (Query Margin Account's Order (USER\_DATA).)
```python
client.get_margin_order(symbol, isIsolated, orderId, origClientOrderId, recvWindow)
```
* **GET /sapi/v1/margin/openOrders (HMAC SHA256)** (Query Margin Account's Open Order (USER\_DATA).)
```python
client.get_open_margin_orders(symbol, isIsolated, recvWindow)
```
* **GET /sapi/v1/margin/allOrders (HMAC SHA256)** (Query Margin Account's All Order (USER\_DATA).)
```python
client.get_all_margin_orders(symbol, isIsolated, orderId, startTime, endTime, limit, recvWindow)
```
* **GET /sapi/v1/margin/myTrades (HMAC SHA256)** (Query Margin Account's Trade List (USER\_DATA).)
```python
client.get_margin_trades(symbol, isIsolated, startTime, endTime, fromId, limit, recvWindow)
```
* **GET /sapi/v1/margin/maxBorrowable (HMAC SHA256)** (Query Max Borrow amount for an asset (USER\_DATA).)
```python
client.get_max_margin_loan(asset, isolatedSymbol, recvWindow)
```
* **GET /sapi/v1/margin/maxTransferable (HMAC SHA256)** (Query Max Transfer-Out Amount (USER\_DATA).)
```python
client.get_max_margin_transfer(asset, isolatedSymbol, recvWindow)
```
* **POST /sapi/v1/margin/isolated/create (HMAC SHA256)** (Create Isolated Margin Account (MARGIN).)
```python
client.create_isolated_margin_account(base, quote, recvWindow)
```
* **POST /sapi/v1/margin/isolated/transfer (HMAC SHA256)** (Isolated Margin Account Transfer (MARGIN).)
```python
client.transfer_spot_to_isolated_margin(asset, symbol, amount, recvWindow)
client.transfer_isolated_margin_to_spot(asset, symbol, amount, recvWindow)
```
* **GET /sapi/v1/margin/isolated/transfer (HMAC SHA256)** (Get Isolated Margin Transfer History (USER\_DATA).)
> :warning: Not yet implemented
* **GET /sapi/v1/margin/isolated/account (HMAC SHA256)** (Query Isolated Margin Account Info (USER\_DATA).)
```python
client.get_isolated_margin_account(symbols, recvWindow)
```
* **GET /sapi/v1/margin/isolated/pair (HMAC SHA256)** (Query Isolated Margin Symbol (USER\_DATA).)
```python
client.get_isolated_margin_symbol(symbol, recvWindow)
```
* **GET /sapi/v1/margin/isolated/allPairs (HMAC SHA256)** (Get All Isolated Margin Symbol (USER\_DATA).)
```python
client.get_all_isolated_margin_symbols(recvWindow)
```
* **POST /sapi/v1/margin/manual-liquidation (HMAC SHA256)** (Margin manual liquidation (MARGIN).)
```python
client.margin_manual_liquidation(type)
```
* *User Data Streams*
* **POST /api/v3/userDataStream** (Create a ListenKey (Spot) (USER\_STREAM): Start a new user data stream.)
```python
client.stream_get_listen_key()
```
* **PUT /api/v3/userDataStream** (Ping/Keep-alive a ListenKey (Spot) (USER\_STREAM).)
```python
client.stream_keepalive(listenKey)
```
* **DELETE /api/v3/userDataStream** (Close a ListenKey (Spot) (USER\_STREAM).)
```python
client.stream_close(listenKey)
```
* **POST /sapi/v1/userDataStream** (Create a ListenKey (Margin).)
```python
client.margin_stream_get_listen_key()
```
* **PUT /sapi/v1/userDataStream** (Ping/Keep-alive a ListenKey (Margin).)
```python
client.margin_stream_keepalive(listenKey)
```
* **DELETE /sapi/v1/userDataStream** (Close a ListenKey (Margin).)
```python
client.margin_stream_close(listenKey)
```
* **POST /sapi/v1/userDataStream/isolated** (Create a ListenKey (Isolated).)
```python
client.isolated_margin_stream_get_listen_key(symbol)
```
* **PUT /sapi/v1/userDataStream/isolated** (Ping/Keep-alive a ListenKey (Isolated).)
```python
client.isolated_margin_stream_keepalive(symbol, listenKey)
```
* **DELETE /sapi/v1/userDataStream/isolated** (Close a ListenKey (Isolated).)
```python
client.isolated_margin_stream_close(symbol, listenKey)
```
* *Savings Endpoints*
* **GET /sapi/v1/lending/daily/product/list (HMAC SHA256)** (Get Flexible Product List (USER\_DATA).)
```python
client.get_lending_product_list(status, featured, recvWindow)
```
* **GET /sapi/v1/lending/daily/userLeftQuota (HMAC SHA256)** (Get Left Daily Purchase Quota of Flexible Product (USER\_DATA).)
```python
client.get_lending_daily_quota_left(productId, recvWindow)
```
* **POST /sapi/v1/lending/daily/purchase (HMAC SHA256)** (Purchase Flexible Product (USER\_DATA).)
```python
client.purchase_lending_product(productId, amount, recvWindow)
```
* **GET /sapi/v1/lending/daily/userRedemptionQuota (HMAC SHA256)** (Get Left Daily Redemption Quota of Flexible Product (USER\_DATA).)
```python
client.get_lending_daily_redemption_quota(productId, type, recvWindow)
```
* **POST /sapi/v1/lending/daily/redeem (HMAC SHA256)** (Redeem Flexible Product (USER\_DATA).)
```python
client.redeem_lending_product(productId, amount, type, recvWindow)
```
* **GET /sapi/v1/lending/daily/token/position (HMAC SHA256)** (Get Flexible Product Position (USER\_DATA).)
```python
client.get_lending_position(asset, recvWindow)
```
* **GET /sapi/v1/lending/project/list (HMAC SHA256)** (Get Fixed and Activity Project List (USER\_DATA).)
```python
client.get_fixed_activity_project_list(asset, type, status, isSortAsc, sortBy, current, size, recvWindow)
```
* **POST /sapi/v1/lending/customizedFixed/purchase (HMAC SHA256)** (Purchase Fixed/Activity Project (USER\_DATA).)
> :warning: Not yet implemented
* **GET /sapi/v1/lending/project/position/list (HMAC SHA256)** (Get Fixed/Activity Project Position (USER\_DATA).)
> :warning: Not yet implemented
* **GET /sapi/v1/lending/union/account (HMAC SHA256)** (Lending Account (USER\_DATA).)
```python
client.get_lending_account(recvWindow)
```
* **GET /sapi/v1/lending/union/purchaseRecord (HMAC SHA256)** (Get Purchase Record (USER\_DATA).)
```python
client.get_lending_purchase_history(lendingType, asset, startTime, endTime, current, size, recvWindow)
```
* **GET /sapi/v1/lending/union/redemptionRecord (HMAC SHA256)** (Get Redemption Record (USER\_DATA).)
```python
client.get_lending_redemption_history(lendingType, asset, startTime, endTime, current, size, recvWindow)
```
* **GET /sapi/v1/lending/union/interestHistory (HMAC SHA256)** (Get Interest History (USER\_DATA).)
```python
client.get_lending_interest_history(lendingType, asset, startTime, endTime, current, size, recvWindow)
```
* **POST /sapi/v1/lending/positionChanged (HMAC SHA256)** (Change Fixed/Activity Position to Daily Position (USER\_DATA).)
```python
client.change_fixed_activity_to_daily_position(projectId, lot, positionId, recvWindow)
```
* *Mining Endpoints*
> :warning: Not yet implemented
* *Sub-Account Endpoints*
* **GET /sapi/v1/sub-account/list (HMAC SHA256)** (Query Sub-account List (For Master Account).)
```python
client.get_sub_account_list(email, isFreeze, page, limit, recvWindow)
```
* **GET /sapi/v1/sub-account/sub/transfer/history (HMAC SHA256)** (Query Sub-account Spot Asset Transfer History (For Master Account).)
```python
client.get_sub_account_transfer_history(fromEmail, toEmail, startTime, endTime, page, limit, recvWindow)
```
* **GET /sapi/v1/sub-account/assets (HMAC SHA256)** (Query Sub-account Assets (For Master Account).)
```python
client.get_sub_account_assets(email, recvWindow)
```
> :warning: The rest of methods for Sub-Account Endpoints are not yet implemented
* *BLVT Endpoints*
> :warning: Not yet implemented
* *BSwap Endpoints*
> :warning: Not yet implemented
[USDT-M Futures](https://binance-docs.github.io/apidocs/futures/en/) [#usdt-m-futures]
* *Market Data Endpoints*
* **GET /fapi/v1/ping** (Test connectivity to the Rest API.)
```python
client.futures_ping()
```
* **GET /fapi/v1/time** (Test connectivity to the Rest API and get the current server time.)
```python
client.futures_time()
```
* **GET /fapi/v1/exchangeInfo** (Current exchange trading rules and symbol information.)
```python
client.futures_exchange_info()
```
* **GET /fapi/v1/depth** (Get the Order Book for the market.)
```python
client.futures_order_book(symbol, limit)
```
* **GET /fapi/v1/trades** (Get recent trades.)
```python
client.futures_recent_trades(symbol, limit)
```
* **GET /fapi/v1/historicalTrades** (Get older market historical trades (MARKET\_DATA).)
```python
client.futures_historical_trades(symbol, limit, fromId)
```
* **GET /fapi/v1/aggTrades** (Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.)
```python
client.futures_aggregate_trades(symbol, fromId, startTime, endTime, limit)
```
* **GET /fapi/v1/klines** (Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.)
```python
client.futures_klines(symbol, interval, startTime, endTime, limit)
```
* **GET /fapi/v1/premiumIndex** (Get Mark Price and Funding Rate.)
```python
client.futures_mark_price(symbol)
```
* **GET /fapi/v1/fundingRate** (Get Funding Rate History.)
```python
client.futures_funding_rate(symbol, startTime, endTime, limit)
```
* **GET /fapi/v1/ticker/24hr** (24 hour rolling window price change statistics. **Careful** when accessing this with no symbol.)
```python
client.futures_ticker(symbol)
```
* **GET /fapi/v1/ticker/price** (Latest price for a symbol or symbols.)
```python
client.futures_symbol_ticker(symbol)
```
* **GET /fapi/v1/ticker/bookTicker** (Best price/qty on the order book for a symbol or symbols.)
```python
client.futures_orderbook_ticker(symbol)
```
* **GET /fapi/v1/allForceOrders** (Get all Liquidation Orders.)
> :warning: Probably broken, python code below is implemented on v1/ticker/allForceOrders endpoint.
```python
client.futures_liquidation_orders(symbol, startTime, endTime, limit)
```
* **GET /fapi/v1/openInterest** (Get present open interest of a specific symbol.)
```python
client.futures_open_interest(symbol)
```
* **GET /futures/data/openInterestHist** (Open Interest Statistics.)
```python
client.futures_open_interest_hist(symbol, period, limit, startTime, endTime)
```
* **GET /futures/data/topLongShortAccountRatio** (Top Trader Long/Short Ratio (Accounts) (MARKET\_DATA).)
```python
client.futures_top_longshort_account_ratio(symbol, period, limit, startTime, endTime)
```
* **GET /futures/data/topLongShortPositionRatio** (Top Trader Long/Short Ratio (Positions).)
```python
client.futures_top_longshort_position_ratio(symbol, period, limit, startTime, endTime)
```
* **GET /futures/data/globalLongShortAccountRatio** (Long/Short Ratio.)
```python
client.futures_global_longshort_ratio(symbol, period, limit, startTime, endTime)
```
* **GET /futures/data/takerlongshortRatio** (Taker Buy/Sell Volume.)
```python
client.futures_taker_longshort_ratio(symbol, period, limit, startTime, endTime)
```
* **GET /fapi/v1/lvtKlines** (Historical BLVT NAV Kline/Candlestick.)
> :warning: Not yet implemented
* **GET /fapi/v1/indexInfo** (Composite Index Symbol Information.)
> :warning: Not yet implemented
* *Account/trades Endpoints*
* **POST /sapi/v1/futures/transfer (HMAC SHA256)** (New Future Account Transfer (FUTURES): Execute transfer between spot account and futures account.)
```python
client.futures_account_transfer(asset, amount, type, recvWindow)
```
* **GET /sapi/v1/futures/transfer (HMAC SHA256)** (Get Future Account Transaction History List (USER\_DATA).)
```python
client.transfer_history(asset, startTime, endTime, current, size, recvWindow)
```
* **POST /fapi/v1/positionSide/dual (HMAC SHA256)** (Change user's position mode (Hedge Mode or One-way Mode ) on ***EVERY symbol***.)
```python
client.futures_change_position_mode(dualSidePosition, recvWindow)
```
* **GET /fapi/v1/positionSide/dual (HMAC SHA256)** (Get user's position mode (Hedge Mode or One-way Mode ) on ***EVERY symbol***.)
```python
client.futures_get_position_mode(recvWindow)
```
* **POST /fapi/v1/order (HMAC SHA256)** (Send in a new order (TRADE).)
```python
client.futures_create_order(symbol,
side,
positionSide,
type,
timeInForce,
quantity,
reduceOnly,
price,
newClientOrderId,
stopPrice,
closePosition,
activationPrice,
callbackRate,
workingType,
priceProtect,
newOrderRespType,
recvWindow)
```
* **POST /fapi/v1/batchOrders (HMAC SHA256)** (Place Multiple Orders (TRADE).)
> :warning: Not yet implemented
* **GET /fapi/v1/order (HMAC SHA256)** (Query Order (USER\_DATA): Check an order's status.)
```python
client.futures_get_order(symbol, orderId, origClientOrderId, recvWindow)
```
* **DELETE /fapi/v1/order (HMAC SHA256)** (Cancel an active order (TRADE).)
```python
client.futures_cancel_order(symbol, orderId, origClientOrderId, recvWindow)
```
* **DELETE /fapi/v1/allOpenOrders (HMAC SHA256)** (Cancel All Open Orders (TRADE).)
```python
client.futures_cancel_all_open_orders(symbol, recvWindow)
```
* **DELETE /fapi/v1/batchOrders (HMAC SHA256)** (Cancel Multiple Orders (TRADE).)
```python
client.futures_cancel_orders(symbol, orderIdList, origClientOrderIdList, recvWindow)
```
* **POST /fapi/v1/countdownCancelAll (HMAC SHA256)** (Cancel all open orders of the specified symbol at the end of the specified countdown (TRADE).)
> :warning: Not yet implemented
* **GET /fapi/v1/openOrder (HMAC SHA256)** (Query Current Open Order (USER\_DATA).)
> :warning: Not yet implemented
* **GET /fapi/v1/openOrders (HMAC SHA256)** (Get all open orders on a symbol. **Careful** when accessing this with no symbol (USER\_DATA).)
```python
client.futures_get_open_orders(symbol, recvWindow)
```
* **GET /fapi/v1/allOrders (HMAC SHA256)** (Get all account orders; active, canceled, or filled (USER\_DATA).)
```python
client.futures_get_all_orders(symbol, orderId, startTime, endTime, limit, recvWindow)
```
* **GET /fapi/v2/balance (HMAC SHA256)** (Futures Account Balance V2 (USER\_DATA).)
> :warning: Probably broken, python code below is implemented on v1 endpoint.
```python
client.futures_account_balance(recvWindow)
```
* **GET /fapi/v2/account (HMAC SHA256)** (Account Information V2: Get current account information (USER\_DATA).)
> :warning: Probably broken, python code below is implemented on v1 endpoint.
```python
client.futures_account(recvWindow)
```
* **POST /fapi/v1/leverage (HMAC SHA256)** (Change user's initial leverage of specific symbol market (TRADE).)
```python
client.futures_change_leverage(symbol, leverage, recvWindow)
```
* **POST /fapi/v1/marginType (HMAC SHA256)** (Change the margin type for a symbol (TRADE).)
```python
client.futures_change_margin_type(symbol, marginType, recvWindow)
```
* **POST /fapi/v1/positionMargin (HMAC SHA256)** (Modify Isolated Position Margin (TRADE).)
```python
client.futures_change_position_margin(symbol, positionSide, amount, type, recvWindow)
```
* **GET /fapi/v1/positionMargin/history (HMAC SHA256)** (Get Position Margin Change History (TRADE).)
```python
client.futures_position_margin_history(symbol, type, startTime, endTime, limit, recvWindow)
```
* **GET /fapi/v2/positionRisk (HMAC SHA256)** (Position Information V2: Get current position information (USER\_DATA).)
> :warning: Probably broken, python code below is implemented on v1 endpoint.
```python
client.futures_position_information(symbol, recvWindow)
```
* **GET /fapi/v1/userTrades (HMAC SHA256)** (Account Trade List: Get trades for a specific account and symbol (USER\_DATA).)
```python
client.futures_account_trades(symbol, startTime, endTime, fromId, limit, recvWindow)
```
* **GET /fapi/v1/income (HMAC SHA256)** (Get Income History (USER\_DATA).)
```python
client.futures_income_history(symbol, incomeType, startTime, endTime, limit, recvWindow)
```
* **GET /fapi/v1/leverageBracket** (Notional and Leverage Brackets (USER\_DATA).)
> :warning: Probably broken, python code below is implemented on ticker/leverageBracket endpoint.
```python
client.futures_leverage_bracket(symbol, recvWindow)
```
* **GET /fapi/v1/adlQuantile** (Position ADL Quantile Estimation (USER\_DATA).)
> :warning: Not yet implemented
* **GET /fapi/v1/forceOrders** (User's Force Orders (USER\_DATA).)
> :warning: Not yet implemented
* **GET /fapi/v1/apiTradingStatus** (User API Trading Quantitative Rules Indicators (USER\_DATA).)
> :warning: Not yet implemented
* *User Data Streams*
> :warning: Not yet implemented
[Vanilla Options](https://binance-docs.github.io/apidocs/voptions/en/) [#vanilla-options]
* *Quoting interface*
* **GET /vapi/v1/ping** (Test connectivity)
```python
client.options_ping()
```
* **GET /vapi/v1/time** (Get server time)
```python
client.options_time()
```
* **GET /vapi/v1/optionInfo** (Get current trading pair info)
```python
client.options_info()
```
* **GET /vapi/v1/exchangeInfo** (Get current limit info and trading pair info)
```python
client.options_exchange_info()
```
* **GET /vapi/v1/index** (Get the spot index price)
```python
client.options_index_price(underlying)
```
* **GET /vapi/v1/ticker** (Get the latest price)
```python
client.options_price(symbol)
```
* **GET /vapi/v1/mark** (Get the latest mark price)
```python
client.options_mark_price(symbol)
```
* **GET /vapi/v1/depth** (Depth information)
```python
client.options_order_book(symbol, limit)
```
* **GET /vapi/v1/klines** (Candle data)
```python
client.options_klines(symbol, interval, startTime, endTime, limit)
```
* **GET /vapi/v1/trades** (Recently completed Option trades)
```python
client.options_recent_trades(symbol, limit)
```
* **GET /vapi/v1/historicalTrades** (Query trade history)
```python
client.options_historical_trades(symbol, fromId, limit)
```
* *Account and trading interface*
* **GET /vapi/v1/account (HMAC SHA256)** (Account asset info (USER\_DATA))
```python
client.options_account_info(recvWindow)
```
* **POST /vapi/v1/transfer (HMAC SHA256)** (Funds transfer (USER\_DATA))
```python
client.options_funds_transfer(currency, type, amount, recvWindow)
```
* **GET /vapi/v1/position (HMAC SHA256)** (Option holdings info (USER\_DATA))
```python
client.options_positions(symbol, recvWindow)
```
* **POST /vapi/v1/bill (HMAC SHA256)** (Account funding flow (USER\_DATA))
```python
client.options_bill(currency, recordId, startTime, endTime, limit, recvWindow)
```
* **POST /vapi/v1/order (HMAC SHA256)** (Option order (TRADE))
```python
client.options_place_order(symbol, side, type, quantity, price, timeInForce, reduceOnly, postOnly, \
newOrderRespType, clientOrderId, recvWindow, recvWindow)
```
* **POST /vapi/v1/batchOrders (HMAC SHA256)** (Place Multiple Option orders (TRADE))
```python
client.options_place_batch_order(orders, recvWindow)
```
* **DELETE /vapi/v1/order (HMAC SHA256)** (Cancel Option order (TRADE))
```python
client.options_cancel_order(symbol, orderId, clientOrderId, recvWindow)
```
* **DELETE /vapi/v1/batchOrders (HMAC SHA256)** (Cancel Multiple Option orders (TRADE))
```python
client.options_cancel_batch_order(symbol, orderIds, clientOrderIds, recvWindow)
```
* **DELETE /vapi/v1/allOpenOrders (HMAC SHA256)** (Cancel all Option orders (TRADE))
```python
client.options_cancel_all_orders(symbol, recvWindow)
```
* **GET /vapi/v1/order (HMAC SHA256)** (Query Option order (TRADE))
```python
client.options_query_order(symbol, orderId, clientOrderId, recvWindow)
```
* **GET /vapi/v1/openOrders (HMAC SHA256)** (Query current pending Option orders (TRADE))
```python
client.options_query_pending_orders(symbol, orderId, startTime, endTime, limit, recvWindow)
```
* **GET /vapi/v1/historyOrders (HMAC SHA256)** (Query Option order history (TRADE))
```python
client.options_query_order_history(symbol, orderId, startTime, endTime, limit, recvWindow)
```
* **GET /vapi/v1/userTrades (HMAC SHA256)** (Option Trade List (USER\_DATA))
```python
client.options_user_trades(symbol, fromId, startTime, endTime, limit, recvWindow)
```
[COIN-M Futures](https://binance-docs.github.io/apidocs/delivery/en/) [#coin-m-futures]
> :warning: Not yet implemented
[USDT-M Futures testnet](https://binance-docs.github.io/apidocs/testnet/en/) [#usdt-m-futures-testnet]
> :warning: Not yet implemented
[COIN-M Futures testnet](https://binance-docs.github.io/apidocs/delivery_testnet/en/) [#coin-m-futures-testnet]
> :warning: Not yet implemented
* **GET /sapi/v1/loan/vip/ongoing/orders**
```python
client.margin_v1_get_loan_vip_ongoing_orders(**params)
```
* **GET /sapi/v1/mining/payment/other**
```python
client.margin_v1_get_mining_payment_other(**params)
```
* **GET /dapi/v1/income/asyn/id**
```python
client.futures_coin_v1_get_income_asyn_id(**params)
```
* **GET /sapi/v1/simple-earn/flexible/history/subscriptionRecord**
```python
client.margin_v1_get_simple_earn_flexible_history_subscription_record(**params)
```
* **POST /sapi/v1/lending/auto-invest/one-off**
```python
client.margin_v1_post_lending_auto_invest_one_off(**params)
```
* **POST /sapi/v1/broker/subAccountApi/commission/coinFutures**
```python
client.margin_v1_post_broker_sub_account_api_commission_coin_futures(**params)
```
* **POST /papi/v1/repay-futures-negative-balance**
```python
client.papi_v1_post_repay_futures_negative_balance(**params)
```
* **POST /eapi/v1/block/order/execute**
```python
client.options_v1_post_block_order_execute(**params)
```
* **GET /sapi/v1/margin/dust**
```python
client.margin_v1_get_margin_dust(**params)
```
* **GET /dapi/v1/trades**
```python
client.futures_coin_v1_get_trades(**params)
```
* **POST /api/v3/orderList/otoco**
```python
client.v3_post_order_list_otoco(**params)
```
* **GET /fapi/v1/order/asyn**
```python
client.futures_v1_get_order_asyn(**params)
```
* **GET /sapi/v1/asset/custody/transfer-history**
```python
client.margin_v1_get_asset_custody_transfer_history(**params)
```
* **POST /fapi/v1/order/test**
```python
client.futures_v1_post_order_test(**params)
```
* **POST /sapi/v1/broker/subAccount/blvt**
```python
client.margin_v1_post_broker_sub_account_blvt(**params)
```
* **POST /sapi/v1/sol-staking/sol/redeem**
```python
client.margin_v1_post_sol_staking_sol_redeem(**params)
```
* **GET /eapi/v1/countdownCancelAll**
```python
client.options_v1_get_countdown_cancel_all(**params)
```
* **GET /sapi/v1/margin/tradeCoeff**
```python
client.margin_v1_get_margin_trade_coeff(**params)
```
* **GET /sapi/v1/sub-account/futures/positionRisk**
```python
client.margin_v1_get_sub_account_futures_position_risk(**params)
```
* **GET /dapi/v1/orderAmendment**
```python
client.futures_coin_v1_get_order_amendment(**params)
```
* **GET /papi/v1/margin/openOrders**
```python
client.papi_v1_get_margin_open_orders(**params)
```
* **GET /sapi/v1/margin/available-inventory**
```python
client.margin_v1_get_margin_available_inventory(**params)
```
* **POST /sapi/v1/account/apiRestrictions/ipRestriction/ipList**
```python
client.margin_v1_post_account_api_restrictions_ip_restriction_ip_list(**params)
```
* **GET /sapi/v2/eth-staking/account**
```python
client.margin_v2_get_eth_staking_account(**params)
```
* **POST /papi/v1/asset-collection**
```python
client.papi_v1_post_asset_collection(**params)
```
* **GET /papi/v1/um/trade/asyn/id**
```python
client.papi_v1_get_um_trade_asyn_id(**params)
```
* **POST /sapi/v1/staking/redeem**
```python
client.margin_v1_post_staking_redeem(**params)
```
* **GET /sapi/v1/loan/income**
```python
client.margin_v1_get_loan_income(**params)
```
* **GET /eapi/v1/depth**
```python
client.options_v1_get_depth(**params)
```
* **GET /dapi/v1/pmAccountInfo**
```python
client.futures_coin_v1_get_pm_account_info(**params)
```
* **GET /sapi/v1/managed-subaccount/queryTransLogForInvestor**
```python
client.margin_v1_get_managed_subaccount_query_trans_log_for_investor(**params)
```
* **POST /sapi/v1/dci/product/auto\_compound/edit-status**
```python
client.margin_v1_post_dci_product_auto_compound_edit_status(**params)
```
* **GET /fapi/v1/trade/asyn**
```python
client.futures_v1_get_trade_asyn(**params)
```
* **GET /sapi/v1/loan/vip/request/interestRate**
```python
client.margin_v1_get_loan_vip_request_interest_rate(**params)
```
* **GET /fapi/v1/fundingInfo**
```python
client.futures_v1_get_funding_info(**params)
```
* **GET /sapi/v2/loan/flexible/repay/rate**
```python
client.margin_v2_get_loan_flexible_repay_rate(**params)
```
* **GET /sapi/v1/lending/auto-invest/plan/id**
```python
client.margin_v1_get_lending_auto_invest_plan_id(**params)
```
* **POST /sapi/v1/loan/adjust/ltv**
```python
client.margin_v1_post_loan_adjust_ltv(**params)
```
* **GET /sapi/v1/bnbBurn**
```python
client.margin_v1_get_bnb_burn(**params)
```
* **GET /papi/v1/um/order**
```python
client.papi_v1_get_um_order(**params)
```
* **GET /sapi/v1/mining/statistics/user/status**
```python
client.margin_v1_get_mining_statistics_user_status(**params)
```
* **POST /sapi/v1/staking/purchase**
```python
client.margin_v1_post_staking_purchase(**params)
```
* **POST /sapi/v1/giftcard/redeemCode**
```python
client.margin_v1_post_giftcard_redeem_code(**params)
```
* **GET /eapi/v1/userTrades**
```python
client.options_v1_get_user_trades(**params)
```
* **GET /sapi/v1/broker/transfer/futures**
```python
client.margin_v1_get_broker_transfer_futures(**params)
```
* **POST /sapi/v1/algo/spot/newOrderTwap**
```python
client.margin_v1_post_algo_spot_new_order_twap(**params)
```
* **GET /sapi/v1/lending/auto-invest/target-asset/list**
```python
client.margin_v1_get_lending_auto_invest_target_asset_list(**params)
```
* **GET /sapi/v1/capital/deposit/address/list**
```python
client.margin_v1_get_capital_deposit_address_list(**params)
```
* **POST /sapi/v1/broker/subAccount/bnbBurn/marginInterest**
```python
client.margin_v1_post_broker_sub_account_bnb_burn_margin_interest(**params)
```
* **POST /sapi/v2/loan/flexible/repay**
```python
client.margin_v2_post_loan_flexible_repay(**params)
```
* **GET /sapi/v2/loan/flexible/loanable/data**
```python
client.margin_v2_get_loan_flexible_loanable_data(**params)
```
* **POST /sapi/v1/broker/subAccountApi/permission**
```python
client.margin_v1_post_broker_sub_account_api_permission(**params)
```
* **GET /sapi/v1/dci/product/positions**
```python
client.margin_v1_get_dci_product_positions(**params)
```
* **POST /sapi/v1/convert/limit/cancelOrder**
```python
client.margin_v1_post_convert_limit_cancel_order(**params)
```
* **GET /sapi/v1/margin/exchange-small-liability-history**
```python
client.margin_v1_get_margin_exchange_small_liability_history(**params)
```
* **GET /sapi/v1/mining/hash-transfer/config/details/list**
```python
client.margin_v1_get_mining_hash_transfer_config_details_list(**params)
```
* **GET /sapi/v1/mining/hash-transfer/profit/details**
```python
client.margin_v1_get_mining_hash_transfer_profit_details(**params)
```
* **GET /sapi/v1/broker/subAccount**
```python
client.margin_v1_get_broker_sub_account(**params)
```
* **GET /sapi/v1/portfolio/balance**
```python
client.margin_v1_get_portfolio_balance(**params)
```
* **POST /sapi/v1/sub-account/eoptions/enable**
```python
client.margin_v1_post_sub_account_eoptions_enable(**params)
```
* **POST /papi/v1/ping**
```python
client.papi_v1_post_ping(**params)
```
* **GET /sapi/v1/loan/loanable/data**
```python
client.margin_v1_get_loan_loanable_data(**params)
```
* **POST /sapi/v1/eth-staking/wbeth/unwrap**
```python
client.margin_v1_post_eth_staking_wbeth_unwrap(**params)
```
* **PUT /fapi/v1/order**
```python
client.futures_v1_put_order(**params)
```
* **GET /sapi/v1/eth-staking/eth/history/stakingHistory**
```python
client.margin_v1_get_eth_staking_eth_history_staking_history(**params)
```
* **GET /papi/v1/um/conditional/openOrder**
```python
client.papi_v1_get_um_conditional_open_order(**params)
```
* **GET /dapi/v1/openOrders**
```python
client.futures_coin_v1_get_open_orders(**params)
```
* **GET /eapi/v1/order**
```python
client.options_v1_get_order(**params)
```
* **POST /sapi/v1/convert/acceptQuote**
```python
client.margin_v1_post_convert_accept_quote(**params)
```
* **GET /sapi/v1/staking/stakingRecord**
```python
client.margin_v1_get_staking_staking_record(**params)
```
* **GET /sapi/v1/broker/rebate/recentRecord**
```python
client.margin_v1_get_broker_rebate_recent_record(**params)
```
* **GET /eapi/v1/block/order/orders**
```python
client.options_v1_get_block_order_orders(**params)
```
* **GET /sapi/v1/asset/transfer**
```python
client.margin_v1_get_asset_transfer(**params)
```
* **GET /sapi/v1/loan/vip/collateral/account**
```python
client.margin_v1_get_loan_vip_collateral_account(**params)
```
* **GET /sapi/v1/algo/spot/openOrders**
```python
client.margin_v1_get_algo_spot_open_orders(**params)
```
* **POST /sapi/v1/loan/repay**
```python
client.margin_v1_post_loan_repay(**params)
```
* **POST /sapi/v1/margin/isolated/account**
```python
client.margin_v1_post_margin_isolated_account(**params)
```
* **GET /dapi/v1/fundingInfo**
```python
client.futures_coin_v1_get_funding_info(**params)
```
* **GET /papi/v1/cm/leverageBracket**
```python
client.papi_v1_get_cm_leverage_bracket(**params)
```
* **POST /sapi/v1/simple-earn/locked/subscribe**
```python
client.margin_v1_post_simple_earn_locked_subscribe(**params)
```
* **GET /sapi/v1/margin/leverageBracket**
```python
client.margin_v1_get_margin_leverage_bracket(**params)
```
* **GET /sapi/v2/portfolio/collateralRate**
```python
client.margin_v2_get_portfolio_collateral_rate(**params)
```
* **POST /sapi/v2/loan/flexible/adjust/ltv**
```python
client.margin_v2_post_loan_flexible_adjust_ltv(**params)
```
* **GET /sapi/v1/convert/orderStatus**
```python
client.margin_v1_get_convert_order_status(**params)
```
* **POST /sapi/v1/margin/dust**
```python
client.margin_v1_post_margin_dust(**params)
```
* **GET /sapi/v1/broker/subAccountApi/ipRestriction**
```python
client.margin_v1_get_broker_sub_account_api_ip_restriction(**params)
```
* **GET /papi/v1/um/conditional/allOrders**
```python
client.papi_v1_get_um_conditional_all_orders(**params)
```
* **PUT /eapi/v1/block/order/create**
```python
client.options_v1_put_block_order_create(**params)
```
* **POST /sapi/v1/dci/product/subscribe**
```python
client.margin_v1_post_dci_product_subscribe(**params)
```
* **GET /fapi/v1/income/asyn/id**
```python
client.futures_v1_get_income_asyn_id(**params)
```
* **GET /dapi/v1/positionRisk**
```python
client.futures_coin_v1_get_position_risk(**params)
```
* **POST /eapi/v1/countdownCancelAll**
```python
client.options_v1_post_countdown_cancel_all(**params)
```
* **POST /papi/v1/repay-futures-switch**
```python
client.papi_v1_post_repay_futures_switch(**params)
```
* **POST /sapi/v1/mining/hash-transfer/config/cancel**
```python
client.margin_v1_post_mining_hash_transfer_config_cancel(**params)
```
* **GET /sapi/v1/broker/subAccount/depositHist**
```python
client.margin_v1_get_broker_sub_account_deposit_hist(**params)
```
* **POST /eapi/v1/block/order/create**
```python
client.options_v1_post_block_order_create(**params)
```
* **GET /sapi/v1/capital/deposit/subAddress**
```python
client.margin_v1_get_capital_deposit_sub_address(**params)
```
* **GET /sapi/v1/mining/payment/list**
```python
client.margin_v1_get_mining_payment_list(**params)
```
* **GET /fapi/v1/pmAccountInfo**
```python
client.futures_v1_get_pm_account_info(**params)
```
* **GET /dapi/v1/adlQuantile**
```python
client.futures_coin_v1_get_adl_quantile(**params)
```
* **GET /eapi/v1/income/asyn/id**
```python
client.options_v1_get_income_asyn_id(**params)
```
* **POST /api/v3/cancelReplace**
```python
client.v3_post_cancel_replace(**params)
```
* **PUT /papi/v1/um/order**
```python
client.papi_v1_put_um_order(**params)
```
* **GET /sapi/v1/sub-account/futures/accountSummary**
```python
client.margin_v1_get_sub_account_futures_account_summary(**params)
```
* **GET /papi/v1/um/symbolConfig**
```python
client.papi_v1_get_um_symbol_config(**params)
```
* **GET /papi/v1/um/userTrades**
```python
client.papi_v1_get_um_user_trades(**params)
```
* **GET /sapi/v1/staking/productList**
```python
client.margin_v1_get_staking_product_list(**params)
```
* **POST /sapi/v1/asset/get-funding-asset**
```python
client.margin_v1_post_asset_get_funding_asset(**params)
```
* **POST /sapi/v1/bnbBurn**
```python
client.margin_v1_post_bnb_burn(**params)
```
* **POST /papi/v1/um/order**
```python
client.papi_v1_post_um_order(**params)
```
* **GET /dapi/v1/order/asyn**
```python
client.futures_coin_v1_get_order_asyn(**params)
```
* **GET /sapi/v1/c2c/orderMatch/listUserOrderHistory**
```python
client.margin_v1_get_c2c_order_match_list_user_order_history(**params)
```
* **POST /sapi/v1/simple-earn/flexible/subscribe**
```python
client.margin_v1_post_simple_earn_flexible_subscribe(**params)
```
* **POST /sapi/v1/broker/transfer/futures**
```python
client.margin_v1_post_broker_transfer_futures(**params)
```
* **POST /api/v3/order/cancelReplace**
```python
client.v3_post_order_cancel_replace(**params)
```
* **POST /sapi/v1/sol-staking/sol/stake**
```python
client.margin_v1_post_sol_staking_sol_stake(**params)
```
* **POST /sapi/v1/loan/borrow**
```python
client.margin_v1_post_loan_borrow(**params)
```
* **GET /sapi/v1/managed-subaccount/info**
```python
client.margin_v1_get_managed_subaccount_info(**params)
```
* **POST /sapi/v1/lending/auto-invest/plan/edit-status**
```python
client.margin_v1_post_lending_auto_invest_plan_edit_status(**params)
```
* **GET /fapi/v1/symbolConfig**
```python
client.futures_v1_get_symbol_config(**params)
```
* **GET /sapi/v1/sol-staking/sol/history/unclaimedRewards**
```python
client.margin_v1_get_sol_staking_sol_history_unclaimed_rewards(**params)
```
* **POST /sapi/v1/asset/convert-transfer/queryByPage**
```python
client.margin_v1_post_asset_convert_transfer_query_by_page(**params)
```
* **GET /sapi/v1/sub-account/universalTransfer**
```python
client.margin_v1_get_sub_account_universal_transfer(**params)
```
* **GET /sapi/v1/sol-staking/sol/history/boostRewardsHistory**
```python
client.margin_v1_get_sol_staking_sol_history_boost_rewards_history(**params)
```
* **GET /sapi/v1/lending/auto-invest/one-off/status**
```python
client.margin_v1_get_lending_auto_invest_one_off_status(**params)
```
* **GET /sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage**
```python
client.margin_v1_get_asset_ledger_transfer_cloud_mining_query_by_page(**params)
```
* **DELETE /sapi/v1/margin/orderList**
```python
client.margin_v1_delete_margin_order_list(**params)
```
* **GET /sapi/v1/mining/pub/coinList**
```python
client.margin_v1_get_mining_pub_coin_list(**params)
```
* **GET /sapi/v2/loan/flexible/repay/history**
```python
client.margin_v2_get_loan_flexible_repay_history(**params)
```
* **GET /fapi/v3/account**
```python
client.futures_v3_get_account(**params)
```
* **POST /api/v3/sor/order**
```python
client.v3_post_sor_order(**params)
```
* **POST /sapi/v1/capital/deposit/credit-apply**
```python
client.margin_v1_post_capital_deposit_credit_apply(**params)
```
* **PUT /fapi/v1/batchOrder**
```python
client.futures_v1_put_batch_order(**params)
```
* **GET /sapi/v1/fiat/payments**
```python
client.margin_v1_get_fiat_payments(**params)
```
* **GET /api/v3/myPreventedMatches**
```python
client.v3_get_my_prevented_matches(**params)
```
* **GET /dapi/v1/forceOrders**
```python
client.futures_coin_v1_get_force_orders(**params)
```
* **POST /sapi/v1/asset/transfer**
```python
client.margin_v1_post_asset_transfer(**params)
```
* **GET /sapi/v1/mining/statistics/user/list**
```python
client.margin_v1_get_mining_statistics_user_list(**params)
```
* **GET /api/v3/ticker/tradingDay**
```python
client.v3_get_ticker_trading_day(**params)
```
* **GET /sapi/v1/mining/worker/detail**
```python
client.margin_v1_get_mining_worker_detail(**params)
```
* **GET /sapi/v1/managed-subaccount/fetch-future-asset**
```python
client.margin_v1_get_managed_subaccount_fetch_future_asset(**params)
```
* **GET /dapi/v1/pmExchangeInfo**
```python
client.futures_coin_v1_get_pm_exchange_info(**params)
```
* **POST /sapi/v1/convert/getQuote**
```python
client.margin_v1_post_convert_get_quote(**params)
```
* **GET /api/v3/uiKlines**
```python
client.v3_get_ui_klines(**params)
```
* **GET /sapi/v1/margin/rateLimit/order**
```python
client.margin_v1_get_margin_rate_limit_order(**params)
```
* **GET /sapi/v1/localentity/vasp**
```python
client.margin_v1_get_localentity_vasp(**params)
```
* **GET /fapi/v1/commissionRate**
```python
client.futures_v1_get_commission_rate(**params)
```
* **GET /sapi/v1/sol-staking/sol/history/rateHistory**
```python
client.margin_v1_get_sol_staking_sol_history_rate_history(**params)
```
* **POST /sapi/v1/broker/subAccountApi/ipRestriction**
```python
client.margin_v1_post_broker_sub_account_api_ip_restriction(**params)
```
* **GET /eapi/v1/block/user-trades**
```python
client.options_v1_get_block_user_trades(**params)
```
* **GET /dapi/v1/order/asyn/id**
```python
client.futures_coin_v1_get_order_asyn_id(**params)
```
* **GET /sapi/v1/sol-staking/account**
```python
client.margin_v1_get_sol_staking_account(**params)
```
* **GET /sapi/v1/account/info**
```python
client.margin_v1_get_account_info(**params)
```
* **POST /sapi/v1/sub-account/transfer/subToMaster**
```python
client.margin_v1_post_sub_account_transfer_sub_to_master(**params)
```
* **POST /sapi/v1/portfolio/repay-futures-switch**
```python
client.margin_v1_post_portfolio_repay_futures_switch(**params)
```
* **GET /sapi/v1/giftcard/buyCode/token-limit**
```python
client.margin_v1_get_giftcard_buy_code_token_limit(**params)
```
* **GET /sapi/v1/capital/deposit/subHisrec**
```python
client.margin_v1_get_capital_deposit_sub_hisrec(**params)
```
* **POST /sapi/v1/loan/vip/borrow**
```python
client.margin_v1_post_loan_vip_borrow(**params)
```
* **GET /papi/v1/um/order/asyn/id**
```python
client.papi_v1_get_um_order_asyn_id(**params)
```
* **GET /papi/v1/cm/account**
```python
client.papi_v1_get_cm_account(**params)
```
* **DELETE /papi/v1/um/conditional/order**
```python
client.papi_v1_delete_um_conditional_order(**params)
```
* **GET /sapi/v2/loan/flexible/ltv/adjustment/history**
```python
client.margin_v2_get_loan_flexible_ltv_adjustment_history(**params)
```
* **DELETE /eapi/v1/allOpenOrdersByUnderlying**
```python
client.options_v1_delete_all_open_orders_by_underlying(**params)
```
* **PUT /papi/v1/cm/order**
```python
client.papi_v1_put_cm_order(**params)
```
* **GET /sapi/v1/broker/subAccount/futuresSummary**
```python
client.margin_v1_get_broker_sub_account_futures_summary(**params)
```
* **GET /dapi/v1/continuousKlines**
```python
client.futures_coin_v1_get_continuous_klines(**params)
```
* **GET /fapi/v1/accountConfig**
```python
client.futures_v1_get_account_config(**params)
```
* **DELETE /dapi/v1/batchOrders**
```python
client.futures_coin_v1_delete_batch_orders(**params)
```
* **GET /sapi/v1/broker/subAccount/spotSummary**
```python
client.margin_v1_get_broker_sub_account_spot_summary(**params)
```
* **GET /papi/v1/margin/openOrderList**
```python
client.papi_v1_get_margin_open_order_list(**params)
```
* **POST /sapi/v1/sub-account/blvt/enable**
```python
client.margin_v1_post_sub_account_blvt_enable(**params)
```
* **GET /dapi/v1/trade/asyn**
```python
client.futures_coin_v1_get_trade_asyn(**params)
```
* **GET /sapi/v1/algo/spot/historicalOrders**
```python
client.margin_v1_get_algo_spot_historical_orders(**params)
```
* **GET /sapi/v1/loan/vip/repay/history**
```python
client.margin_v1_get_loan_vip_repay_history(**params)
```
* **GET /eapi/v1/openInterest**
```python
client.options_v1_get_open_interest(**params)
```
* **GET /papi/v1/um/adlQuantile**
```python
client.papi_v1_get_um_adl_quantile(**params)
```
* **GET /eapi/v1/account**
```python
client.options_v1_get_account(**params)
```
* **POST /sapi/v1/sub-account/universalTransfer**
```python
client.margin_v1_post_sub_account_universal_transfer(**params)
```
* **GET /papi/v1/margin/allOrderList**
```python
client.papi_v1_get_margin_all_order_list(**params)
```
* **GET /fapi/v2/ticker/price**
```python
client.futures_v2_get_ticker_price(**params)
```
* **GET /sapi/v1/loan/borrow/history**
```python
client.margin_v1_get_loan_borrow_history(**params)
```
* **GET /papi/v1/um/account**
```python
client.papi_v1_get_um_account(**params)
```
* **POST /sapi/v1/lending/auto-invest/redeem**
```python
client.margin_v1_post_lending_auto_invest_redeem(**params)
```
* **POST /sapi/v1/managed-subaccount/deposit**
```python
client.margin_v1_post_managed_subaccount_deposit(**params)
```
* **GET /dapi/v1/fundingRate**
```python
client.futures_coin_v1_get_funding_rate(**params)
```
* **GET /fapi/v1/trade/asyn/id**
```python
client.futures_v1_get_trade_asyn_id(**params)
```
* **DELETE /sapi/v1/sub-account/subAccountApi/ipRestriction/ipList**
```python
client.margin_v1_delete_sub_account_sub_account_api_ip_restriction_ip_list(**params)
```
* **GET /sapi/v1/copyTrading/futures/userStatus**
```python
client.margin_v1_get_copy_trading_futures_user_status(**params)
```
* **GET /papi/v1/um/income**
```python
client.papi_v1_get_um_income(**params)
```
* **GET /papi/v1/um/openOrders**
```python
client.papi_v1_get_um_open_orders(**params)
```
* **GET /eapi/v1/marginAccount**
```python
client.options_v1_get_margin_account(**params)
```
* **GET /dapi/v1/premiumIndex**
```python
client.futures_coin_v1_get_premium_index(**params)
```
* **POST /sapi/v1/localentity/withdraw/apply**
```python
client.margin_v1_post_localentity_withdraw_apply(**params)
```
* **GET /sapi/v1/margin/orderList**
```python
client.margin_v1_get_margin_order_list(**params)
```
* **GET /papi/v1/um/feeBurn**
```python
client.papi_v1_get_um_fee_burn(**params)
```
* **GET /fapi/v1/multiAssetsMargin**
```python
client.futures_v1_get_multi_assets_margin(**params)
```
* **GET /sapi/v1/giftcard/verify**
```python
client.margin_v1_get_giftcard_verify(**params)
```
* **GET /sapi/v1/asset/wallet/balance**
```python
client.margin_v1_get_asset_wallet_balance(**params)
```
* **POST /sapi/v1/algo/futures/newOrderTwap**
```python
client.margin_v1_post_algo_futures_new_order_twap(**params)
```
* **GET /sapi/v1/margin/crossMarginCollateralRatio**
```python
client.margin_v1_get_margin_cross_margin_collateral_ratio(**params)
```
* **POST /sapi/v2/eth-staking/eth/stake**
```python
client.margin_v2_post_eth_staking_eth_stake(**params)
```
* **POST /sapi/v1/loan/flexible/repay/history**
```python
client.margin_v1_post_loan_flexible_repay_history(**params)
```
* **GET /dapi/v1/exchangeInfo**
```python
client.futures_coin_v1_get_exchange_info(**params)
```
* **POST /sapi/v1/sub-account/futures/enable**
```python
client.margin_v1_post_sub_account_futures_enable(**params)
```
* **GET /sapi/v1/lending/auto-invest/index/info**
```python
client.margin_v1_get_lending_auto_invest_index_info(**params)
```
* **GET /sapi/v2/sub-account/futures/positionRisk**
```python
client.margin_v2_get_sub_account_futures_position_risk(**params)
```
* **GET /sapi/v1/sub-account/margin/account**
```python
client.margin_v1_get_sub_account_margin_account(**params)
```
* **GET /papi/v1/rateLimit/order**
```python
client.papi_v1_get_rate_limit_order(**params)
```
* **GET /sapi/v1/sol-staking/sol/history/redemptionHistory**
```python
client.margin_v1_get_sol_staking_sol_history_redemption_history(**params)
```
* **GET /fapi/v1/markPriceKlines**
```python
client.futures_v1_get_mark_price_klines(**params)
```
* **GET /sapi/v1/broker/rebate/futures/recentRecord**
```python
client.margin_v1_get_broker_rebate_futures_recent_record(**params)
```
* **GET /sapi/v3/broker/subAccount/futuresSummary**
```python
client.margin_v3_get_broker_sub_account_futures_summary(**params)
```
* **GET /dapi/v1/aggTrades**
```python
client.futures_coin_v1_get_agg_trades(**params)
```
* **GET /eapi/v1/exchangeInfo**
```python
client.options_v1_get_exchange_info(**params)
```
* **GET /sapi/v1/lending/auto-invest/target-asset/roi/list**
```python
client.margin_v1_get_lending_auto_invest_target_asset_roi_list(**params)
```
* **GET /sapi/v1/broker/universalTransfer**
```python
client.margin_v1_get_broker_universal_transfer(**params)
```
* **POST /sapi/v1/sub-account/futures/transfer**
```python
client.margin_v1_post_sub_account_futures_transfer(**params)
```
* **PUT /fapi/v1/batchOrders**
```python
client.futures_v1_put_batch_orders(**params)
```
* **POST /eapi/v1/countdownCancelAllHeartBeat**
```python
client.options_v1_post_countdown_cancel_all_heart_beat(**params)
```
* **GET /sapi/v1/loan/collateral/data**
```python
client.margin_v1_get_loan_collateral_data(**params)
```
* **GET /sapi/v1/margin/borrow-repay**
```python
client.margin_v1_get_margin_borrow_repay(**params)
```
* **GET /sapi/v1/loan/repay/history**
```python
client.margin_v1_get_loan_repay_history(**params)
```
* **GET /dapi/v2/leverageBracket**
```python
client.futures_coin_v2_get_leverage_bracket(**params)
```
* **GET /fapi/v1/indexPriceKlines**
```python
client.futures_v1_get_index_price_klines(**params)
```
* **POST /sapi/v1/convert/limit/placeOrder**
```python
client.margin_v1_post_convert_limit_place_order(**params)
```
* **GET /fapi/v1/convert/exchangeInfo**
```python
client.futures_v1_get_convert_exchange_info(**params)
```
* **GET /dapi/v1/historicalTrades**
```python
client.futures_coin_v1_get_historical_trades(**params)
```
* **DELETE /sapi/v1/broker/subAccountApi/ipRestriction/ipList**
```python
client.margin_v1_delete_broker_sub_account_api_ip_restriction_ip_list(**params)
```
* **GET /sapi/v1/staking/personalLeftQuota**
```python
client.margin_v1_get_staking_personal_left_quota(**params)
```
* **POST /sapi/v1/sub-account/virtualSubAccount**
```python
client.margin_v1_post_sub_account_virtual_sub_account(**params)
```
* **GET /sapi/v1/staking/position**
```python
client.margin_v1_get_staking_position(**params)
```
* **GET /papi/v1/um/income/asyn/id**
```python
client.papi_v1_get_um_income_asyn_id(**params)
```
* **PUT /sapi/v1/localentity/deposit/provide-info**
```python
client.margin_v1_put_localentity_deposit_provide_info(**params)
```
* **POST /sapi/v1/portfolio/mint**
```python
client.margin_v1_post_portfolio_mint(**params)
```
* **POST /sapi/v1/sub-account/transfer/subToSub**
```python
client.margin_v1_post_sub_account_transfer_sub_to_sub(**params)
```
* **GET /fapi/v1/orderAmendment**
```python
client.futures_v1_get_order_amendment(**params)
```
* **POST /sapi/v1/sol-staking/sol/claim**
```python
client.margin_v1_post_sol_staking_sol_claim(**params)
```
* **GET /sapi/v1/account/apiRestrictions**
```python
client.margin_v1_get_account_api_restrictions(**params)
```
* **GET /papi/v1/um/allOrders**
```python
client.papi_v1_get_um_all_orders(**params)
```
* **POST /sapi/v1/giftcard/createCode**
```python
client.margin_v1_post_giftcard_create_code(**params)
```
* **GET /sapi/v1/lending/auto-invest/rebalance/history**
```python
client.margin_v1_get_lending_auto_invest_rebalance_history(**params)
```
* **GET /sapi/v1/loan/repay/collateral/rate**
```python
client.margin_v1_get_loan_repay_collateral_rate(**params)
```
* **GET /sapi/v1/mining/payment/uid**
```python
client.margin_v1_get_mining_payment_uid(**params)
```
* **GET /sapi/v2/loan/flexible/borrow/history**
```python
client.margin_v2_get_loan_flexible_borrow_history(**params)
```
* **POST /sapi/v1/asset/dust**
```python
client.margin_v1_post_asset_dust(**params)
```
* **GET /sapi/v1/capital/contract/convertible-coins**
```python
client.margin_v1_get_capital_contract_convertible_coins(**params)
```
* **POST /sapi/v1/asset/dust-btc**
```python
client.margin_v1_post_asset_dust_btc(**params)
```
* **GET /papi/v1/um/conditional/openOrders**
```python
client.papi_v1_get_um_conditional_open_orders(**params)
```
* **GET /sapi/v1/sub-account/spotSummary**
```python
client.margin_v1_get_sub_account_spot_summary(**params)
```
* **POST /sapi/v1/broker/subAccountApi/permission/vanillaOptions**
```python
client.margin_v1_post_broker_sub_account_api_permission_vanilla_options(**params)
```
* **GET /sapi/v1/lending/auto-invest/redeem/history**
```python
client.margin_v1_get_lending_auto_invest_redeem_history(**params)
```
* **GET /fapi/v3/positionRisk**
```python
client.futures_v3_get_position_risk(**params)
```
* **GET /dapi/v1/klines**
```python
client.futures_coin_v1_get_klines(**params)
```
* **GET /sapi/v2/localentity/withdraw/history**
```python
client.margin_v2_get_localentity_withdraw_history(**params)
```
* **GET /sapi/v1/eth-staking/eth/history/redemptionHistory**
```python
client.margin_v1_get_eth_staking_eth_history_redemption_history(**params)
```
* **POST /eapi/v1/transfer**
```python
client.options_v1_post_transfer(**params)
```
* **GET /fapi/v1/feeBurn**
```python
client.futures_v1_get_fee_burn(**params)
```
* **GET /sapi/v1/lending/auto-invest/index/user-summary**
```python
client.margin_v1_get_lending_auto_invest_index_user_summary(**params)
```
* **POST /sapi/v2/loan/flexible/borrow**
```python
client.margin_v2_post_loan_flexible_borrow(**params)
```
* **DELETE /dapi/v1/order**
```python
client.futures_coin_v1_delete_order(**params)
```
* **POST /sapi/v3/asset/getUserAsset**
```python
client.margin_v3_post_asset_get_user_asset(**params)
```
* **POST /sapi/v1/loan/vip/repay**
```python
client.margin_v1_post_loan_vip_repay(**params)
```
* **GET /sapi/v2/sub-account/futures/accountSummary**
```python
client.margin_v2_get_sub_account_futures_account_summary(**params)
```
* **GET /dapi/v1/commissionRate**
```python
client.futures_coin_v1_get_commission_rate(**params)
```
* **GET /papi/v1/um/conditional/orderHistory**
```python
client.papi_v1_get_um_conditional_order_history(**params)
```
* **GET /fapi/v3/balance**
```python
client.futures_v3_get_balance(**params)
```
* **GET /sapi/v1/convert/assetInfo**
```python
client.margin_v1_get_convert_asset_info(**params)
```
* **POST /api/v3/sor/order/test**
```python
client.v3_post_sor_order_test(**params)
```
* **GET /sapi/v1/giftcard/cryptography/rsa-public-key**
```python
client.margin_v1_get_giftcard_cryptography_rsa_public_key(**params)
```
* **POST /sapi/v1/broker/universalTransfer**
```python
client.margin_v1_post_broker_universal_transfer(**params)
```
* **GET /dapi/v1/allOrders**
```python
client.futures_coin_v1_get_all_orders(**params)
```
* **POST /sapi/v1/margin/borrow-repay**
```python
client.margin_v1_post_margin_borrow_repay(**params)
```
* **GET /fapi/v1/assetIndex**
```python
client.futures_v1_get_asset_index(**params)
```
* **GET /api/v3/rateLimit/order**
```python
client.v3_get_rate_limit_order(**params)
```
* **GET /papi/v1/um/orderAmendment**
```python
client.papi_v1_get_um_order_amendment(**params)
```
* **GET /sapi/v1/account/apiRestrictions/ipRestriction**
```python
client.margin_v1_get_account_api_restrictions_ip_restriction(**params)
```
* **POST /sapi/v1/broker/subAccount/bnbBurn/spot**
```python
client.margin_v1_post_broker_sub_account_bnb_burn_spot(**params)
```
* **POST /papi/v1/um/conditional/order**
```python
client.papi_v1_post_um_conditional_order(**params)
```
* **PUT /dapi/v1/batchOrders**
```python
client.futures_coin_v1_put_batch_orders(**params)
```
* **DELETE /api/v3/openOrders**
```python
client.v3_delete_open_orders(**params)
```
* **GET /sapi/v1/margin/delist-schedule**
```python
client.margin_v1_get_margin_delist_schedule(**params)
```
* **POST /sapi/v1/broker/subAccountApi/permission/universalTransfer**
```python
client.margin_v1_post_broker_sub_account_api_permission_universal_transfer(**params)
```
* **GET /papi/v1/cm/positionRisk**
```python
client.papi_v1_get_cm_position_risk(**params)
```
* **GET /papi/v1/cm/income**
```python
client.papi_v1_get_cm_income(**params)
```
* **POST /sapi/v1/giftcard/buyCode**
```python
client.margin_v1_post_giftcard_buy_code(**params)
```
* **GET /fapi/v1/balance**
```python
client.futures_v1_get_balance(**params)
```
* **GET /api/v3/myAllocations**
```python
client.v3_get_my_allocations(**params)
```
* **GET /papi/v1/margin/order**
```python
client.papi_v1_get_margin_order(**params)
```
* **GET /sapi/v1/loan/ltv/adjustment/history**
```python
client.margin_v1_get_loan_ltv_adjustment_history(**params)
```
* **POST /dapi/v1/batchOrders**
```python
client.futures_coin_v1_post_batch_orders(**params)
```
* **GET /sapi/v1/localentity/withdraw/history**
```python
client.margin_v1_get_localentity_withdraw_history(**params)
```
* **GET /sapi/v1/sub-account/status**
```python
client.margin_v1_get_sub_account_status(**params)
```
* **POST /sapi/v2/sub-account/subAccountApi/ipRestriction**
```python
client.margin_v2_post_sub_account_sub_account_api_ip_restriction(**params)
```
* **GET /dapi/v1/trade/asyn/id**
```python
client.futures_coin_v1_get_trade_asyn_id(**params)
```
* **GET /fapi/v1/rateLimit/order**
```python
client.futures_v1_get_rate_limit_order(**params)
```
* **GET /sapi/v1/broker/subAccountApi/commission/futures**
```python
client.margin_v1_get_broker_sub_account_api_commission_futures(**params)
```
* **GET /sapi/v1/sol-staking/sol/history/stakingHistory**
```python
client.margin_v1_get_sol_staking_sol_history_staking_history(**params)
```
* **DELETE /sapi/v1/algo/spot/order**
```python
client.margin_v1_delete_algo_spot_order(**params)
```
* **GET /papi/v1/repay-futures-switch**
```python
client.papi_v1_get_repay_futures_switch(**params)
```
* **POST /sapi/v1/margin/max-leverage**
```python
client.margin_v1_post_margin_max_leverage(**params)
```
* **DELETE /sapi/v1/account/apiRestrictions/ipRestriction/ipList**
```python
client.margin_v1_delete_account_api_restrictions_ip_restriction_ip_list(**params)
```
* **POST /sapi/v1/capital/contract/convertible-coins**
```python
client.margin_v1_post_capital_contract_convertible_coins(**params)
```
* **GET /sapi/v1/managed-subaccount/marginAsset**
```python
client.margin_v1_get_managed_subaccount_margin_asset(**params)
```
* **GET /sapi/v3/sub-account/assets**
```python
client.margin_v3_get_sub_account_assets(**params)
```
* **GET /fapi/v1/continuousKlines**
```python
client.futures_v1_get_continuous_klines(**params)
```
* **GET /sapi/v1/sub-account/futures/internalTransfer**
```python
client.margin_v1_get_sub_account_futures_internal_transfer(**params)
```
* **GET /sapi/v1/capital/withdraw/apply**
```python
client.margin_v1_get_capital_withdraw_apply(**params)
```
* **POST /sapi/v1/sub-account/subAccountApi/ipRestriction/ipList**
```python
client.margin_v1_post_sub_account_sub_account_api_ip_restriction_ip_list(**params)
```
* **POST /sapi/v1/staking/setAutoStaking**
```python
client.margin_v1_post_staking_set_auto_staking(**params)
```
* **POST /fapi/v1/feeBurn**
```python
client.futures_v1_post_fee_burn(**params)
```
* **POST /sapi/v1/simple-earn/flexible/redeem**
```python
client.margin_v1_post_simple_earn_flexible_redeem(**params)
```
* **GET /sapi/v1/broker/subAccount/marginSummary**
```python
client.margin_v1_get_broker_sub_account_margin_summary(**params)
```
* **GET /sapi/v1/lending/auto-invest/plan/list**
```python
client.margin_v1_get_lending_auto_invest_plan_list(**params)
```
* **GET /sapi/v1/loan/vip/loanable/data**
```python
client.margin_v1_get_loan_vip_loanable_data(**params)
```
* **POST /sapi/v1/margin/exchange-small-liability**
```python
client.margin_v1_post_margin_exchange_small_liability(**params)
```
* **GET /sapi/v2/loan/flexible/collateral/data**
```python
client.margin_v2_get_loan_flexible_collateral_data(**params)
```
* **POST /papi/v1/margin/repay-debt**
```python
client.papi_v1_post_margin_repay_debt(**params)
```
* **GET /sapi/v1/sol-staking/sol/history/bnsolRewardsHistory**
```python
client.margin_v1_get_sol_staking_sol_history_bnsol_rewards_history(**params)
```
* **GET /sapi/v1/convert/limit/queryOpenOrders**
```python
client.margin_v1_get_convert_limit_query_open_orders(**params)
```
* **GET /api/v3/account/commission**
```python
client.v3_get_account_commission(**params)
```
* **GET /sapi/v1/margin/interestRateHistory**
```python
client.margin_v1_get_margin_interest_rate_history(**params)
```
* **POST /api/v3/orderList/oco**
```python
client.v3_post_order_list_oco(**params)
```
* **GET /sapi/v1/managed-subaccount/query-trans-log**
```python
client.margin_v1_get_managed_subaccount_query_trans_log(**params)
```
* **POST /sapi/v2/broker/subAccountApi/ipRestriction**
```python
client.margin_v2_post_broker_sub_account_api_ip_restriction(**params)
```
* **GET /papi/v1/um/positionRisk**
```python
client.papi_v1_get_um_position_risk(**params)
```
* **POST /sapi/v1/sub-account/margin/transfer**
```python
client.margin_v1_post_sub_account_margin_transfer(**params)
```
* **GET /fapi/v1/positionRisk**
```python
client.futures_v1_get_position_risk(**params)
```
* **GET /sapi/v1/lending/auto-invest/all/asset**
```python
client.margin_v1_get_lending_auto_invest_all_asset(**params)
```
* **POST /fapi/v1/convert/acceptQuote**
```python
client.futures_v1_post_convert_accept_quote(**params)
```
* **GET /sapi/v1/spot/delist-schedule**
```python
client.margin_v1_get_spot_delist_schedule(**params)
```
* **GET /sapi/v1/dci/product/accounts**
```python
client.margin_v1_get_dci_product_accounts(**params)
```
* **GET /sapi/v1/sub-account/subAccountApi/ipRestriction**
```python
client.margin_v1_get_sub_account_sub_account_api_ip_restriction(**params)
```
* **GET /papi/v1/um/accountConfig**
```python
client.papi_v1_get_um_account_config(**params)
```
* **GET /papi/v1/cm/adlQuantile**
```python
client.papi_v1_get_cm_adl_quantile(**params)
```
* **GET /sapi/v1/sub-account/transaction-statistics**
```python
client.margin_v1_get_sub_account_transaction_statistics(**params)
```
* **PUT /fapi/v1/listenKey**
```python
client.futures_v1_put_listen_key(**params)
```
* **GET /sapi/v1/margin/openOrderList**
```python
client.margin_v1_get_margin_open_order_list(**params)
```
* **GET /api/v3/acccount**
```python
client.v3_get_acccount(**params)
```
* **GET /sapi/v1/fiat/orders**
```python
client.margin_v1_get_fiat_orders(**params)
```
* **GET /papi/v1/margin/allOrders**
```python
client.papi_v1_get_margin_all_orders(**params)
```
* **POST /sapi/v1/sub-account/margin/enable**
```python
client.margin_v1_post_sub_account_margin_enable(**params)
```
* **GET /sapi/v1/managed-subaccount/deposit/address**
```python
client.margin_v1_get_managed_subaccount_deposit_address(**params)
```
* **DELETE /sapi/v1/margin/isolated/account**
```python
client.margin_v1_delete_margin_isolated_account(**params)
```
* **GET /sapi/v2/portfolio/account**
```python
client.margin_v2_get_portfolio_account(**params)
```
* **GET /sapi/v1/simple-earn/locked/history/redemptionRecord**
```python
client.margin_v1_get_simple_earn_locked_history_redemption_record(**params)
```
* **GET /fapi/v1/order/asyn/id**
```python
client.futures_v1_get_order_asyn_id(**params)
```
* **POST /sapi/v1/managed-subaccount/withdraw**
```python
client.margin_v1_post_managed_subaccount_withdraw(**params)
```
* **GET /sapi/v1/convert/tradeFlow**
```python
client.margin_v1_get_convert_trade_flow(**params)
```
* **GET /sapi/v1/localentity/deposit/history**
```python
client.margin_v1_get_localentity_deposit_history(**params)
```
* **POST /sapi/v1/eth-staking/wbeth/wrap**
```python
client.margin_v1_post_eth_staking_wbeth_wrap(**params)
```
* **POST /sapi/v1/simple-earn/locked/setRedeemOption**
```python
client.margin_v1_post_simple_earn_locked_set_redeem_option(**params)
```
* **POST /sapi/v1/broker/subAccountApi/ipRestriction/ipList**
```python
client.margin_v1_post_broker_sub_account_api_ip_restriction_ip_list(**params)
```
* **POST /sapi/v1/broker/subAccountApi/commission/futures**
```python
client.margin_v1_post_broker_sub_account_api_commission_futures(**params)
```
* **GET /papi/v1/margin/myTrades**
```python
client.papi_v1_get_margin_my_trades(**params)
```
* **GET /sapi/v1/pay/transactions**
```python
client.margin_v1_get_pay_transactions(**params)
```
* **GET /papi/v1/um/leverageBracket**
```python
client.papi_v1_get_um_leverage_bracket(**params)
```
* **GET /papi/v1/margin/orderList**
```python
client.papi_v1_get_margin_order_list(**params)
```
* **GET /dapi/v1/allForceOrders**
```python
client.futures_coin_v1_get_all_force_orders(**params)
```
* **GET /sapi/v1/margin/isolated/accountLimit**
```python
client.margin_v1_get_margin_isolated_account_limit(**params)
```
* **GET /sapi/v1/lending/auto-invest/history/list**
```python
client.margin_v1_get_lending_auto_invest_history_list(**params)
```
* **GET /dapi/v1/account**
```python
client.futures_coin_v1_get_account(**params)
```
* **GET /dapi/v1/markPriceKlines**
```python
client.futures_coin_v1_get_mark_price_klines(**params)
```
* **POST /sapi/v1/loan/customize/margin\_call**
```python
client.margin_v1_post_loan_customize_margin_call(**params)
```
* **GET /sapi/v1/broker/subAccount/bnbBurn/status**
```python
client.margin_v1_get_broker_sub_account_bnb_burn_status(**params)
```
* **DELETE /eapi/v1/block/order/create**
```python
client.options_v1_delete_block_order_create(**params)
```
* **GET /sapi/v1/managed-subaccount/accountSnapshot**
```python
client.margin_v1_get_managed_subaccount_account_snapshot(**params)
```
* **GET /fapi/v1/constituents**
```python
client.futures_v1_get_constituents(**params)
```
* **GET /dapi/v1/indexPriceKlines**
```python
client.futures_coin_v1_get_index_price_klines(**params)
```
* **GET /sapi/v1/broker/subAccountApi/commission/coinFutures**
```python
client.margin_v1_get_broker_sub_account_api_commission_coin_futures(**params)
```
* **GET /sapi/v2/broker/subAccount/futuresSummary**
```python
client.margin_v2_get_broker_sub_account_futures_summary(**params)
```
* **GET /sapi/v1/sub-account/transfer/subUserHistory**
```python
client.margin_v1_get_sub_account_transfer_sub_user_history(**params)
```
* **POST /sapi/v1/sub-account/futures/internalTransfer**
```python
client.margin_v1_post_sub_account_futures_internal_transfer(**params)
```
* **GET /sapi/v1/loan/ongoing/orders**
```python
client.margin_v1_get_loan_ongoing_orders(**params)
```
* **GET /sapi/v2/loan/flexible/ongoing/orders**
```python
client.margin_v2_get_loan_flexible_ongoing_orders(**params)
```
* **GET /eapi/v1/block/order/execute**
```python
client.options_v1_get_block_order_execute(**params)
```
* **GET /papi/v2/um/account**
```python
client.papi_v2_get_um_account(**params)
```
* **POST /sapi/v1/margin/order/oco**
```python
client.margin_v1_post_margin_order_oco(**params)
```
* **GET /api/v1/portfolio/negative-balance-exchange-record**
```python
client.v1_get_portfolio_negative_balance_exchange_record(**params)
```
* **POST /sapi/v1/algo/futures/newOrderVp**
```python
client.margin_v1_post_algo_futures_new_order_vp(**params)
```
* **DELETE /papi/v1/um/order**
```python
client.papi_v1_delete_um_order(**params)
```
* **POST /fapi/v1/convert/getQuote**
```python
client.futures_v1_post_convert_get_quote(**params)
```
* **GET /sapi/v1/algo/spot/subOrders**
```python
client.margin_v1_get_algo_spot_sub_orders(**params)
```
* **GET /dapi/v1/userTrades**
```python
client.futures_coin_v1_get_user_trades(**params)
```
* **POST /papi/v1/um/feeBurn**
```python
client.papi_v1_post_um_fee_burn(**params)
```
* **POST /sapi/v1/portfolio/redeem**
```python
client.margin_v1_post_portfolio_redeem(**params)
```
* **POST /fapi/v1/multiAssetsMargin**
```python
client.futures_v1_post_multi_assets_margin(**params)
```
* **POST /sapi/v1/lending/auto-invest/plan/add**
```python
client.margin_v1_post_lending_auto_invest_plan_add(**params)
```
* **GET /eapi/v1/historyOrders**
```python
client.options_v1_get_history_orders(**params)
```
* **GET /sapi/v1/lending/auto-invest/source-asset/list**
```python
client.margin_v1_get_lending_auto_invest_source_asset_list(**params)
```
* **GET /sapi/v1/margin/allOrderList**
```python
client.margin_v1_get_margin_all_order_list(**params)
```
* **POST /sapi/v1/eth-staking/eth/redeem**
```python
client.margin_v1_post_eth_staking_eth_redeem(**params)
```
* **GET /sapi/v1/broker/rebate/historicalRecord**
```python
client.margin_v1_get_broker_rebate_historical_record(**params)
```
* **GET /sapi/v1/simple-earn/locked/history/subscriptionRecord**
```python
client.margin_v1_get_simple_earn_locked_history_subscription_record(**params)
```
* **PUT /dapi/v1/order**
```python
client.futures_coin_v1_put_order(**params)
```
* **GET /sapi/v1/managed-subaccount/asset**
```python
client.margin_v1_get_managed_subaccount_asset(**params)
```
* **GET /sapi/v1/sol-staking/sol/quota**
```python
client.margin_v1_get_sol_staking_sol_quota(**params)
```
* **POST /sapi/v1/loan/vip/renew**
```python
client.margin_v1_post_loan_vip_renew(**params)
```
* **POST /dapi/v1/order**
```python
client.futures_coin_v1_post_order(**params)
```
* **GET /sapi/v1/managed-subaccount/queryTransLogForTradeParent**
```python
client.margin_v1_get_managed_subaccount_query_trans_log_for_trade_parent(**params)
```
* **GET /sapi/v1/simple-earn/flexible/history/redemptionRecord**
```python
client.margin_v1_get_simple_earn_flexible_history_redemption_record(**params)
```
* **GET /sapi/v1/sub-account/margin/accountSummary**
```python
client.margin_v1_get_sub_account_margin_account_summary(**params)
```
* **GET /sapi/v1/margin/dribblet**
```python
client.margin_v1_get_margin_dribblet(**params)
```
* **GET /eapi/v1/exerciseHistory**
```python
client.options_v1_get_exercise_history(**params)
```
* **GET /sapi/v1/convert/exchangeInfo**
```python
client.margin_v1_get_convert_exchange_info(**params)
```
* **GET /sapi/v1/eth-staking/eth/history/wbethRewardsHistory**
```python
client.margin_v1_get_eth_staking_eth_history_wbeth_rewards_history(**params)
```
* **GET /sapi/v1/simple-earn/locked/position**
```python
client.margin_v1_get_simple_earn_locked_position(**params)
```
* **GET /sapi/v1/mining/pub/algoList**
```python
client.margin_v1_get_mining_pub_algo_list(**params)
```
* **GET /dapi/v1/ticker/bookTicker**
```python
client.futures_coin_v1_get_ticker_book_ticker(**params)
```
* **GET /eapi/v1/blockTrades**
```python
client.options_v1_get_block_trades(**params)
```
* **GET /sapi/v1/copyTrading/futures/leadSymbol**
```python
client.margin_v1_get_copy_trading_futures_lead_symbol(**params)
```
* **GET /papi/v1/cm/orderAmendment**
```python
client.papi_v1_get_cm_order_amendment(**params)
```
* **GET /sapi/v4/sub-account/assets**
```python
client.margin_v4_get_sub_account_assets(**params)
```
* **GET /sapi/v1/mining/worker/list**
```python
client.margin_v1_get_mining_worker_list(**params)
```
* **DELETE /sapi/v1/margin/openOrders**
```python
client.margin_v1_delete_margin_open_orders(**params)
```
* **GET /dapi/v1/constituents**
```python
client.futures_coin_v1_get_constituents(**params)
```
* **GET /sapi/v1/dci/product/list**
```python
client.margin_v1_get_dci_product_list(**params)
```
* **GET /fapi/v1/convert/orderStatus**
```python
client.futures_v1_get_convert_order_status(**params)
```
# FAQ (/docs/faq)
Why do I get "Timestamp for this request is not valid"? [#why-do-i-get-timestamp-for-this-request-is-not-valid]
This occurs in 2 different cases:
1. The timestamp sent is outside of the `serverTime - recvWindow` value
2. The timestamp sent is more than 1000ms ahead of the server time
Check that your system time is in sync. See [this issue](https://github.com/sammchardy/python-binance/issues/2#issuecomment-324878152) for sample code to check the difference.
Why do I get "Signature for this request is not valid"? [#why-do-i-get-signature-for-this-request-is-not-valid]
**A1:** One of your parameters may not be in the correct format. Check `recvWindow` is an integer and not a string.
**A2:** You may need to regenerate your API Key and Secret.
**A3:** You may be attempting to access the API from a Chinese IP address, which are restricted by Binance.
How can I debug API issues? [#how-can-i-debug-api-issues]
Enable verbose mode to see detailed request and response information:
```python
client = Client(api_key, api_secret, verbose=True)
```
This logs all HTTP requests and responses, including headers, body, and status codes. See the [Configuration guide](/docs/getting-started/configuration#verbose-mode) for more details.
# python-binance (/docs)
Welcome to the **python-binance** documentation.
This is the unofficial Python wrapper for the [Binance exchange REST API v3](https://github.com/binance-exchange/binance-official-api-docs). It supports:
* Spot, Margin, and Futures trading
* Synchronous and Asynchronous clients
* WebSocket streaming with automatic reconnection
* Depth cache management
* Testnet support
Quick Start [#quick-start]
```bash
pip install python-binance
```
```python
from binance.client import Client
client = Client(api_key, api_secret)
# Get market data
tickers = client.get_all_tickers()
# Place an order
order = client.order_market_buy(symbol='BNBBTC', quantity=100)
```
Links [#links]
* [GitHub Repository](https://github.com/sammchardy/python-binance)
* [PyPI Package](https://pypi.org/project/python-binance/)
* [Binance API Documentation](https://binance-docs.github.io/apidocs/spot/en/)
# LLM Integration (/docs/llm)
This documentation is available in machine-readable formats for use with AI assistants like Claude, ChatGPT, Cursor, Copilot, and others.
Agent Skill [#agent-skill]
Install the agent skill into any project or globally with [npx skills](https://www.npmjs.com/package/skills)
(works with Claude Code, Cursor, Copilot, Gemini CLI, Goose, Roo Code, and 30+ other agents):
```bash
# Install into the current project
npx -y skills add sammchardy/python-binance
# Install globally (available in all projects)
npx -y skills add sammchardy/python-binance --global
```
Once installed, your AI agent will have access to python-binance documentation and API reference as context when working on your project.
Copy Docs for AI [#copy-docs-for-ai]
Open With [#open-with]
Per-Page Markdown [#per-page-markdown]
Append `.mdx` to any docs URL to get the Markdown source for that page. For example:
* [`/docs/getting-started/installation.mdx`](/docs/getting-started/installation.mdx)
* [`/docs/guides/websockets.mdx`](/docs/guides/websockets.mdx)
* [`/docs/guides/account.mdx`](/docs/guides/account.mdx)
Direct Links [#direct-links]
| Format | URL | Description |
| ----------------- | ---------------------------------- | -------------------------------------------------- |
| **llms.txt** | [`/llms.txt`](/llms.txt) | Page index with titles, URLs, and descriptions |
| **llms-full.txt** | [`/llms-full.txt`](/llms-full.txt) | Full processed Markdown of all documentation pages |
# binance (/docs/api)
An unofficial Python wrapper for the Binance exchange API v3
.. moduleauthor:: Sam McHardy
# Configuration (/docs/getting-started/configuration)
Initialise the Client [#initialise-the-client]
Pass your API Key and Secret:
```python
from binance.client import Client
client = Client(api_key, api_secret)
```
Or for the asynchronous client:
```python
import asyncio
from binance import AsyncClient
async def main():
client = await AsyncClient.create(api_key, api_secret)
await client.close_connection()
if __name__ == "__main__":
asyncio.run(main())
```
Making API Calls [#making-api-calls]
Every method supports passing arbitrary parameters via keyword arguments matching those in the [Binance API documentation](https://github.com/binance-exchange/binance-official-api-docs). These keyword arguments are sent directly to the relevant endpoint.
Each API method returns a dictionary of the JSON response. The docstring of each method references the endpoint it implements.
The `timestamp` parameter is generated for you where required.
Some methods have a `recvWindow` parameter for [timing security](https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#timing-security).
API Endpoints are rate limited by Binance at 20 requests per second.
Async API Calls [#async-api-calls]
`aiohttp` is used to handle async REST requests. Each function available in the normal client is also available in the `AsyncClient` class.
```python
import asyncio
from binance import AsyncClient
async def main():
client = await AsyncClient.create()
res = await client.get_exchange_info()
print(json.dumps(res, indent=2))
await client.close_connection()
if __name__ == "__main__":
asyncio.run(main())
```
Read [Async basics for Binance](https://sammchardy.github.io/binance/2021/05/01/async-binance-basics.html) for more information.
API Rate Limit [#api-rate-limit]
Check the `get_exchange_info()` call for up-to-date rate limits. Current limits:
* 1200 weights per minute
* 10 orders per second
* 100,000 orders per 24hrs
Some calls have a higher weight than others, especially those returning information about all symbols. Read the [official Binance documentation](https://github.com/binance-exchange/binance-official-api-docs) for details.
On each request Binance returns `X-MBX-USED-WEIGHT-(intervalNum)(intervalLetter)` and `X-MBX-ORDER-COUNT-(intervalNum)` headers.
Asynchronous example [#asynchronous-example]
```python
import asyncio
from binance import AsyncClient
async def main():
client = await AsyncClient.create(api_key, api_secret)
res = await client.get_exchange_info()
print(client.response.headers)
await client.close_connection()
if __name__ == "__main__":
asyncio.run(main())
```
Synchronous example [#synchronous-example]
```python
from binance import Client
def main():
client = Client(api_key, api_secret)
res = client.get_exchange_info()
print(client.response.headers)
if __name__ == "__main__":
main()
```
Requests Settings [#requests-settings]
`python-binance` uses the [requests](http://docs.python-requests.org/en/master/) library. You can set custom requests parameters for all API calls when creating the client:
```python
client = Client("api-key", "api-secret", {"verify": False, "timeout": 20})
```
You can also pass custom parameters through any API call to override defaults:
```python
# verify: False and timeout: 5 for this call
client = Client("api-key", "api-secret", {"verify": False, "timeout": 20})
client.get_all_orders(symbol='BNBBTC', requests_params={'timeout': 5})
```
Proxy Settings [#proxy-settings]
```python
proxies = {
'http': 'http://10.10.1.10:3128',
'https': 'http://10.10.1.10:1080'
}
# In the Client instantiation
client = Client("api-key", "api-secret", {'proxies': proxies})
# Or on an individual call
client.get_all_orders(symbol='BNBBTC', requests_params={'proxies': proxies})
```
Or set environment variables:
```bash
# Linux
export HTTP_PROXY="http://10.10.1.10:3128"
export HTTPS_PROXY="http://10.10.1.10:1080"
# Windows
set HTTP_PROXY=http://10.10.1.10:3128
set HTTPS_PROXY=http://10.10.1.10:1080
```
Logging [#logging]
python-binance uses the Python logging module.
Basic Logging Setup [#basic-logging-setup]
```python
import logging
logging.basicConfig(level=logging.DEBUG)
```
Advanced Logging Setup [#advanced-logging-setup]
```python
import logging
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
)
```
Verbose Mode [#verbose-mode]
Verbose mode logs all HTTP requests and responses — useful for debugging API issues.
**Method 1: Using the verbose Parameter**
```python
from binance.client import Client
import logging
logging.basicConfig(level=logging.DEBUG)
client = Client(api_key, api_secret, verbose=True)
server_time = client.get_server_time()
```
For AsyncClient:
```python
import asyncio
import logging
from binance.async_client import AsyncClient
logging.basicConfig(level=logging.DEBUG)
async def main():
client = await AsyncClient.create(api_key, api_secret, verbose=True)
server_time = await client.get_server_time()
await client.close_connection()
if __name__ == "__main__":
asyncio.run(main())
```
**Method 2: Using Python's Logging Module (Production)**
```python
import logging
from binance.client import Client
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logging.getLogger('binance.base_client').setLevel(logging.DEBUG)
client = Client(api_key, api_secret)
```
When verbose mode is enabled, you'll see logs for each request including HTTP method and URL, request headers and body, response status code, and response headers and body (truncated to 1000 characters).
> **Note:** Verbose mode should be disabled in production environments.
WebSocket Verbose Logging [#websocket-verbose-logging]
```python
import logging
from binance import AsyncClient, BinanceSocketManager
logging.basicConfig(level=logging.DEBUG)
# Enable verbose for both REST API and WebSocket
client = await AsyncClient.create(verbose=True)
bm = BinanceSocketManager(client, verbose=True)
```
You can also enable logging for specific WebSocket components:
```python
logging.getLogger('binance.ws.websocket_api').setLevel(logging.DEBUG)
logging.getLogger('binance.ws.reconnecting_websocket').setLevel(logging.DEBUG)
logging.getLogger('binance.ws.streams').setLevel(logging.DEBUG)
```
For ThreadedWebsocketManager:
```python
import logging
from binance.ws.threaded_stream import ThreadedApiManager
logging.basicConfig(level=logging.DEBUG)
twm = ThreadedApiManager(api_key='your_key', api_secret='your_secret', verbose=True)
twm.start()
```
# Installation (/docs/getting-started/installation)
Install [#install]
`python-binance` is available on [PyPI](https://pypi.python.org/pypi/python-binance/).
```bash
pip install python-binance
```
Register on Binance [#register-on-binance]
[Register an account with Binance](https://accounts.binance.com/en/register?ref=10099792).
Generate an API Key [#generate-an-api-key]
To use signed account methods you need to [create an API Key](https://www.binance.com/en/support/faq/360002502072).
# Testnet (/docs/getting-started/testnet)
Binance offers a [Spot](https://testnet.binance.vision/), [Futures](https://testnet.binancefuture.com/) and [Vanilla Options](https://testnet.binanceops.com/) Testnet to test interacting with the exchange.
To enable this, set the `testnet` parameter to `True`:
```python
client = Client(api_key, api_secret, testnet=True)
```
Or for the async client:
```python
client = await AsyncClient.create(api_key, api_secret, testnet=True)
```
The testnet parameter will also be used by any websocket streams when the client is passed to the `BinanceSocketManager`.
Using a Different TLD [#using-a-different-tld]
If you are interacting with a regional version of Binance (e.g. `.us` or `.jp`), pass the `tld` parameter:
```python
client = Client(api_key, api_secret, tld='us')
```
Or for the async client:
```python
client = await AsyncClient.create(api_key, api_secret, tld='us')
```
This TLD will also be used by any websocket streams when the client is passed to the `BinanceSocketManager`.
# Account Endpoints (/docs/guides/account)
Orders [#orders]
Order Validation [#order-validation]
Binance has rules around symbol pair orders with validation on minimum price, quantity, and total order value. Read more in the [Filters](https://binance-docs.github.io/apidocs/spot/en/#filters) section of the official API.
Read [Understanding Binance Order Filters](https://sammchardy.github.io/binance/2021/05/03/binance-order-filters.html) for more information.
It can be helpful to format the output:
```python
amount = 0.000234234
precision = 5
amt_str = "{:0.0{}f}".format(amount, precision)
```
Or use the helper to round to step size:
```python
from binance.helpers import round_step_size
amount = 0.000234234
tick_size = 0.00001
rounded_amount = round_step_size(amount, tick_size)
```
Fetch All Orders [#fetch-all-orders]
```python
orders = client.get_all_orders(symbol='BNBBTC', limit=10)
```
Place an Order [#place-an-order]
Use `create_order` for full control:
```python
from binance.enums import *
order = client.create_order(
symbol='BNBBTC',
side=SIDE_BUY,
type=ORDER_TYPE_LIMIT,
timeInForce=TIME_IN_FORCE_GTC,
quantity=100,
price='0.00001')
```
**Limit orders:**
```python
order = client.order_limit_buy(
symbol='BNBBTC',
quantity=100,
price='0.00001')
order = client.order_limit_sell(
symbol='BNBBTC',
quantity=100,
price='0.00001')
```
**Market orders:**
```python
order = client.order_market_buy(
symbol='BNBBTC',
quantity=100)
order = client.order_market_sell(
symbol='BNBBTC',
quantity=100)
```
**OCO orders:**
```python
from binance.enums import *
order = client.create_oco_order(
symbol='BNBBTC',
side=SIDE_SELL,
stopLimitTimeInForce=TIME_IN_FORCE_GTC,
quantity=100,
stopPrice='0.00001',
price='0.00002')
```
Place a Test Order [#place-a-test-order]
Creates and validates a new order but does not send it into the exchange:
```python
from binance.enums import *
order = client.create_test_order(
symbol='BNBBTC',
side=SIDE_BUY,
type=ORDER_TYPE_LIMIT,
timeInForce=TIME_IN_FORCE_GTC,
quantity=100,
price='0.00001')
```
Check Order Status [#check-order-status]
```python
order = client.get_order(
symbol='BNBBTC',
orderId='orderId')
```
Cancel an Order [#cancel-an-order]
```python
result = client.cancel_order(
symbol='BNBBTC',
orderId='orderId')
```
Get All Open Orders [#get-all-open-orders]
```python
orders = client.get_open_orders(symbol='BNBBTC')
```
Get All Orders [#get-all-orders]
```python
orders = client.get_all_orders(symbol='BNBBTC')
```
Account [#account]
Get Account Info [#get-account-info]
```python
info = client.get_account()
```
Get Asset Balance [#get-asset-balance]
```python
balance = client.get_asset_balance(asset='BTC')
```
Get Account Status [#get-account-status]
```python
status = client.get_account_status()
```
Get Account API Trading Status [#get-account-api-trading-status]
```python
status = client.get_account_api_trading_status()
```
Get Trades [#get-trades]
```python
trades = client.get_my_trades(symbol='BNBBTC')
```
Get Trade Fees [#get-trade-fees]
```python
# Get fees for all symbols
fees = client.get_trade_fee()
# Get fee for one symbol
fees = client.get_trade_fee(symbol='BNBBTC')
```
Get Asset Details [#get-asset-details]
```python
details = client.get_asset_details()
```
Get Dust Log [#get-dust-log]
```python
log = client.get_dust_log()
```
Transfer Dust [#transfer-dust]
```python
transfer = client.transfer_dust(asset='BNZ')
```
Get Asset Dividend History [#get-asset-dividend-history]
```python
history = client.get_asset_dividend_history()
```
Disable Fast Withdraw Switch [#disable-fast-withdraw-switch]
```python
client.disable_fast_withdraw_switch()
```
Enable Fast Withdraw Switch [#enable-fast-withdraw-switch]
```python
client.enable_fast_withdraw_switch()
```
# Constants (/docs/guides/constants)
Binance requires specific string constants for Order Types, Order Side, Time in Force, Order response and Kline intervals. These are found on `binance.client.Client`.
```python
SYMBOL_TYPE_SPOT = 'SPOT'
ORDER_STATUS_NEW = 'NEW'
ORDER_STATUS_PARTIALLY_FILLED = 'PARTIALLY_FILLED'
ORDER_STATUS_FILLED = 'FILLED'
ORDER_STATUS_CANCELED = 'CANCELED'
ORDER_STATUS_PENDING_CANCEL = 'PENDING_CANCEL'
ORDER_STATUS_REJECTED = 'REJECTED'
ORDER_STATUS_EXPIRED = 'EXPIRED'
KLINE_INTERVAL_1SECOND = '1s'
KLINE_INTERVAL_1MINUTE = '1m'
KLINE_INTERVAL_3MINUTE = '3m'
KLINE_INTERVAL_5MINUTE = '5m'
KLINE_INTERVAL_15MINUTE = '15m'
KLINE_INTERVAL_30MINUTE = '30m'
KLINE_INTERVAL_1HOUR = '1h'
KLINE_INTERVAL_2HOUR = '2h'
KLINE_INTERVAL_4HOUR = '4h'
KLINE_INTERVAL_6HOUR = '6h'
KLINE_INTERVAL_8HOUR = '8h'
KLINE_INTERVAL_12HOUR = '12h'
KLINE_INTERVAL_1DAY = '1d'
KLINE_INTERVAL_3DAY = '3d'
KLINE_INTERVAL_1WEEK = '1w'
KLINE_INTERVAL_1MONTH = '1M'
SIDE_BUY = 'BUY'
SIDE_SELL = 'SELL'
ORDER_TYPE_LIMIT = 'LIMIT'
ORDER_TYPE_MARKET = 'MARKET'
ORDER_TYPE_STOP_LOSS = 'STOP_LOSS'
ORDER_TYPE_STOP_LOSS_LIMIT = 'STOP_LOSS_LIMIT'
ORDER_TYPE_TAKE_PROFIT = 'TAKE_PROFIT'
ORDER_TYPE_TAKE_PROFIT_LIMIT = 'TAKE_PROFIT_LIMIT'
ORDER_TYPE_LIMIT_MAKER = 'LIMIT_MAKER'
TIME_IN_FORCE_GTC = 'GTC'
TIME_IN_FORCE_IOC = 'IOC'
TIME_IN_FORCE_FOK = 'FOK'
ORDER_RESP_TYPE_ACK = 'ACK'
ORDER_RESP_TYPE_RESULT = 'RESULT'
ORDER_RESP_TYPE_FULL = 'FULL'
# For accessing aggregate trade data
AGG_ID = 'a'
AGG_PRICE = 'p'
AGG_QUANTITY = 'q'
AGG_FIRST_TRADE_ID = 'f'
AGG_LAST_TRADE_ID = 'l'
AGG_TIME = 'T'
AGG_BUYER_MAKES = 'm'
AGG_BEST_MATCH = 'M'
```
For WebSocket Depth, found on `binance.websockets.BinanceSocketManager`:
```python
WEBSOCKET_DEPTH_5 = '5'
WEBSOCKET_DEPTH_10 = '10'
WEBSOCKET_DEPTH_20 = '20'
```
Usage:
```python
from binance.client import Client
from binance.websockets import BinanceSocketManager
side = Client.SIDE_BUY
```
# Depth Cache (/docs/guides/depth-cache)
To follow depth cache updates for a symbol there are 2 options:
* **DepthCacheManager** (or **OptionsDepthCacheManager** for vanilla options) — requires asyncio
* **ThreadedDepthCacheManager** — no asyncio required
ThreadedDepthCacheManager Usage [#threadeddepthcachemanager-usage]
```python
from binance import ThreadedDepthCacheManager
def main():
dcm = ThreadedDepthCacheManager()
dcm.start()
def handle_depth_cache(depth_cache):
print(f"symbol {depth_cache.symbol}")
print("top 5 bids")
print(depth_cache.get_bids()[:5])
print("top 5 asks")
print(depth_cache.get_asks()[:5])
print("last update time {}".format(depth_cache.update_time))
dcm_name = dcm.start_depth_cache(handle_depth_cache, symbol='BNBBTC')
# Multiple depth caches can be started
dcm_name = dcm.start_depth_cache(handle_depth_cache, symbol='ETHBTC')
dcm.join()
if __name__ == "__main__":
main()
```
Stop Individual Depth Cache [#stop-individual-depth-cache]
```python
dcm_name = dcm.start_depth_cache(handle_depth_cache, symbol='BNBBTC')
# Later...
dcm.stop_socket(dcm_name)
```
Stop All Depth Cache Streams [#stop-all-depth-cache-streams]
```python
dcm.stop()
```
Attempting to start a stream after `stop` is called will not work.
DepthCacheManager Usage [#depthcachemanager-usage]
```python
import asyncio
from binance import AsyncClient, DepthCacheManager
async def main():
client = await AsyncClient.create()
dcm = DepthCacheManager(client, 'BNBBTC')
async with dcm as dcm_socket:
while True:
depth_cache = await dcm_socket.recv()
print("symbol {}".format(depth_cache.symbol))
print("top 5 bids")
print(depth_cache.get_bids()[:5])
print("top 5 asks")
print(depth_cache.get_asks()[:5])
print("last update time {}".format(depth_cache.update_time))
if __name__ == "__main__":
asyncio.run(main())
```
By default the depth cache fetches the order book via REST every 30 minutes. Change this with `refresh_interval`:
```python
# 1 hour interval refresh
dcm = DepthCacheManager(client, 'BNBBTC', refresh_interval=60*60)
# Disable refreshing
dcm = DepthCacheManager(client, 'BNBBTC', refresh_interval=0)
```
Share a Socket Manager [#share-a-socket-manager]
Multiple DepthCacheManagers can share the same BinanceSocketManager:
```python
from binance.websockets import BinanceSocketManager
from binance.depthcache import DepthCacheManager
bm = BinanceSocketManager(client)
dcm1 = DepthCacheManager(client, 'BNBBTC', bm=bm)
dcm2 = DepthCacheManager(client, 'ETHBTC', bm=bm)
```
WebSocket Errors [#websocket-errors]
If the underlying websocket disconnects and cannot reconnect, `None` is returned for the `depth_cache` parameter. An error message is passed to the callback and to `recv()`.
If `BinanceWebsocketClosed` is returned, the websocket will attempt to reconnect 5 times before returning `BinanceUnableToConnect`.
**Async error handling:**
```python
depth_cache = await dcm.recv()
if isinstance(depth_cache, dict) and depth_cache.get('e') == 'error':
logger.error(f"Received depth cache error: {depth_cache}")
if depth_cache.get('type') == 'BinanceWebsocketClosed':
continue # will auto-reconnect
break
```
**Callback error handling:**
```python
def handle_depth_cache(depth_cache):
if isinstance(depth_cache, dict) and depth_cache.get('e') == 'error':
logger.error(f"Received depth cache error: {depth_cache}")
if depth_cache.get('type') == 'BinanceWebsocketClosed':
return # will auto-reconnect
dcm.stop()
return
# handle non-error cases here
```
Manual Context Manager Usage [#manual-context-manager-usage]
```python
dcm = DepthCacheManager(client, 'BNBBTC')
await dcm.__aenter__()
depth_cache = await dcm.recv()
print("symbol {}".format(depth_cache.symbol))
print("top 5 bids")
print(depth_cache.get_bids()[:5])
print("top 5 asks")
print(depth_cache.get_asks()[:5])
print("last update time {}".format(depth_cache.update_time))
await dcm.__aexit__(None, None, None)
```
# Exceptions (/docs/guides/exceptions)
BinanceRequestException [#binancerequestexception]
Raised if a non-JSON response is returned.
BinanceAPIException [#binanceapiexception]
On an API call error a `binance.exceptions.BinanceAPIException` will be raised. The exception provides access to:
* `status_code` — response status code
* `response` — response object
* `code` — Binance error code
* `message` — Binance error message
* `request` — request object if available
```python
try:
client.get_all_orders()
except BinanceAPIException as e:
print(e.status_code)
print(e.message)
```
# General Endpoints (/docs/guides/general)
Ping the Server [#ping-the-server]
```python
client.ping()
```
Get the Server Time [#get-the-server-time]
```python
time_res = client.get_server_time()
```
Get System Status [#get-system-status]
```python
status = client.get_system_status()
```
Returns:
```python
{
"status": 0, # 0: normal, 1: system maintenance
"msg": "normal" # normal or System maintenance.
}
```
Get Exchange Info [#get-exchange-info]
```python
info = client.get_exchange_info()
```
Get Symbol Info [#get-symbol-info]
Get the exchange info for a particular symbol:
```python
info = client.get_symbol_info('BNBBTC')
```
Get All Coins Info [#get-all-coins-info]
Get information of coins (available for deposit and withdraw) for user:
```python
info = client.get_all_tickers()
```
Get Daily Account Snapshot [#get-daily-account-snapshot]
Get daily account snapshot of specific type. Valid types: `SPOT`, `MARGIN`, `FUTURES`.
```python
info = client.get_account_snapshot(type='SPOT')
```
Get Current Products [#get-current-products]
> **Deprecated:** Use Exchange Info instead.
```python
products = client.get_products()
```
# Helper Functions (/docs/guides/helpers)
The `binance.helpers` module provides utility functions:
* `date_to_milliseconds` — Convert a date string to milliseconds
* `interval_to_milliseconds` — Convert a Binance interval string to milliseconds
* `round_step_size` — Round a value to the nearest step size
```python
from binance.helpers import round_step_size
amount = 0.000234234
tick_size = 0.00001
rounded_amount = round_step_size(amount, tick_size)
```
# Margin Trading (/docs/guides/margin)
> **Cross-margin vs isolated margin trading**
>
> Binance offers both *cross-margin* trading (where all margin is in one account) and *isolated margin* trading (where each pair is a separate margin account). Make sure you are interacting with the right one.
>
> Some API endpoints apply to the cross-margin or isolated margin accounts only. Other endpoints, such as trade execution, are used for cross-margin by default, but you can use isolated margin by using the `isIsolated` or `isolatedSymbol` parameters.
Market Data [#market-data]
Get Cross-Margin Asset Info [#get-cross-margin-asset-info]
```python
info = client.get_margin_asset(asset='BNB')
```
Get Cross-Margin Symbol Info [#get-cross-margin-symbol-info]
```python
info = client.get_margin_symbol(symbol='BTCUSDT')
```
Get Isolated Margin Symbol Info [#get-isolated-margin-symbol-info]
```python
info = client.get_isolated_margin_symbol(symbol='BTCUSDT')
```
Get All Isolated Margin Symbols [#get-all-isolated-margin-symbols]
```python
info = client.get_all_isolated_margin_symbols()
```
Get Margin Price Index [#get-margin-price-index]
```python
info = client.get_margin_price_index(symbol='BTCUSDT')
```
Orders [#orders]
Cross-Margin vs Isolated Margin Orders [#cross-margin-vs-isolated-margin-orders]
By default, trade execution endpoints use the *cross-margin* account. To use *isolated margin*, add `isIsolated='TRUE'` to the API calls.
Order Validation [#order-validation]
Binance has rules around symbol pair orders with validation on minimum price, quantity, and total order value. Read more in the [Filters](https://binance-docs.github.io/apidocs/spot/en/#filters) section of the official API.
```python
amount = 0.000234234
precision = 5
amt_str = "{:0.0{}f}".format(amount, precision)
```
Fetch All Margin Orders [#fetch-all-margin-orders]
```python
orders = client.get_all_margin_orders(symbol='BNBBTC', limit=10)
```
Place a Margin Order [#place-a-margin-order]
```python
from binance.enums import *
order = client.create_margin_order(
symbol='BNBBTC',
side=SIDE_BUY,
type=ORDER_TYPE_LIMIT,
timeInForce=TIME_IN_FORCE_GTC,
quantity=100,
price='0.00001')
```
Check Order Status [#check-order-status]
```python
order = client.get_margin_order(
symbol='BNBBTC',
orderId='orderId')
```
Cancel a Margin Order [#cancel-a-margin-order]
```python
result = client.cancel_margin_order(
symbol='BNBBTC',
orderId='orderId')
```
Get All Open Margin Orders [#get-all-open-margin-orders]
```python
orders = client.get_open_margin_orders(symbol='BNBBTC')
```
For isolated margin, add `isIsolated='TRUE'`.
Get All Margin Orders [#get-all-margin-orders]
```python
orders = client.get_all_margin_orders(symbol='BNBBTC')
```
For isolated margin, add `isIsolated='TRUE'`.
Account [#account]
Get Cross-Margin Account Info [#get-cross-margin-account-info]
```python
info = client.get_margin_account()
```
Create Isolated Margin Account [#create-isolated-margin-account]
```python
account = client.create_isolated_margin_account(base='BTC', quote='ETH')
```
Get Isolated Margin Account Info [#get-isolated-margin-account-info]
```python
info = client.get_isolated_margin_account()
```
Transfer Spot to Cross-Margin [#transfer-spot-to-cross-margin]
```python
transaction = client.transfer_spot_to_margin(asset='BTC', amount='1.1')
```
Transfer Cross-Margin to Spot [#transfer-cross-margin-to-spot]
```python
transaction = client.transfer_margin_to_spot(asset='BTC', amount='1.1')
```
Transfer Spot to Isolated Margin [#transfer-spot-to-isolated-margin]
```python
transaction = client.transfer_spot_to_isolated_margin(
asset='BTC', symbol='ETHBTC', amount='1.1')
```
Transfer Isolated Margin to Spot [#transfer-isolated-margin-to-spot]
```python
transaction = client.transfer_isolated_margin_to_spot(
asset='BTC', symbol='ETHBTC', amount='1.1')
```
Get Max Transfer Amount [#get-max-transfer-amount]
```python
details = client.get_max_margin_transfer(asset='BTC')
```
For isolated margin, add `isolatedSymbol=symbol_name`.
Trades [#trades]
Get All Margin Trades [#get-all-margin-trades]
```python
trades = client.get_margin_trades(symbol='BNBBTC')
```
For isolated margin, add `isIsolated='TRUE'`.
Loans [#loans]
Create Loan [#create-loan]
```python
transaction = client.create_margin_loan(asset='BTC', amount='1.1')
```
For isolated margin, add `isIsolated='TRUE'` and `symbol=symbol_name`.
Repay Loan [#repay-loan]
```python
transaction = client.repay_margin_loan(asset='BTC', amount='1.1')
```
For isolated margin, add `isIsolated='TRUE'` and `symbol=symbol_name`.
Get Loan Details [#get-loan-details]
```python
details = client.get_margin_loan_details(asset='BTC', txId='100001')
```
For isolated margin, add `isolatedSymbol=symbol_name`.
Get Repay Details [#get-repay-details]
```python
details = client.get_margin_repay_details(asset='BTC', txId='100001')
```
For isolated margin, add `isolatedSymbol=symbol_name`.
Get Max Loan Amount [#get-max-loan-amount]
```python
details = client.get_max_margin_loan(asset='BTC')
```
For isolated margin, add `isolatedSymbol=symbol_name`.
# Market Data (/docs/guides/market-data)
Get Market Depth [#get-market-depth]
```python
depth = client.get_order_book(symbol='BNBBTC')
```
Get Recent Trades [#get-recent-trades]
```python
trades = client.get_recent_trades(symbol='BNBBTC')
```
Get Historical Trades [#get-historical-trades]
```python
trades = client.get_historical_trades(symbol='BNBBTC')
```
Get Aggregate Trades [#get-aggregate-trades]
```python
trades = client.get_aggregate_trades(symbol='BNBBTC')
```
Aggregate Trade Iterator [#aggregate-trade-iterator]
Iterate over aggregate trades for a symbol from a given date or order id:
```python
agg_trades = client.aggregate_trade_iter(symbol='ETHBTC', start_str='30 minutes ago UTC')
for trade in agg_trades:
print(trade)
# Convert to list (note: generators can only be iterated once)
agg_trades = client.aggregate_trade_iter(symbol='ETHBTC', start_str='30 minutes ago UTC')
agg_trade_list = list(agg_trades)
# Using last_id
agg_trades = client.aggregate_trade_iter(symbol='ETHBTC', last_id=23380478)
agg_trade_list = list(agg_trades)
```
Get Kline/Candlesticks [#get-klinecandlesticks]
```python
candles = client.get_klines(symbol='BNBBTC', interval=Client.KLINE_INTERVAL_30MINUTE)
```
Get Historical Kline/Candlesticks [#get-historical-klinecandlesticks]
Fetch klines for any date range and interval:
```python
# Fetch 1 minute klines for the last day
klines = client.get_historical_klines("BNBBTC", Client.KLINE_INTERVAL_1MINUTE, "1 day ago UTC")
# Fetch 30 minute klines for a specific date range
klines = client.get_historical_klines("ETHBTC", Client.KLINE_INTERVAL_30MINUTE, "1 Dec, 2017", "1 Jan, 2018")
# Fetch weekly klines since listing
klines = client.get_historical_klines("NEOBTC", Client.KLINE_INTERVAL_1WEEK, "1 Jan, 2017")
```
Get Historical Klines Using a Generator [#get-historical-klines-using-a-generator]
```python
for kline in client.get_historical_klines_generator("BNBBTC", Client.KLINE_INTERVAL_1MINUTE, "1 day ago UTC"):
print(kline)
```
Get Average Price [#get-average-price]
```python
avg_price = client.get_avg_price(symbol='BNBBTC')
```
Get 24hr Ticker [#get-24hr-ticker]
```python
tickers = client.get_ticker()
```
Get All Prices [#get-all-prices]
Get last price for all markets:
```python
prices = client.get_all_tickers()
```
Get Orderbook Tickers [#get-orderbook-tickers]
Get first bid and ask entry in the order book for all markets:
```python
tickers = client.get_orderbook_tickers()
```
# Sub Accounts (/docs/guides/sub-accounts)
Get Sub Account List [#get-sub-account-list]
```python
accounts = client.get_sub_account_list()
```
Get Sub Account Transfer History [#get-sub-account-transfer-history]
```python
history = client.get_sub_account_transfer_history(
fromEmail='blah@gmail.com',
toEmail='foo@gmail.com')
```
Get Sub Account Assets [#get-sub-account-assets]
```python
assets = client.get_sub_account_assets(email='blah@gmail.com')
```
# WebSockets (/docs/guides/websockets)
API Requests via WebSockets [#api-requests-via-websockets]
Some API endpoints can be accessed via websockets:
* Synchronous: `client.ws_`
* Asynchronous: `async_client.ws_`
```python
# Synchronous
client.ws_get_order_book(symbol="BTCUSDT")
# Asynchronous
await async_client.ws_get_order_book(symbol="BTCUSDT")
```
WebSocket Managers for Streaming Data [#websocket-managers-for-streaming-data]
There are 2 ways to interact with websockets for streaming data:
* **ThreadedWebsocketManager** — does not require asyncio programming
* **BinanceSocketManager** — requires asyncio
`ThreadedWebsocketManager` functions begin with `start_` (e.g. `start_ticker_socket`), while `BinanceSocketManager` uses the plain name (e.g. `ticker_socket`).
Multiple socket connections can be made through either manager. Only one instance of each socket type will be created per symbol. Messages are received as dictionary objects matching the [Binance WebSocket API documentation](https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams).
Websockets reconnect automatically with up to 5 retries using exponential backoff.
ThreadedWebsocketManager Usage [#threadedwebsocketmanager-usage]
```python
import time
from binance import ThreadedWebsocketManager
api_key = ''
api_secret = ''
def main():
symbol = 'BNBBTC'
twm = ThreadedWebsocketManager(api_key=api_key, api_secret=api_secret)
twm.start()
def handle_socket_message(msg):
print(f"message type: {msg['e']}")
print(msg)
twm.start_kline_socket(callback=handle_socket_message, symbol=symbol)
twm.start_depth_socket(callback=handle_socket_message, symbol=symbol)
# Multiplex socket
streams = ['bnbbtc@miniTicker', 'bnbbtc@bookTicker']
twm.start_multiplex_socket(callback=handle_socket_message, streams=streams)
twm.join()
if __name__ == "__main__":
main()
```
Stop Individual Stream [#stop-individual-stream]
```python
twm = ThreadedWebsocketManager()
twm.start()
depth_stream_name = twm.start_depth_socket(callback=handle_socket_message, symbol=symbol)
# Later...
twm.stop_socket(depth_stream_name)
```
Stop All Streams [#stop-all-streams]
```python
twm.stop()
```
Attempting to start a stream after `stop` is called will not work.
BinanceSocketManager Usage [#binancesocketmanager-usage]
```python
import asyncio
from binance import AsyncClient, BinanceSocketManager
async def main():
client = await AsyncClient.create()
bm = BinanceSocketManager(client)
ts = bm.trade_socket('BNBBTC')
async with ts as tscm:
while True:
res = await tscm.recv()
print(res)
await client.close_connection()
if __name__ == "__main__":
asyncio.run(main())
```
Set a custom timeout:
```python
bm = BinanceSocketManager(client, user_timeout=60)
```
Manually enter and exit the context manager:
```python
ts = bm.trade_socket('BNBBTC')
await ts.__aenter__()
msg = await ts.recv()
print(msg)
await ts.__aexit__(None, None, None)
```
Using a Different TLD [#using-a-different-tld]
```python
# ThreadedWebsocketManager
twm = ThreadedWebsocketManager(tld='us')
# BinanceSocketManager
client = await AsyncClient.create(tld='us')
bm = BinanceSocketManager(client)
```
WebSocket Errors [#websocket-errors]
If an error occurs, a message is sent to the callback:
```python
{
'e': 'error',
'type': '',
'm': ''
}
```
| Type | Description | Typical Action |
| --------------------------------- | --------------------------------------------- | ----------------------------------------- |
| `BinanceWebsocketUnableToConnect` | Could not connect after max retries | Check network, restart socket |
| `BinanceWebsocketClosed` | Connection closed, will auto-reconnect | Usually auto-reconnects |
| `BinanceWebsocketQueueOverflow` | Message queue exceeded max size (default 100) | Process messages faster or increase queue |
| `CancelledError` | Task was cancelled (e.g., on shutdown) | Usually safe to ignore |
| `IncompleteReadError` | Connection interrupted during read | Will attempt to reconnect |
| `gaierror` | DNS failure | Check network |
| `ConnectionClosedError` | Unexpected close | Will attempt to reconnect |
**Example error handling:**
```python
def process_message(msg):
if msg.get('e') == 'error':
print(f"WebSocket error: {msg.get('type')} - {msg.get('m')}")
else:
# process message normally
pass
```
> Most connection-related errors trigger automatic reconnection up to 5 times. If the queue overflows, increase `max_queue_size` or process messages more quickly.
WebSocket Examples [#websocket-examples]
Multiplex Socket [#multiplex-socket]
Combine multiple streams (depth, kline, ticker, trade — not user stream). Symbols must be lowercase.
```python
ms = bm.multiplex_socket(['bnbbtc@aggTrade', 'neobtc@ticker'])
```
Depth Socket [#depth-socket]
```python
# Diff response (default)
ds = bm.depth_socket('BNBBTC')
# Partial book response (valid depths: 5, 10, 20)
ds = bm.depth_socket('BNBBTC', depth=BinanceSocketManager.WEBSOCKET_DEPTH_5)
```
Kline Socket [#kline-socket]
```python
from binance.enums import *
ks = bm.kline_socket('BNBBTC', interval=KLINE_INTERVAL_30MINUTE)
```
Aggregated Trade Socket [#aggregated-trade-socket]
```python
ats = bm.aggtrade_socket('BNBBTC')
```
Trade Socket [#trade-socket]
```python
ts = bm.trade_socket('BNBBTC')
```
Symbol Ticker Socket [#symbol-ticker-socket]
```python
sts = bm.symbol_ticker_socket('BNBBTC')
```
Ticker Socket [#ticker-socket]
```python
ts = bm.ticker_socket(process_message)
```
Mini Ticker Socket [#mini-ticker-socket]
```python
# Updates every second (default)
mts = bm.miniticker_socket()
# Updates every 5 seconds
mts = bm.miniticker_socket(5000)
```
User Socket [#user-socket]
Watches for Account Update, Order Update, and Trade Update events. There are separate sockets for Spot, Cross-margin, and Isolated margin.
```python
# Spot trading
bm.user_socket()
# Cross-margin
bm.margin_socket()
# Isolated margin
bm.isolated_margin_socket(symbol)
```
# Withdrawals (/docs/guides/withdrawals)
Place a Withdrawal [#place-a-withdrawal]
Make sure you enable Withdrawal permissions for your API Key. You must have withdrawn to the address through the website and approved via email before using the API.
```python
from binance.exceptions import BinanceAPIException
try:
result = client.withdraw(
coin='ETH',
address='',
amount=100)
except BinanceAPIException as e:
print(e)
else:
print("Success")
# With a name parameter
result = client.withdraw(
coin='ETH',
address='',
amount=100,
name='Withdraw')
# For coins requiring a tag (e.g. XRP, XMR)
result = client.withdraw(
coin='XRP',
address='',
addressTag='',
amount=10000)
```
Fetch Deposit History [#fetch-deposit-history]
```python
deposits = client.get_deposit_history()
btc_deposits = client.get_deposit_history(coin='BTC')
```
Fetch Withdraw History [#fetch-withdraw-history]
```python
withdraws = client.get_withdraw_history()
btc_withdraws = client.get_withdraw_history(coin='BTC')
```
Get Deposit Address [#get-deposit-address]
```python
address = client.get_deposit_address(coin='BTC')
```
# AsyncClient (/docs/api/async_client/AsyncClient)
Attributes [#attributes]
Functions [#functions]
```python
def __init__(
self,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
requests_params: Optional[Dict[str, Any]] = None,
tld: str = "com",
base_endpoint: str = BaseClient.BASE_ENDPOINT_DEFAULT,
testnet: bool = False,
demo: bool = False,
loop=None,
session_params: Optional[Dict[str, Any]] = None,
private_key: Optional[Union[str, Path]] = None,
private_key_pass: Optional[str] = None,
https_proxy: Optional[str] = None,
time_unit: Optional[str] = None,
verbose: bool = False,
):
self.https_proxy = https_proxy
self.loop = loop or get_loop()
self._session_params: Dict[str, Any] = session_params or {}
# Convert https_proxy to requests_params format for BaseClient
if https_proxy and requests_params is None:
requests_params = {'proxies': {'http': https_proxy, 'https': https_proxy}}
elif https_proxy and requests_params is not None:
if 'proxies' not in requests_params:
requests_params['proxies'] = {}
requests_params['proxies'].update({'http': https_proxy, 'https': https_proxy})
super().__init__(
api_key,
api_secret,
requests_params,
tld,
base_endpoint,
testnet,
demo,
private_key,
private_key_pass,
time_unit=time_unit,
verbose=verbose,
)
```
```python
@classmethod
async def create(
cls,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
requests_params: Optional[Dict[str, Any]] = None,
tld: str = "com",
base_endpoint: str = BaseClient.BASE_ENDPOINT_DEFAULT,
testnet: bool = False,
demo: bool = False,
loop=None,
session_params: Optional[Dict[str, Any]] = None,
private_key: Optional[Union[str, Path]] = None,
private_key_pass: Optional[str] = None,
https_proxy: Optional[str] = None,
time_unit: Optional[str] = None,
verbose: bool = False,
):
self = cls(
api_key,
api_secret,
requests_params,
tld,
base_endpoint,
testnet,
demo,
loop,
session_params,
private_key,
private_key_pass,
https_proxy,
time_unit,
verbose
)
self.https_proxy = https_proxy # move this to the constructor
try:
await self.ping()
# calculate timestamp offset between local and binance server
res = await self.get_server_time()
self.timestamp_offset = res["serverTime"] - int(time.time() * 1000)
return self
except Exception:
# If ping throw an exception, the current self must be cleaned
# else, we can receive a "asyncio:Unclosed client session"
await self.close_connection()
raise
```
```python
def _init_session(self) -> aiohttp.ClientSession:
session = aiohttp.ClientSession(
loop=self.loop, headers=self._get_headers(), **self._session_params
)
return session
```
```python
async def close_connection(self):
if self.session:
assert self.session
await self.session.close()
if self.ws_api:
await self.ws_api.close()
self._ws_api = None
```
```python
async def _request(
self, method, uri: str, signed: bool, force_params: bool = False, **kwargs
):
# this check needs to be done before __get_request_kwargs to avoid
# polluting the signature
headers = {}
if method.upper() in ["POST", "PUT", "DELETE"]:
headers.update({"Content-Type": "application/x-www-form-urlencoded"})
if "data" in kwargs:
for key in kwargs["data"]:
if key == "headers":
headers.update(kwargs["data"][key])
del kwargs["data"][key]
break
kwargs = self._get_request_kwargs(method, signed, force_params, **kwargs)
if method == "get":
# url encode the query string
if "params" in kwargs:
uri = f"{uri}?{kwargs['params']}"
kwargs.pop("params")
data = kwargs.get("data")
if data is not None:
del kwargs["data"]
if (
signed and self.PRIVATE_KEY and data
): # handle issues with signing using eddsa/rsa and POST requests
dict_data = Client.convert_to_dict(data)
signature = dict_data["signature"] if "signature" in dict_data else None
if signature:
del dict_data["signature"]
url_encoded_data = urlencode(dict_data)
data = f"{url_encoded_data}&signature={signature}"
# Remove proxies from kwargs since aiohttp uses 'proxy' parameter instead
kwargs.pop('proxies', None)
async with getattr(self.session, method)(
yarl.URL(uri, encoded=True),
proxy=self.https_proxy,
headers=headers,
data=data,
**kwargs,
) as response:
self.response = response
if self.verbose:
response_text = await response.text()
self.logger.debug(
"\nRequest: %s %s\nRequestHeaders: %s\nRequestBody: %s\nResponse: %s\nResponseHeaders: %s\nResponseBody: %s",
method.upper(),
uri,
headers,
data,
response.status,
dict(response.headers),
response_text[:1000] if response_text else None
)
return await self._handle_response(response)
```
Internal helper for handling API responses from the Binance server.
Raises the appropriate exceptions when necessary; otherwise, returns the
response.
```python
async def _handle_response(self, response: aiohttp.ClientResponse):
"""Internal helper for handling API responses from the Binance server.
Raises the appropriate exceptions when necessary; otherwise, returns the
response.
"""
if not str(response.status).startswith("2"):
raise BinanceAPIException(response, response.status, await response.text())
text = await response.text()
if text == "":
return {}
try:
return await response.json()
except ValueError:
txt = await response.text()
raise BinanceRequestException(f"Invalid Response: {txt}")
```
```python
async def _request_api(
self,
method,
path,
signed=False,
version=BaseClient.PUBLIC_API_VERSION,
**kwargs,
):
uri = self._create_api_uri(path, signed, version)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)
```
```python
async def _request_futures_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_futures_api_uri(path, version=version)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)
```
```python
async def _request_futures_data_api(
self, method, path, signed=False, **kwargs
) -> Dict:
uri = self._create_futures_data_api_uri(path)
force_params = kwargs.pop("force_params", True)
return await self._request(method, uri, signed, force_params, **kwargs)
```
```python
async def _request_futures_coin_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_futures_coin_api_url(path, version=version)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)
```
```python
async def _request_futures_coin_data_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_futures_coin_data_api_url(path, version=version)
force_params = kwargs.pop("force_params", True)
return await self._request(method, uri, signed, force_params, **kwargs)
```
```python
async def _request_options_api(self, method, path, signed=False, **kwargs) -> Dict:
uri = self._create_options_api_uri(path)
force_params = kwargs.pop("force_params", True)
return await self._request(method, uri, signed, force_params, **kwargs)
```
```python
async def _request_margin_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_margin_api_uri(path, version)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)
```
```python
async def _request_papi_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_papi_api_uri(path, version)
force_params = kwargs.pop("force_params", False)
return await self._request(method, uri, signed, force_params, **kwargs)
```
```python
async def _request_website(self, method, path, signed=False, **kwargs) -> Dict:
uri = self._create_website_uri(path)
return await self._request(method, uri, signed, **kwargs)
```
```python
async def _get(
self, path, signed=False, version=BaseClient.PUBLIC_API_VERSION, **kwargs
):
return await self._request_api("get", path, signed, version, **kwargs)
```
```python
async def _post(
self, path, signed=False, version=BaseClient.PUBLIC_API_VERSION, **kwargs
) -> Dict:
return await self._request_api("post", path, signed, version, **kwargs)
```
```python
async def _put(
self, path, signed=False, version=BaseClient.PUBLIC_API_VERSION, **kwargs
) -> Dict:
return await self._request_api("put", path, signed, version, **kwargs)
```
```python
async def _delete(
self, path, signed=False, version=BaseClient.PUBLIC_API_VERSION, **kwargs
) -> Dict:
return await self._request_api("delete", path, signed, version, **kwargs)
```
```python
async def get_products(self) -> Dict:
products = await self._request_website(
"get",
"bapi/asset/v2/public/asset-service/product/get-products?includeEtf=true",
)
return products
```
```python
async def get_exchange_info(self) -> Dict:
return await self._get("exchangeInfo")
```
```python
async def get_symbol_info(self, symbol) -> Optional[Dict]:
res = await self.get_exchange_info()
for item in res["symbols"]:
if item["symbol"] == symbol.upper():
return item
return None
```
```python
async def ping(self) -> Dict:
return await self._get("ping")
```
```python
async def get_server_time(self) -> Dict:
return await self._get("time")
```
```python
async def get_all_tickers(
self, symbol: Optional[str] = None
) -> List[Dict[str, str]]:
params = {}
if symbol:
params["symbol"] = symbol
response = await self._get(
"ticker/price", data=params
)
if isinstance(response, list) and all(isinstance(item, dict) for item in response):
return response
raise TypeError("Expected a list of dictionaries")
```
```python
async def get_orderbook_tickers(self, **params) -> Dict:
data = {}
if "symbol" in params:
data["symbol"] = params["symbol"]
elif "symbols" in params:
data["symbols"] = params["symbols"]
return await self._get(
"ticker/bookTicker", data=data
)
```
```python
async def get_order_book(self, **params) -> Dict:
return await self._get("depth", data=params)
```
```python
async def get_recent_trades(self, **params) -> Dict:
return await self._get("trades", data=params)
```
```python
async def get_historical_trades(self, **params) -> Dict:
return await self._get(
"historicalTrades", data=params
)
```
```python
async def get_aggregate_trades(self, **params) -> Dict:
return await self._get(
"aggTrades", data=params
)
```
```python
async def aggregate_trade_iter(self, symbol, start_str=None, last_id=None):
if start_str is not None and last_id is not None:
raise ValueError(
"start_time and last_id may not be simultaneously specified."
)
# If there's no last_id, get one.
if last_id is None:
# Without a last_id, we actually need the first trade. Normally,
# we'd get rid of it. See the next loop.
if start_str is None:
trades = await self.get_aggregate_trades(symbol=symbol, fromId=0)
else:
# The difference between startTime and endTime should be less
# or equal than an hour and the result set should contain at
# least one trade.
start_ts = convert_ts_str(start_str)
# If the resulting set is empty (i.e. no trades in that interval)
# then we just move forward hour by hour until we find at least one
# trade or reach present moment
while True:
end_ts = start_ts + (60 * 60 * 1000)
trades = await self.get_aggregate_trades(
symbol=symbol, startTime=start_ts, endTime=end_ts
)
if len(trades) > 0:
break
# If we reach present moment and find no trades then there is
# nothing to iterate, so we're done
if end_ts > int(time.time() * 1000):
return
start_ts = end_ts
for t in trades:
yield t
last_id = trades[-1][self.AGG_ID]
while True:
# There is no need to wait between queries, to avoid hitting the
# rate limit. We're using blocking IO, and as long as we're the
# only thread running calls like this, Binance will automatically
# add the right delay time on their end, forcing us to wait for
# data. That really simplifies this function's job. Binance is
# fucking awesome.
trades = await self.get_aggregate_trades(symbol=symbol, fromId=last_id)
# fromId=n returns a set starting with id n, but we already have
# that one. So get rid of the first item in the result set.
trades = trades[1:]
if len(trades) == 0:
return
for t in trades:
yield t
last_id = trades[-1][self.AGG_ID]
```
```python
async def get_ui_klines(self, **params) -> Dict:
return await self._get("uiKlines", data=params)
```
```python
async def get_klines(self, **params) -> Dict:
return await self._get("klines", data=params)
```
```python
async def _klines(
self, klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT, **params
) -> Dict:
if "endTime" in params and not params["endTime"]:
del params["endTime"]
if HistoricalKlinesType.SPOT == klines_type:
return await self.get_klines(**params)
elif HistoricalKlinesType.FUTURES == klines_type:
return await self.futures_klines(**params)
elif HistoricalKlinesType.FUTURES_COIN == klines_type:
return await self.futures_coin_klines(**params)
elif HistoricalKlinesType.FUTURES_MARK_PRICE == klines_type:
return await self.futures_mark_price_klines(**params)
elif HistoricalKlinesType.FUTURES_INDEX_PRICE == klines_type:
return await self.futures_index_price_klines(**params)
elif HistoricalKlinesType.FUTURES_COIN_MARK_PRICE == klines_type:
return await self.futures_coin_mark_price_klines(**params)
elif HistoricalKlinesType.FUTURES_COIN_INDEX_PRICE == klines_type:
return await self.futures_coin_index_price_klines(**params)
else:
raise NotImplementedException(klines_type)
```
```python
async def _get_earliest_valid_timestamp(
self,
symbol,
interval,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
kline = await self._klines(
klines_type=klines_type,
symbol=symbol,
interval=interval,
limit=1,
startTime=0,
endTime=int(time.time() * 1000),
)
return kline[0][0]
```
```python
async def get_historical_klines(
self,
symbol,
interval,
start_str=None,
end_str=None,
limit=None,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
return await self._historical_klines(
symbol,
interval,
start_str,
end_str=end_str,
limit=limit,
klines_type=klines_type,
)
```
```python
async def _historical_klines(
self,
symbol,
interval,
start_str=None,
end_str=None,
limit=None,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
initial_limit_set = True
if limit is None:
limit = 1000
initial_limit_set = False
# init our list
output_data = []
# convert interval to useful value in seconds
timeframe = interval_to_milliseconds(interval)
# establish first available start timestamp
start_ts = convert_ts_str(start_str)
if start_ts is not None:
first_valid_ts = await self._get_earliest_valid_timestamp(
symbol, interval, klines_type
)
start_ts = max(start_ts, first_valid_ts)
# if an end time was passed convert it
end_ts = convert_ts_str(end_str)
if end_ts and start_ts and end_ts <= start_ts:
return output_data
idx = 0
while True:
# fetch the klines from start_ts up to max 500 entries or the end_ts if set
temp_data = await self._klines(
klines_type=klines_type,
symbol=symbol,
interval=interval,
limit=limit,
startTime=start_ts,
endTime=end_ts,
)
# append this loops data to our output data
if temp_data:
output_data += temp_data
# check if output_data is greater than limit and truncate if needed and break loop
if initial_limit_set and len(output_data) > limit:
output_data = output_data[:limit]
break
# handle the case where exactly the limit amount of data was returned last loop
# or check if we received less than the required limit and exit the loop
if not len(temp_data) or len(temp_data) < limit:
# exit the while loop
break
# set our start timestamp using the last value in the array
# and increment next call by our timeframe
start_ts = temp_data[-1][0] + timeframe
# exit loop if we reached end_ts before reaching klines
if end_ts and start_ts >= end_ts:
break
# sleep after every 3rd call to be kind to the API
idx += 1
if idx % 3 == 0:
await asyncio.sleep(1)
return output_data
```
```python
async def get_historical_klines_generator(
self,
symbol,
interval,
start_str=None,
end_str=None,
limit=1000,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
return self._historical_klines_generator(
symbol,
interval,
start_str,
end_str=end_str,
limit=limit,
klines_type=klines_type,
)
```
```python
async def _historical_klines_generator(
self,
symbol,
interval,
start_str=None,
end_str=None,
limit=1000,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
# convert interval to useful value in seconds
timeframe = interval_to_milliseconds(interval)
# if a start time was passed convert it
start_ts = convert_ts_str(start_str)
# establish first available start timestamp
if start_ts is not None:
first_valid_ts = await self._get_earliest_valid_timestamp(
symbol, interval, klines_type
)
start_ts = max(start_ts, first_valid_ts)
# if an end time was passed convert it
end_ts = convert_ts_str(end_str)
if end_ts and start_ts and end_ts <= start_ts:
return
idx = 0
while True:
# fetch the klines from start_ts up to max 500 entries or the end_ts if set
output_data = await self._klines(
klines_type=klines_type,
symbol=symbol,
interval=interval,
limit=limit,
startTime=start_ts,
endTime=end_ts,
)
# yield data
if output_data:
for o in output_data:
yield o
# handle the case where exactly the limit amount of data was returned last loop
# check if we received less than the required limit and exit the loop
if not len(output_data) or len(output_data) < limit:
# exit the while loop
break
# increment next call by our timeframe
start_ts = output_data[-1][0] + timeframe
# exit loop if we reached end_ts before reaching klines
if end_ts and start_ts >= end_ts:
break
# sleep after every 3rd call to be kind to the API
idx += 1
if idx % 3 == 0:
await asyncio.sleep(1)
```
```python
async def get_avg_price(self, **params):
return await self._get(
"avgPrice", data=params
)
```
```python
async def get_ticker(self, **params):
return await self._get(
"ticker/24hr", data=params
)
```
```python
async def get_symbol_ticker(self, **params):
return await self._get(
"ticker/price", data=params
)
```
```python
async def get_symbol_ticker_window(self, **params):
return await self._get("ticker", data=params)
```
```python
async def get_orderbook_ticker(self, **params):
return await self._get(
"ticker/bookTicker", data=params
)
```
```python
async def create_order(self, **params):
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return await self._post("order", True, data=params)
```
```python
async def order_limit(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
params.update({"type": self.ORDER_TYPE_LIMIT, "timeInForce": timeInForce})
return await self.create_order(**params)
```
```python
async def order_limit_buy(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
params.update({
"side": self.SIDE_BUY,
})
return await self.order_limit(timeInForce=timeInForce, **params)
```
```python
async def order_limit_sell(
self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params
):
params.update({"side": self.SIDE_SELL})
return await self.order_limit(timeInForce=timeInForce, **params)
```
```python
async def order_market(self, **params):
params.update({"type": self.ORDER_TYPE_MARKET})
return await self.create_order(**params)
```
```python
async def order_market_buy(self, **params):
params.update({"side": self.SIDE_BUY})
return await self.order_market(**params)
```
```python
async def order_market_sell(self, **params):
params.update({"side": self.SIDE_SELL})
return await self.order_market(**params)
```
```python
async def order_oco_buy(self, **params):
params.update({"side": self.SIDE_BUY})
return await self.create_oco_order(**params)
```
```python
async def order_oco_sell(self, **params):
params.update({"side": self.SIDE_SELL})
return await self.create_oco_order(**params)
```
```python
async def create_test_order(self, **params):
return await self._post("order/test", True, data=params)
```
```python
async def get_order(self, **params):
return await self._get("order", True, data=params)
```
```python
async def get_all_orders(self, **params):
return await self._get("allOrders", True, data=params)
```
```python
async def cancel_order(self, **params):
return await self._delete("order", True, data=params)
```
```python
async def get_open_orders(self, **params):
return await self._get("openOrders", True, data=params)
```
```python
async def get_open_oco_orders(self, **params):
return await self._get("openOrderList", True, data=params)
```
```python
async def get_account(self, **params):
return await self._get("account", True, data=params)
```
```python
async def get_asset_balance(self, asset=None, **params):
res = await self.get_account(**params)
# find asset balance in list of balances
if "balances" in res:
if asset:
for bal in res["balances"]:
if bal["asset"].lower() == asset.lower():
return bal
else:
return res["balances"]
return None
```
```python
async def get_my_trades(self, **params):
return await self._get("myTrades", True, data=params)
```
```python
async def get_current_order_count(self, **params):
return await self._get("rateLimit/order", True, data=params)
```
```python
async def get_prevented_matches(self, **params):
return await self._get("myPreventedMatches", True, data=params)
```
```python
async def get_allocations(self, **params):
return await self._get("myAllocations", True, data=params)
```
```python
async def get_system_status(self):
return await self._request_margin_api("get", "system/status")
```
```python
async def get_account_status(self, **params):
return await self._request_margin_api(
"get", "account/status", True, data=params
)
```
```python
async def get_account_api_trading_status(self, **params):
return await self._request_margin_api(
"get", "account/apiTradingStatus", True, data=params
)
```
```python
async def get_account_api_permissions(self, **params):
return await self._request_margin_api(
"get", "account/apiRestrictions", True, data=params
)
```
```python
async def get_dust_assets(self, **params):
return await self._request_margin_api(
"post", "asset/dust-btc", True, data=params
)
```
```python
async def get_dust_log(self, **params):
return await self._request_margin_api(
"get", "asset/dribblet", True, data=params
)
```
```python
async def transfer_dust(self, **params):
return await self._request_margin_api("post", "asset/dust", True, data=params)
```
```python
async def get_asset_dividend_history(self, **params):
return await self._request_margin_api(
"get", "asset/assetDividend", True, data=params
)
```
```python
async def make_universal_transfer(self, **params):
return await self._request_margin_api(
"post", "asset/transfer", signed=True, data=params
)
```
```python
async def query_universal_transfer_history(self, **params):
return await self._request_margin_api(
"get", "asset/transfer", signed=True, data=params
)
```
```python
async def get_trade_fee(self, **params):
if self.tld == "us":
endpoint = "asset/query/trading-fee"
else:
endpoint = "asset/tradeFee"
return await self._request_margin_api("get", endpoint, True, data=params)
```
```python
async def get_asset_details(self, **params):
return await self._request_margin_api(
"get", "asset/assetDetail", True, data=params
)
```
```python
async def get_spot_delist_schedule(self, **params):
return await self._request_margin_api(
"get", "/spot/delist-schedule", signed=False, data=params
)
```
```python
async def withdraw(self, **params):
# force a name for the withdrawal if one not set
if "coin" in params and "name" not in params:
params["name"] = params["coin"]
return await self._request_margin_api(
"post", "capital/withdraw/apply", True, data=params
)
```
```python
async def get_deposit_history(self, **params):
return await self._request_margin_api(
"get", "capital/deposit/hisrec", True, data=params
)
```
```python
async def get_withdraw_history(self, **params):
return await self._request_margin_api(
"get", "capital/withdraw/history", True, data=params
)
```
```python
async def get_withdraw_history_id(self, withdraw_id, **params):
result = await self.get_withdraw_history(**params)
for entry in result:
if "id" in entry and entry["id"] == withdraw_id:
return entry
raise Exception("There is no entry with withdraw id", result)
```
```python
async def get_deposit_address(
self, coin: str, network: Optional[str] = None, **params
):
params["coin"] = coin
if network:
params["network"] = network
return await self._request_margin_api(
"get", "capital/deposit/address", True, data=params
)
```
```python
async def stream_get_listen_key(self):
res = await self._post("userDataStream", False, data={})
return res["listenKey"]
```
```python
async def stream_keepalive(self, listenKey):
params = {"listenKey": listenKey}
return await self._put("userDataStream", False, data=params)
```
```python
async def stream_close(self, listenKey):
params = {"listenKey": listenKey}
return await self._delete("userDataStream", False, data=params)
```
```python
async def get_margin_account(self, **params):
return await self._request_margin_api(
"get", "margin/account", True, data=params
)
```
```python
async def get_isolated_margin_account(self, **params):
return await self._request_margin_api(
"get", "margin/isolated/account", True, data=params
)
```
```python
async def enable_isolated_margin_account(self, **params):
return await self._request_margin_api(
"post", "margin/isolated/account", True, data=params
)
```
```python
async def disable_isolated_margin_account(self, **params):
return await self._request_margin_api(
"delete", "margin/isolated/account", True, data=params
)
```
```python
async def get_enabled_isolated_margin_account_limit(self, **params):
return await self._request_margin_api(
"get", "margin/isolated/accountLimit", True, data=params
)
```
```python
async def get_margin_dustlog(self, **params):
return await self._request_margin_api(
"get", "margin/dribblet", True, data=params
)
```
```python
async def get_margin_dust_assets(self, **params):
return await self._request_margin_api("get", "margin/dust", True, data=params)
```
```python
async def transfer_margin_dust(self, **params):
return await self._request_margin_api("post", "margin/dust", True, data=params)
```
```python
async def get_cross_margin_collateral_ratio(self, **params):
return await self._request_margin_api(
"get", "margin/crossMarginCollateralRatio", True, data=params
)
```
```python
async def get_small_liability_exchange_assets(self, **params):
return await self._request_margin_api(
"get", "margin/exchange-small-liability", True, data=params
)
```
```python
async def exchange_small_liability_assets(self, **params):
return await self._request_margin_api(
"post", "margin/exchange-small-liability", True, data=params
)
```
```python
async def get_small_liability_exchange_history(self, **params):
return await self._request_margin_api(
"get", "margin/exchange-small-liability-history", True, data=params
)
```
```python
async def get_future_hourly_interest_rate(self, **params):
return await self._request_margin_api(
"get", "margin/next-hourly-interest-rate", True, data=params
)
```
```python
async def get_margin_capital_flow(self, **params):
return await self._request_margin_api(
"get", "margin/capital-flow", True, data=params
)
```
```python
async def get_margin_delist_schedule(self, **params):
return await self._request_margin_api(
"get", "margin/delist-schedule", True, data=params
)
```
```python
async def get_margin_asset(self, **params):
return await self._request_margin_api("get", "margin/asset", data=params)
```
```python
async def get_margin_symbol(self, **params):
return await self._request_margin_api("get", "margin/pair", data=params)
```
```python
async def get_margin_all_assets(self, **params):
return await self._request_margin_api("get", "margin/allAssets", data=params)
```
```python
async def get_margin_all_pairs(self, **params):
return await self._request_margin_api("get", "margin/allPairs", data=params)
```
```python
async def create_isolated_margin_account(self, **params):
return await self._request_margin_api(
"post", "margin/isolated/create", signed=True, data=params
)
```
```python
async def get_isolated_margin_symbol(self, **params):
return await self._request_margin_api(
"get", "margin/isolated/pair", signed=True, data=params
)
```
```python
async def get_all_isolated_margin_symbols(self, **params):
return await self._request_margin_api(
"get", "margin/isolated/allPairs", signed=True, data=params
)
```
```python
async def get_isolated_margin_fee_data(self, **params):
return await self._request_margin_api(
"get", "margin/isolatedMarginData", True, data=params
)
```
```python
async def get_isolated_margin_tier_data(self, **params):
return await self._request_margin_api(
"get", "margin/isolatedMarginTier", True, data=params
)
```
```python
async def margin_manual_liquidation(self, **params):
return await self._request_margin_api(
"get", "margin/manual-liquidation", True, data=params
)
```
```python
async def toggle_bnb_burn_spot_margin(self, **params):
return await self._request_margin_api(
"post", "bnbBurn", signed=True, data=params
)
```
```python
async def get_bnb_burn_spot_margin(self, **params):
return await self._request_margin_api(
"get", "bnbBurn", signed=True, data=params
)
```
```python
async def get_margin_price_index(self, **params):
return await self._request_margin_api("get", "margin/priceIndex", data=params)
```
```python
async def transfer_margin_to_spot(self, **params):
params["type"] = 2
return await self._request_margin_api(
"post", "margin/transfer", signed=True, data=params
)
```
```python
async def transfer_spot_to_margin(self, **params):
params["type"] = 1
return await self._request_margin_api(
"post", "margin/transfer", signed=True, data=params
)
```
```python
async def transfer_isolated_margin_to_spot(self, **params):
params["transFrom"] = "ISOLATED_MARGIN"
params["transTo"] = "SPOT"
return await self._request_margin_api(
"post", "margin/isolated/transfer", signed=True, data=params
)
```
```python
async def transfer_spot_to_isolated_margin(self, **params):
params["transFrom"] = "SPOT"
params["transTo"] = "ISOLATED_MARGIN"
return await self._request_margin_api(
"post", "margin/isolated/transfer", signed=True, data=params
)
```
```python
async def create_margin_loan(self, **params):
return await self._request_margin_api(
"post", "margin/loan", signed=True, data=params
)
```
```python
async def repay_margin_loan(self, **params):
return await self._request_margin_api(
"post", "margin/repay", signed=True, data=params
)
```
```python
async def create_margin_order(self, **params):
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return await self._request_margin_api(
"post", "margin/order", signed=True, data=params
)
```
```python
async def cancel_margin_order(self, **params):
return await self._request_margin_api(
"delete", "margin/order", signed=True, data=params
)
```
```python
async def cancel_all_open_margin_orders(self, **params):
return await self._request_margin_api(
"delete", "margin/openOrders", signed=True, data=params
)
```
```python
async def set_margin_max_leverage(self, **params):
return await self._request_margin_api(
"post", "margin/max-leverage", signed=True, data=params
)
```
```python
async def get_margin_transfer_history(self, **params):
return await self._request_margin_api(
"get", "margin/transfer", signed=True, data=params
)
```
```python
async def get_margin_loan_details(self, **params):
return await self._request_margin_api(
"get", "margin/loan", signed=True, data=params
)
```
```python
async def get_margin_repay_details(self, **params):
return await self._request_margin_api(
"get", "margin/repay", signed=True, data=params
)
```
```python
async def get_cross_margin_data(self, **params):
return await self._request_margin_api(
"get", "margin/crossMarginData", signed=True, data=params
)
```
```python
async def get_margin_interest_history(self, **params):
return await self._request_margin_api(
"get", "margin/interestHistory", signed=True, data=params
)
```
```python
async def get_margin_force_liquidation_rec(self, **params):
return await self._request_margin_api(
"get", "margin/forceLiquidationRec", signed=True, data=params
)
```
```python
async def get_margin_order(self, **params):
return await self._request_margin_api(
"get", "margin/order", signed=True, data=params
)
```
```python
async def get_open_margin_orders(self, **params):
return await self._request_margin_api(
"get", "margin/openOrders", signed=True, data=params
)
```
```python
async def get_all_margin_orders(self, **params):
return await self._request_margin_api(
"get", "margin/allOrders", signed=True, data=params
)
```
```python
async def get_margin_trades(self, **params):
return await self._request_margin_api(
"get", "margin/myTrades", signed=True, data=params
)
```
```python
async def get_max_margin_loan(self, **params):
return await self._request_margin_api(
"get", "margin/maxBorrowable", signed=True, data=params
)
```
```python
async def get_max_margin_transfer(self, **params):
return await self._request_margin_api(
"get", "margin/maxTransferable", signed=True, data=params
)
```
```python
async def create_margin_oco_order(self, **params):
return await self._request_margin_api(
"post", "margin/order/oco", signed=True, data=params
)
```
```python
async def cancel_margin_oco_order(self, **params):
return await self._request_margin_api(
"delete", "margin/orderList", signed=True, data=params
)
```
```python
async def get_margin_oco_order(self, **params):
return await self._request_margin_api(
"get", "margin/orderList", signed=True, data=params
)
```
```python
async def get_open_margin_oco_orders(self, **params):
return await self._request_margin_api(
"get", "margin/openOrderList", signed=True, data=params
)
```
```python
async def margin_stream_get_listen_key(self):
warnings.warn(
"POST /sapi/v1/userDataStream is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken, "
"then subscribe with userDataStream.subscribe.listenToken). "
"The margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
res = await self._request_margin_api(
"post", "userDataStream", signed=False, data={}
)
return res["listenKey"]
```
```python
async def margin_stream_keepalive(self, listenKey):
warnings.warn(
"PUT /sapi/v1/userDataStream is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken, "
"then subscribe with userDataStream.subscribe.listenToken). "
"The margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"listenKey": listenKey}
return await self._request_margin_api(
"put", "userDataStream", signed=False, data=params
)
```
```python
async def margin_stream_close(self, listenKey):
warnings.warn(
"DELETE /sapi/v1/userDataStream is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken, "
"then subscribe with userDataStream.subscribe.listenToken). "
"The margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"listenKey": listenKey}
return await self._request_margin_api(
"delete", "userDataStream", signed=False, data=params
)
```
Create a listenToken for margin account user data stream
[https://developers.binance.com/docs/margin\_trading/trade-data-stream/Create-Margin-Account-listenToken](https://developers.binance.com/docs/margin_trading/trade-data-stream/Create-Margin-Account-listenToken)
:param symbol: Trading pair symbol (required when is\_isolated=True)
:type symbol: str
:param is\_isolated: Whether it is isolated margin (default: False for cross-margin)
:type is\_isolated: bool
:param validity: Validity in milliseconds (default: 24 hours, max: 24 hours)
:type validity: int
:returns: API response with token and expirationTime
.. code-block:: python
\{
"token": "6xXxePXwZRjVSHKhzUCCGnmN3fkvMTXru+pYJS8RwijXk9Vcyr3rkwfVOTcP2OkONqciYA",
"expirationTime": 1758792204196
}
```python
async def margin_create_listen_token(self, symbol: Optional[str] = None, is_isolated: bool = False, validity: Optional[int] = None):
"""Create a listenToken for margin account user data stream
https://developers.binance.com/docs/margin_trading/trade-data-stream/Create-Margin-Account-listenToken
:param symbol: Trading pair symbol (required when is_isolated=True)
:type symbol: str
:param is_isolated: Whether it is isolated margin (default: False for cross-margin)
:type is_isolated: bool
:param validity: Validity in milliseconds (default: 24 hours, max: 24 hours)
:type validity: int
:returns: API response with token and expirationTime
.. code-block:: python
{
"token": "6xXxePXwZRjVSHKhzUCCGnmN3fkvMTXru+pYJS8RwijXk9Vcyr3rkwfVOTcP2OkONqciYA",
"expirationTime": 1758792204196
}
"""
params = {}
if is_isolated:
if not symbol:
raise ValueError("symbol is required when is_isolated=True")
params["symbol"] = symbol
params["isIsolated"] = "true"
if validity is not None:
params["validity"] = validity
return await self._request_margin_api(
"post", "userListenToken", signed=True, data=params
)
```
```python
async def isolated_margin_stream_get_listen_key(self, symbol):
warnings.warn(
"POST /sapi/v1/userDataStream/isolated is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken "
"with isIsolated=true, then subscribe with userDataStream.subscribe.listenToken). "
"The isolated_margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"symbol": symbol}
res = await self._request_margin_api(
"post", "userDataStream/isolated", signed=False, data=params
)
return res["listenKey"]
```
```python
async def isolated_margin_stream_keepalive(self, symbol, listenKey):
warnings.warn(
"PUT /sapi/v1/userDataStream/isolated is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken "
"with isIsolated=true, then subscribe with userDataStream.subscribe.listenToken). "
"The isolated_margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"symbol": symbol, "listenKey": listenKey}
return await self._request_margin_api(
"put", "userDataStream/isolated", signed=False, data=params
)
```
```python
async def isolated_margin_stream_close(self, symbol, listenKey):
warnings.warn(
"DELETE /sapi/v1/userDataStream/isolated is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken "
"with isIsolated=true, then subscribe with userDataStream.subscribe.listenToken). "
"The isolated_margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"symbol": symbol, "listenKey": listenKey}
return await self._request_margin_api(
"delete", "userDataStream/isolated", signed=False, data=params
)
```
```python
async def get_simple_earn_flexible_product_list(self, **params):
return await self._request_margin_api(
"get", "simple-earn/flexible/list", signed=True, data=params
)
```
```python
async def get_simple_earn_locked_product_list(self, **params):
return await self._request_margin_api(
"get", "simple-earn/locked/list", signed=True, data=params
)
```
```python
async def subscribe_simple_earn_flexible_product(self, **params):
return await self._request_margin_api(
"post", "simple-earn/flexible/subscribe", signed=True, data=params
)
```
```python
async def subscribe_simple_earn_locked_product(self, **params):
return await self._request_margin_api(
"post", "simple-earn/locked/subscribe", signed=True, data=params
)
```
```python
async def redeem_simple_earn_flexible_product(self, **params):
return await self._request_margin_api(
"post", "simple-earn/flexible/redeem", signed=True, data=params
)
```
```python
async def redeem_simple_earn_locked_product(self, **params):
return await self._request_margin_api(
"post", "simple-earn/locked/redeem", signed=True, data=params
)
```
```python
async def get_simple_earn_flexible_product_position(self, **params):
return await self._request_margin_api(
"get", "simple-earn/flexible/position", signed=True, data=params
)
```
```python
async def get_simple_earn_locked_product_position(self, **params):
return await self._request_margin_api(
"get", "simple-earn/locked/position", signed=True, data=params
)
```
```python
async def get_simple_earn_account(self, **params):
return await self._request_margin_api(
"get", "simple-earn/account", signed=True, data=params
)
```
```python
async def get_fixed_activity_project_list(self, **params):
return await self._request_margin_api(
"get", "lending/project/list", signed=True, data=params
)
```
```python
async def change_fixed_activity_to_daily_position(self, **params):
return await self._request_margin_api(
"post", "lending/positionChanged", signed=True, data=params
)
```
```python
async def get_staking_product_list(self, **params):
return await self._request_margin_api(
"get", "staking/productList", signed=True, data=params
)
```
```python
async def purchase_staking_product(self, **params):
return await self._request_margin_api(
"post", "staking/purchase", signed=True, data=params
)
```
```python
async def redeem_staking_product(self, **params):
return await self._request_margin_api(
"post", "staking/redeem", signed=True, data=params
)
```
```python
async def get_staking_position(self, **params):
return await self._request_margin_api(
"get", "staking/position", signed=True, data=params
)
```
```python
async def get_staking_purchase_history(self, **params):
return await self._request_margin_api(
"get", "staking/purchaseRecord", signed=True, data=params
)
```
```python
async def set_auto_staking(self, **params):
return await self._request_margin_api(
"post", "staking/setAutoStaking", signed=True, data=params
)
```
```python
async def get_personal_left_quota(self, **params):
return await self._request_margin_api(
"get", "staking/personalLeftQuota", signed=True, data=params
)
```
```python
async def get_staking_asset_us(self, **params):
self._require_tld("us", "get_staking_asset_us")
return await self._request_margin_api("get", "staking/asset", True, data=params)
```
```python
async def stake_asset_us(self, **params):
self._require_tld("us", "stake_asset_us")
return await self._request_margin_api(
"post", "staking/stake", True, data=params
)
```
```python
async def unstake_asset_us(self, **params):
self._require_tld("us", "unstake_asset_us")
return await self._request_margin_api(
"post", "staking/unstake", True, data=params
)
```
```python
async def get_staking_balance_us(self, **params):
self._require_tld("us", "get_staking_balance_us")
return await self._request_margin_api(
"get", "staking/stakingBalance", True, data=params
)
```
```python
async def get_staking_history_us(self, **params):
self._require_tld("us", "get_staking_history_us")
return await self._request_margin_api(
"get", "staking/history", True, data=params
)
```
```python
async def get_staking_rewards_history_us(self, **params):
self._require_tld("us", "get_staking_rewards_history_us")
return await self._request_margin_api(
"get", "staking/stakingRewardsHistory", True, data=params
)
```
```python
async def get_sub_account_list(self, **params):
return await self._request_margin_api(
"get", "sub-account/list", True, data=params
)
```
```python
async def get_sub_account_transfer_history(self, **params):
return await self._request_margin_api(
"get", "sub-account/sub/transfer/history", True, data=params
)
```
```python
async def get_sub_account_futures_transfer_history(self, **params):
return await self._request_margin_api(
"get", "sub-account/futures/internalTransfer", True, data=params
)
```
```python
async def create_sub_account_futures_transfer(self, **params):
return await self._request_margin_api(
"post", "sub-account/futures/internalTransfer", True, data=params
)
```
```python
async def get_sub_account_assets(self, **params):
return await self._request_margin_api(
"get", "sub-account/assets", True, data=params, version=4
)
```
```python
async def query_subaccount_spot_summary(self, **params):
return await self._request_margin_api(
"get", "sub-account/spotSummary", True, data=params
)
```
```python
async def get_subaccount_deposit_address(self, **params):
return await self._request_margin_api(
"get", "capital/deposit/subAddress", True, data=params
)
```
```python
async def get_subaccount_deposit_history(self, **params):
return await self._request_margin_api(
"get", "capital/deposit/subHisrec", True, data=params
)
```
```python
async def get_subaccount_futures_margin_status(self, **params):
return await self._request_margin_api(
"get", "sub-account/status", True, data=params
)
```
```python
async def enable_subaccount_margin(self, **params):
return await self._request_margin_api(
"post", "sub-account/margin/enable", True, data=params
)
```
```python
async def get_subaccount_margin_details(self, **params):
return await self._request_margin_api(
"get", "sub-account/margin/account", True, data=params
)
```
```python
async def get_subaccount_margin_summary(self, **params):
return await self._request_margin_api(
"get", "sub-account/margin/accountSummary", True, data=params
)
```
```python
async def enable_subaccount_futures(self, **params):
return await self._request_margin_api(
"post", "sub-account/futures/enable", True, data=params
)
```
```python
async def get_subaccount_futures_details(self, **params):
return await self._request_margin_api(
"get", "sub-account/futures/account", True, data=params, version=2
)
```
```python
async def get_subaccount_futures_summary(self, **params):
return await self._request_margin_api(
"get", "sub-account/futures/accountSummary", True, data=params, version=2
)
```
```python
async def get_subaccount_futures_positionrisk(self, **params):
return await self._request_margin_api(
"get", "sub-account/futures/positionRisk", True, data=params, version=2
)
```
```python
async def make_subaccount_futures_transfer(self, **params):
return await self._request_margin_api(
"post", "sub-account/futures/transfer", True, data=params
)
```
```python
async def make_subaccount_margin_transfer(self, **params):
return await self._request_margin_api(
"post", "sub-account/margin/transfer", True, data=params
)
```
```python
async def make_subaccount_to_subaccount_transfer(self, **params):
return await self._request_margin_api(
"post", "sub-account/transfer/subToSub", True, data=params
)
```
```python
async def make_subaccount_to_master_transfer(self, **params):
return await self._request_margin_api(
"post", "sub-account/transfer/subToMaster", True, data=params
)
```
```python
async def get_subaccount_transfer_history(self, **params):
return await self._request_margin_api(
"get", "sub-account/transfer/subUserHistory", True, data=params
)
```
```python
async def make_subaccount_universal_transfer(self, **params):
return await self._request_margin_api(
"post", "sub-account/universalTransfer", True, data=params
)
```
```python
async def get_universal_transfer_history(self, **params):
return await self._request_margin_api(
"get", "sub-account/universalTransfer", True, data=params
)
```
```python
async def futures_ping(self):
return await self._request_futures_api("get", "ping")
```
```python
async def futures_time(self):
return await self._request_futures_api("get", "time")
```
```python
async def futures_exchange_info(self):
return await self._request_futures_api("get", "exchangeInfo")
```
```python
async def futures_order_book(self, **params):
return await self._request_futures_api("get", "depth", data=params)
```
```python
async def futures_rpi_depth(self, **params):
return await self._request_futures_api("get", "rpiDepth", data=params)
```
```python
async def futures_recent_trades(self, **params):
return await self._request_futures_api("get", "trades", data=params)
```
```python
async def futures_historical_trades(self, **params):
return await self._request_futures_api("get", "historicalTrades", data=params)
```
```python
async def futures_aggregate_trades(self, **params):
return await self._request_futures_api("get", "aggTrades", data=params)
```
```python
async def futures_klines(self, **params):
return await self._request_futures_api("get", "klines", data=params)
```
```python
async def futures_mark_price_klines(self, **params):
return await self._request_futures_api("get", "markPriceKlines", data=params)
```
```python
async def futures_index_price_klines(self, **params):
return await self._request_futures_api("get", "indexPriceKlines", data=params)
```
```python
async def futures_premium_index_klines(self, **params):
return await self._request_futures_api("get", "premiumIndexKlines", data=params)
```
```python
async def futures_continuous_klines(self, **params):
return await self._request_futures_api("get", "continuousKlines", data=params)
```
```python
async def futures_historical_klines(
self, symbol: str, interval: str, start_str, end_str=None, limit=None
):
return await self._historical_klines(
symbol,
interval,
start_str,
end_str=end_str,
limit=limit,
klines_type=HistoricalKlinesType.FUTURES,
)
```
```python
async def futures_historical_klines_generator(
self, symbol, interval, start_str, end_str=None
):
return self._historical_klines_generator(
symbol,
interval,
start_str,
end_str=end_str,
klines_type=HistoricalKlinesType.FUTURES,
)
```
```python
async def futures_mark_price(self, **params):
return await self._request_futures_api("get", "premiumIndex", data=params)
```
```python
async def futures_funding_rate(self, **params):
return await self._request_futures_api("get", "fundingRate", data=params)
```
```python
async def futures_top_longshort_account_ratio(self, **params):
return await self._request_futures_data_api(
"get", "topLongShortAccountRatio", data=params
)
```
```python
async def futures_top_longshort_position_ratio(self, **params):
return await self._request_futures_data_api(
"get", "topLongShortPositionRatio", data=params
)
```
```python
async def futures_global_longshort_ratio(self, **params):
return await self._request_futures_data_api(
"get", "globalLongShortAccountRatio", data=params
)
```
```python
async def futures_taker_longshort_ratio(self, **params):
return await self._request_futures_data_api(
"get", "takerlongshortRatio", data=params
)
```
```python
async def futures_ticker(self, **params):
return await self._request_futures_api("get", "ticker/24hr", data=params)
```
```python
async def futures_symbol_ticker(self, **params):
return await self._request_futures_api("get", "ticker/price", version=2, data=params)
```
```python
async def futures_orderbook_ticker(self, **params):
return await self._request_futures_api("get", "ticker/bookTicker", data=params)
```
```python
async def futures_index_price_constituents(self, **params):
return await self._request_futures_api("get", "constituents", data=params)
```
```python
async def futures_liquidation_orders(self, **params):
return await self._request_futures_api(
"get", "forceOrders", signed=True, data=params
)
```
```python
async def futures_api_trading_status(self, **params):
return await self._request_futures_api(
"get", "apiTradingStatus", signed=True, data=params
)
```
```python
async def futures_commission_rate(self, **params):
return await self._request_futures_api(
"get", "commissionRate", signed=True, data=params
)
```
```python
async def futures_adl_quantile_estimate(self, **params):
return await self._request_futures_api(
"get", "adlQuantile", signed=True, data=params
)
```
```python
async def futures_open_interest(self, **params):
return await self._request_futures_api("get", "openInterest", data=params)
```
```python
async def futures_index_info(self, **params):
return await self._request_futures_api("get", "indexInfo", data=params)
```
```python
async def futures_open_interest_hist(self, **params):
return await self._request_futures_data_api(
"get", "openInterestHist", data=params
)
```
```python
async def futures_leverage_bracket(self, **params):
return await self._request_futures_api(
"get", "leverageBracket", True, data=params
)
```
```python
async def futures_account_transfer(self, **params):
return await self._request_margin_api(
"post", "futures/transfer", True, data=params
)
```
```python
async def transfer_history(self, **params):
return await self._request_margin_api(
"get", "futures/transfer", True, data=params
)
```
```python
async def futures_loan_borrow_history(self, **params):
return await self._request_margin_api(
"get", "futures/loan/borrow/history", True, data=params
)
```
```python
async def futures_loan_repay_history(self, **params):
return await self._request_margin_api(
"get", "futures/loan/repay/history", True, data=params
)
```
```python
async def futures_loan_wallet(self, **params):
return await self._request_margin_api(
"get", "futures/loan/wallet", True, data=params, version=2
)
```
```python
async def futures_cross_collateral_adjust_history(self, **params):
return await self._request_margin_api(
"get", "futures/loan/adjustCollateral/history", True, data=params
)
```
```python
async def futures_cross_collateral_liquidation_history(self, **params):
return await self._request_margin_api(
"get", "futures/loan/liquidationHistory", True, data=params
)
```
```python
async def futures_loan_interest_history(self, **params):
return await self._request_margin_api(
"get", "futures/loan/interestHistory", True, data=params
)
```
```python
async def futures_create_order(self, **params):
# Check if this is a conditional order type that needs to use algo endpoint
order_type = params.get("type", "").upper()
conditional_types = [
"STOP",
"STOP_MARKET",
"TAKE_PROFIT",
"TAKE_PROFIT_MARKET",
"TRAILING_STOP_MARKET",
]
if order_type in conditional_types:
# Route to algo order endpoint
if "clientAlgoId" not in params:
params["clientAlgoId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
# Remove newClientOrderId if it was added by default
params.pop("newClientOrderId", None)
params["algoType"] = "CONDITIONAL"
# Convert stopPrice to triggerPrice for algo orders (camelCase per API docs)
if "stopPrice" in params and "triggerPrice" not in params:
params["triggerPrice"] = params.pop("stopPrice")
return await self._request_futures_api("post", "algoOrder", True, data=params)
else:
# Use regular order endpoint
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures limit order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
async def futures_limit_order(self, **params):
"""Send in a new futures limit order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["type"] = "LIMIT"
return await self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures market order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
async def futures_market_order(self, **params):
"""Send in a new futures market order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["type"] = "MARKET"
return await self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures limit buy order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
async def futures_limit_buy_order(self, **params):
"""Send in a new futures limit buy order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["side"] = "BUY"
params["type"] = "LIMIT"
return await self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures limit sell order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
async def futures_limit_sell_order(self, **params):
"""Send in a new futures limit sell order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["side"] = "SELL"
params["type"] = "LIMIT"
return await self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures market buy order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
async def futures_market_buy_order(self, **params):
"""Send in a new futures market buy order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["side"] = "BUY"
params["type"] = "MARKET"
return await self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures market sell order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
async def futures_market_sell_order(self, **params):
"""Send in a new futures market sell order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["side"] = "SELL"
params["type"] = "MARKET"
return await self._request_futures_api("post", "order", True, data=params)
```
Modify an existing order. Currently only LIMIT order modification is supported.
[https://binance-docs.github.io/apidocs/futures/en/#modify-order-trade](https://binance-docs.github.io/apidocs/futures/en/#modify-order-trade)
```python
async def futures_modify_order(self, **params):
"""Modify an existing order. Currently only LIMIT order modification is supported.
https://binance-docs.github.io/apidocs/futures/en/#modify-order-trade
"""
return await self._request_futures_api("put", "order", True, data=params)
```
```python
async def futures_create_test_order(self, **params):
return await self._request_futures_api("post", "order/test", True, data=params)
```
```python
async def futures_place_batch_order(self, **params):
for order in params["batchOrders"]:
if "newClientOrderId" not in order:
order["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
order = self._order_params(order)
query_string = urlencode(params).replace("%40", "@").replace("%27", "%22")
params["batchOrders"] = query_string[12:]
return await self._request_futures_api(
"post", "batchOrders", True, data=params, force_params=True
)
```
```python
async def futures_get_order(self, **params):
# Check if this is a request for a conditional/algo order
is_conditional = params.pop("conditional", False)
# Also check if algoId or clientAlgoId is provided
if "algoId" in params or "clientAlgoId" in params:
is_conditional = True
if is_conditional:
return await self._request_futures_api("get", "algoOrder", True, data=params)
else:
return await self._request_futures_api("get", "order", True, data=params)
```
```python
async def futures_get_open_orders(self, **params):
is_conditional = params.pop("conditional", False)
if is_conditional:
return await self._request_futures_api("get", "openAlgoOrders", True, data=params)
else:
return await self._request_futures_api("get", "openOrders", True, data=params)
```
```python
async def futures_get_all_orders(self, **params):
is_conditional = params.pop("conditional", False)
if is_conditional:
return await self._request_futures_api("get", "allAlgoOrders", True, data=params)
else:
return await self._request_futures_api("get", "allOrders", True, data=params)
```
```python
async def futures_cancel_order(self, **params):
# Check if this is a request for a conditional/algo order
is_conditional = params.pop("conditional", False)
# Also check if algoId or clientAlgoId is provided
if "algoId" in params or "clientAlgoId" in params:
is_conditional = True
if is_conditional:
return await self._request_futures_api("delete", "algoOrder", True, data=params)
else:
return await self._request_futures_api("delete", "order", True, data=params)
```
```python
async def futures_cancel_all_open_orders(self, **params):
is_conditional = params.pop("conditional", False)
if is_conditional:
return await self._request_futures_api(
"delete", "algoOpenOrders", True, data=params
)
else:
return await self._request_futures_api(
"delete", "allOpenOrders", True, data=params
)
```
```python
async def futures_cancel_orders(self, **params):
if params.get("orderidlist"):
params["orderidlist"] = quote(
convert_list_to_json_array(params["orderidlist"])
)
if params.get("origclientorderidlist"):
params["origclientorderidlist"] = quote(
convert_list_to_json_array(params["origclientorderidlist"])
)
return await self._request_futures_api(
"delete", "batchOrders", True, data=params, force_params=True
)
```
```python
async def futures_countdown_cancel_all(self, **params):
return await self._request_futures_api(
"post", "countdownCancelAll", True, data=params
)
```
```python
async def futures_create_algo_order(self, **params):
if "clientAlgoId" not in params:
params["clientAlgoId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
if "algoType" not in params:
params["algoType"] = "CONDITIONAL"
return await self._request_futures_api("post", "algoOrder", True, data=params)
```
```python
async def futures_cancel_algo_order(self, **params):
return await self._request_futures_api("delete", "algoOrder", True, data=params)
```
```python
async def futures_cancel_all_algo_open_orders(self, **params):
return await self._request_futures_api(
"delete", "algoOpenOrders", True, data=params
)
```
```python
async def futures_get_algo_order(self, **params):
return await self._request_futures_api("get", "algoOrder", True, data=params)
```
```python
async def futures_get_open_algo_orders(self, **params):
return await self._request_futures_api("get", "openAlgoOrders", True, data=params)
```
```python
async def futures_get_all_algo_orders(self, **params):
return await self._request_futures_api("get", "allAlgoOrders", True, data=params)
```
```python
async def futures_account_balance(self, **params):
return await self._request_futures_api(
"get", "balance", True, version=3, data=params
)
```
```python
async def futures_account(self, **params):
return await self._request_futures_api(
"get", "account", True, version=2, data=params
)
```
```python
async def futures_symbol_adl_risk(self, **params):
return await self._request_futures_api("get", "symbolAdlRisk", True, data=params)
```
```python
async def futures_change_leverage(self, **params):
return await self._request_futures_api("post", "leverage", True, data=params)
```
```python
async def futures_change_margin_type(self, **params):
return await self._request_futures_api("post", "marginType", True, data=params)
```
```python
async def futures_change_position_margin(self, **params):
return await self._request_futures_api(
"post", "positionMargin", True, data=params
)
```
```python
async def futures_position_margin_history(self, **params):
return await self._request_futures_api(
"get", "positionMargin/history", True, data=params
)
```
```python
async def futures_position_information(self, **params):
return await self._request_futures_api(
"get", "positionRisk", True, version=3, data=params
)
```
```python
async def futures_account_trades(self, **params):
return await self._request_futures_api("get", "userTrades", True, data=params)
```
```python
async def futures_income_history(self, **params):
return await self._request_futures_api("get", "income", True, data=params)
```
```python
async def futures_change_position_mode(self, **params):
return await self._request_futures_api(
"post", "positionSide/dual", True, data=params
)
```
```python
async def futures_get_position_mode(self, **params):
return await self._request_futures_api(
"get", "positionSide/dual", True, data=params
)
```
```python
async def futures_change_multi_assets_mode(self, multiAssetsMargin: bool):
params = {"multiAssetsMargin": "true" if multiAssetsMargin else "false"}
return await self._request_futures_api(
"post", "multiAssetsMargin", True, data=params
)
```
```python
async def futures_get_multi_assets_mode(self):
return await self._request_futures_api(
"get", "multiAssetsMargin", True, data={}
)
```
```python
async def futures_stream_get_listen_key(self):
res = await self._request_futures_api(
"post", "listenKey", signed=False, data={}
)
return res["listenKey"]
```
```python
async def futures_stream_keepalive(self, listenKey):
params = {"listenKey": listenKey}
return await self._request_futures_api(
"put", "listenKey", signed=False, data=params
)
```
```python
async def futures_stream_close(self, listenKey):
params = {"listenKey": listenKey}
return await self._request_futures_api(
"delete", "listenKey", signed=False, data=params
)
```
```python
async def futures_account_config(self, **params):
return await self._request_futures_api(
"get", "accountConfig", signed=True, version=1, data=params
)
```
```python
async def futures_symbol_config(self, **params):
return await self._request_futures_api(
"get", "symbolConfig", signed=True, version=1, data=params
)
```
```python
async def futures_coin_ping(self):
return await self._request_futures_coin_api("get", "ping")
```
```python
async def futures_coin_time(self):
return await self._request_futures_coin_api("get", "time")
```
```python
async def futures_coin_exchange_info(self):
return await self._request_futures_coin_api("get", "exchangeInfo")
```
```python
async def futures_coin_order_book(self, **params):
return await self._request_futures_coin_api("get", "depth", data=params)
```
```python
async def futures_coin_recent_trades(self, **params):
return await self._request_futures_coin_api("get", "trades", data=params)
```
```python
async def futures_coin_historical_trades(self, **params):
return await self._request_futures_coin_api(
"get", "historicalTrades", data=params
)
```
```python
async def futures_coin_aggregate_trades(self, **params):
return await self._request_futures_coin_api("get", "aggTrades", data=params)
```
```python
async def futures_coin_klines(self, **params):
return await self._request_futures_coin_api("get", "klines", data=params)
```
```python
async def futures_coin_continous_klines(self, **params):
return await self._request_futures_coin_api(
"get", "continuousKlines", data=params
)
```
```python
async def futures_coin_index_price_klines(self, **params):
return await self._request_futures_coin_api(
"get", "indexPriceKlines", data=params
)
```
```python
async def futures_coin_mark_price_klines(self, **params):
return await self._request_futures_coin_api(
"get", "markPriceKlines", data=params
)
```
```python
async def futures_coin_premium_index_klines(self, **params):
return await self._request_futures_coin_api(
"get", "premiumIndexKlines", data=params
)
```
```python
async def futures_coin_mark_price(self, **params):
return await self._request_futures_coin_api("get", "premiumIndex", data=params)
```
```python
async def futures_coin_funding_rate(self, **params):
return await self._request_futures_coin_api("get", "fundingRate", data=params)
```
```python
async def futures_coin_ticker(self, **params):
return await self._request_futures_coin_api("get", "ticker/24hr", data=params)
```
```python
async def futures_coin_symbol_ticker(self, **params):
return await self._request_futures_coin_api("get", "ticker/price", data=params)
```
```python
async def futures_coin_orderbook_ticker(self, **params):
return await self._request_futures_coin_api(
"get", "ticker/bookTicker", data=params
)
```
```python
async def futures_coin_index_price_constituents(self, **params):
return await self._request_futures_coin_api("get", "constituents", data=params)
```
```python
async def futures_coin_liquidation_orders(self, **params):
return await self._request_futures_coin_api(
"get", "forceOrders", signed=True, data=params
)
```
```python
async def futures_coin_open_interest(self, **params):
return await self._request_futures_coin_api("get", "openInterest", data=params)
```
```python
async def futures_coin_open_interest_hist(self, **params):
return await self._request_futures_coin_data_api(
"get", "openInterestHist", data=params
)
```
```python
async def futures_coin_leverage_bracket(self, **params):
return await self._request_futures_coin_api(
"get", "leverageBracket", version=2, signed=True, data=params
)
```
```python
async def new_transfer_history(self, **params):
return await self._request_margin_api(
"get", "asset/transfer", True, data=params
)
```
```python
async def funding_wallet(self, **params):
return await self._request_margin_api(
"post", "asset/get-funding-asset", True, data=params
)
```
```python
async def get_user_asset(self, **params):
return await self._request_margin_api(
"post", "asset/getUserAsset", True, data=params, version=3
)
```
```python
async def universal_transfer(self, **params):
return await self._request_margin_api(
"post", "asset/transfer", signed=True, data=params
)
```
```python
async def futures_coin_create_order(self, **params):
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_futures_coin_api("post", "order", True, data=params)
```
```python
async def futures_coin_place_batch_order(self, **params):
for order in params["batchOrders"]:
if "newClientOrderId" not in order:
order["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
query_string = urlencode(params)
query_string = query_string.replace("%27", "%22")
params["batchOrders"] = query_string[12:]
return await self._request_futures_coin_api(
"post", "batchOrders", True, data=params
)
```
```python
async def futures_coin_get_order(self, **params):
return await self._request_futures_coin_api("get", "order", True, data=params)
```
```python
async def futures_coin_get_open_orders(self, **params):
return await self._request_futures_coin_api(
"get", "openOrders", True, data=params
)
```
```python
async def futures_coin_get_all_orders(self, **params):
return await self._request_futures_coin_api(
"get", "allOrders", signed=True, data=params
)
```
```python
async def futures_coin_cancel_order(self, **params):
return await self._request_futures_coin_api(
"delete", "order", signed=True, data=params
)
```
```python
async def futures_coin_cancel_all_open_orders(self, **params):
return await self._request_futures_coin_api(
"delete", "allOpenOrders", signed=True, data=params, force_params=True
)
```
```python
async def futures_coin_cancel_orders(self, **params):
if params.get("orderidlist"):
params["orderidlist"] = quote(
convert_list_to_json_array(params["orderidlist"])
)
if params.get("origclientorderidlist"):
params["origclientorderidlist"] = quote(
convert_list_to_json_array(params["origclientorderidlist"])
)
return await self._request_futures_coin_api(
"delete", "batchOrders", True, data=params
)
```
```python
async def futures_coin_account_balance(self, **params):
return await self._request_futures_coin_api(
"get", "balance", signed=True, data=params
)
```
```python
async def futures_coin_account(self, **params):
return await self._request_futures_coin_api(
"get", "account", signed=True, data=params
)
```
```python
async def futures_coin_change_leverage(self, **params):
return await self._request_futures_coin_api(
"post", "leverage", signed=True, data=params
)
```
```python
async def futures_coin_change_margin_type(self, **params):
return await self._request_futures_coin_api(
"post", "marginType", signed=True, data=params
)
```
```python
async def futures_coin_change_position_margin(self, **params):
return await self._request_futures_coin_api(
"post", "positionMargin", True, data=params
)
```
```python
async def futures_coin_position_margin_history(self, **params):
return await self._request_futures_coin_api(
"get", "positionMargin/history", True, data=params
)
```
```python
async def futures_coin_position_information(self, **params):
return await self._request_futures_coin_api(
"get", "positionRisk", True, data=params
)
```
```python
async def futures_coin_account_trades(self, **params):
return await self._request_futures_coin_api(
"get", "userTrades", True, data=params
)
```
```python
async def futures_coin_income_history(self, **params):
return await self._request_futures_coin_api("get", "income", True, data=params)
```
```python
async def futures_coin_change_position_mode(self, **params):
return await self._request_futures_coin_api(
"post", "positionSide/dual", True, data=params
)
```
```python
async def futures_coin_get_position_mode(self, **params):
return await self._request_futures_coin_api(
"get", "positionSide/dual", True, data=params
)
```
```python
async def futures_coin_stream_get_listen_key(self):
res = await self._request_futures_coin_api(
"post", "listenKey", signed=False, data={}
)
return res["listenKey"]
```
```python
async def futures_coin_stream_keepalive(self, listenKey):
params = {"listenKey": listenKey}
return await self._request_futures_coin_api(
"put", "listenKey", signed=False, data=params
)
```
```python
async def futures_coin_account_order_history_download(self, **params):
return await self._request_futures_coin_api(
"get", "order/asyn", True, data=params
)
```
```python
async def futures_coin_account_order_history_download_link(self, **params):
return await self._request_futures_coin_api(
"get", "order/asyn/id", True, data=params
)
```
```python
async def futures_coin_account_trade_history_download(self, **params):
return await self._request_futures_coin_api(
"get", "trade/asyn", True, data=params
)
```
```python
async def futures_coin_account_trade_history_download_link(self, **params):
return await self._request_futures_coin_api(
"get", "trade/asyn/id", True, data=params
)
```
```python
async def futures_coin_stream_close(self, listenKey):
params = {"listenKey": listenKey}
return await self._request_futures_coin_api(
"delete", "listenKey", signed=False, data=params
)
```
```python
async def get_all_coins_info(self, **params):
return await self._request_margin_api(
"get", "capital/config/getall", True, data=params
)
```
```python
async def get_account_snapshot(self, **params):
return await self._request_margin_api(
"get", "accountSnapshot", True, data=params
)
```
```python
async def disable_fast_withdraw_switch(self, **params):
return await self._request_margin_api(
"post", "disableFastWithdrawSwitch", True, data=params
)
```
```python
async def enable_fast_withdraw_switch(self, **params):
return await self._request_margin_api(
"post", "enableFastWithdrawSwitch", True, data=params
)
```
```python
async def options_ping(self):
return await self._request_options_api("get", "ping")
```
```python
async def options_time(self):
return await self._request_options_api("get", "time")
```
```python
async def options_info(self):
return await self._request_options_api("get", "optionInfo")
```
```python
async def options_exchange_info(self):
return await self._request_options_api("get", "exchangeInfo")
```
```python
async def options_index_price(self, **params):
return await self._request_options_api("get", "index", data=params)
```
```python
async def options_price(self, **params):
return await self._request_options_api("get", "ticker", data=params)
```
```python
async def options_mark_price(self, **params):
return await self._request_options_api("get", "mark", data=params)
```
```python
async def options_order_book(self, **params):
return await self._request_options_api("get", "depth", data=params)
```
```python
async def options_klines(self, **params):
return await self._request_options_api("get", "klines", data=params)
```
```python
async def options_recent_trades(self, **params):
return await self._request_options_api("get", "trades", data=params)
```
```python
async def options_historical_trades(self, **params):
return await self._request_options_api("get", "historicalTrades", data=params)
```
```python
async def options_account_info(self, **params):
return await self._request_options_api(
"get", "account", signed=True, data=params
)
```
```python
async def options_funds_transfer(self, **params):
return await self._request_options_api(
"post", "transfer", signed=True, data=params
)
```
```python
async def options_positions(self, **params):
return await self._request_options_api(
"get", "position", signed=True, data=params
)
```
```python
async def options_bill(self, **params):
return await self._request_options_api("post", "bill", signed=True, data=params)
```
```python
async def options_place_order(self, **params):
if "clientOrderId" not in params:
params["clientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_options_api(
"post", "order", signed=True, data=params
)
```
```python
async def options_place_batch_order(self, **params):
for order in params["batchOrders"]:
if "newClientOrderId" not in order:
order["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_options_api(
"post", "batchOrders", signed=True, data=params
)
```
```python
async def options_cancel_order(self, **params):
return await self._request_options_api(
"delete", "order", signed=True, data=params
)
```
```python
async def options_cancel_batch_order(self, **params):
return await self._request_options_api(
"delete", "batchOrders", signed=True, data=params
)
```
```python
async def options_cancel_all_orders(self, **params):
return await self._request_options_api(
"delete", "allOpenOrders", signed=True, data=params
)
```
```python
async def options_query_order(self, **params):
return await self._request_options_api("get", "order", signed=True, data=params)
```
```python
async def options_query_pending_orders(self, **params):
return await self._request_options_api(
"get", "openOrders", signed=True, data=params
)
```
```python
async def options_query_order_history(self, **params):
return await self._request_options_api(
"get", "historyOrders", signed=True, data=params
)
```
```python
async def options_user_trades(self, **params):
return await self._request_options_api(
"get", "userTrades", signed=True, data=params
)
```
```python
async def get_fiat_deposit_withdraw_history(self, **params):
return await self._request_margin_api(
"get", "fiat/orders", signed=True, data=params
)
```
```python
async def get_fiat_payments_history(self, **params):
return await self._request_margin_api(
"get", "fiat/payments", signed=True, data=params
)
```
```python
async def get_c2c_trade_history(self, **params):
return await self._request_margin_api(
"get", "c2c/orderMatch/listUserOrderHistory", signed=True, data=params
)
```
```python
async def get_pay_trade_history(self, **params):
return await self._request_margin_api(
"get", "pay/transactions", signed=True, data=params
)
```
```python
async def get_convert_trade_history(self, **params):
return await self._request_margin_api(
"get", "convert/tradeFlow", signed=True, data=params
)
```
```python
async def convert_request_quote(self, **params):
return await self._request_margin_api(
"post", "convert/getQuote", signed=True, data=params
)
```
```python
async def convert_accept_quote(self, **params):
return await self._request_margin_api(
"post", "convert/acceptQuote", signed=True, data=params
)
```
```python
async def papi_stream_get_listen_key(self):
res = await self._request_papi_api("post", "listenKey", signed=False, data={})
return res["listenKey"]
```
```python
async def papi_stream_keepalive(self, listenKey):
params = {"listenKey": listenKey}
return await self._request_papi_api(
"put", "listenKey", signed=False, data=params
)
```
```python
async def papi_stream_close(self, listenKey):
params = {"listenKey": listenKey}
return await self._request_papi_api(
"delete", "listenKey", signed=False, data=params
)
```
```python
async def papi_get_balance(self, **params):
return await self._request_papi_api("get", "balance", signed=True, data=params)
```
```python
async def papi_get_rate_limit(self, **params):
return await self._request_papi_api("get", "rateLimit/order", signed=True, data=params)
```
```python
async def papi_get_account(self, **params):
return await self._request_papi_api("get", "account", signed=True, data=params)
```
```python
async def papi_get_margin_max_borrowable(self, **params):
return await self._request_papi_api(
"get", "margin/maxBorrowable", signed=True, data=params
)
```
```python
async def papi_get_margin_max_withdraw(self, **params):
return await self._request_papi_api(
"get", "margin/maxWithdraw", signed=True, data=params
)
```
```python
async def papi_get_um_position_risk(self, **params):
return await self._request_papi_api(
"get", "um/positionRisk", signed=True, data=params
)
```
```python
async def papi_get_cm_position_risk(self, **params):
return await self._request_papi_api(
"get", "cm/positionRisk", signed=True, data=params
)
```
```python
async def papi_set_um_leverage(self, **params):
return await self._request_papi_api(
"post", "um/leverage", signed=True, data=params
)
```
```python
async def papi_set_cm_leverage(self, **params):
return await self._request_papi_api(
"post", "cm/leverage", signed=True, data=params
)
```
```python
async def papi_change_um_position_side_dual(self, **params):
return await self._request_papi_api(
"post", "um/positionSide/dual", signed=True, data=params
)
```
```python
async def papi_get_um_position_side_dual(self, **params):
return await self._request_papi_api(
"get", "um/positionSide/dual", signed=True, data=params
)
```
```python
async def papi_get_cm_position_side_dual(self, **params):
return await self._request_papi_api(
"get", "cm/positionSide/dual", signed=True, data=params
)
```
```python
async def papi_get_um_leverage_bracket(self, **params):
return await self._request_papi_api(
"get", "um/leverageBracket", signed=True, data=params
)
```
```python
async def papi_get_cm_leverage_bracket(self, **params):
return await self._request_papi_api(
"get", "cm/leverageBracket", signed=True, data=params
)
```
```python
async def papi_get_um_api_trading_status(self, **params):
return await self._request_papi_api(
"get", "um/apiTradingStatus", signed=True, data=params
)
```
```python
async def papi_get_um_comission_rate(self, **params):
return await self._request_papi_api(
"get", "um/commissionRate", signed=True, data=params
)
```
```python
async def papi_get_cm_comission_rate(self, **params):
return await self._request_papi_api(
"get", "cm/commissionRate", signed=True, data=params
)
```
```python
async def papi_get_margin_margin_loan(self, **params):
return await self._request_papi_api(
"get", "margin/marginLoan", signed=True, data=params
)
```
```python
async def papi_get_margin_repay_loan(self, **params):
return await self._request_papi_api(
"get", "margin/repayLoan", signed=True, data=params
)
```
```python
async def papi_get_repay_futures_switch(self, **params):
return await self._request_papi_api(
"get", "repay-futures-switch", signed=True, data=params
)
```
```python
async def papi_repay_futures_switch(self, **params):
return await self._request_papi_api(
"post", "repay-futures-switch", signed=True, data=params
)
```
```python
async def papi_get_margin_interest_history(self, **params):
return await self._request_papi_api(
"get", "margin/marginInterestHistory", signed=True, data=params
)
```
```python
async def papi_repay_futures_negative_balance(self, **params):
return await self._request_papi_api(
"post", "repay-futures-negative-balance", signed=True, data=params
)
```
```python
async def papi_get_portfolio_interest_history(self, **params):
return await self._request_papi_api(
"get", "portfolio/interest-history", signed=True, data=params
)
```
```python
async def papi_get_portfolio_negative_balance_exchange_record(self, **params):
return await self._request_papi_api(
"get", "portfolio/negative-balance-exchange-record", signed=True, data=params
)
```
```python
async def papi_fund_auto_collection(self, **params):
return await self._request_papi_api(
"post", "auto-collection", signed=True, data=params
)
```
```python
async def papi_fund_asset_collection(self, **params):
return await self._request_papi_api(
"post", "asset-collection", signed=True, data=params
)
```
```python
async def papi_bnb_transfer(self, **params):
return await self._request_papi_api(
"post", "bnb-transfer", signed=True, data=params
)
```
```python
async def papi_get_um_income_history(self, **params):
return await self._request_papi_api(
"get", "um/income", signed=True, data=params
)
```
```python
async def papi_get_cm_income_history(self, **params):
return await self._request_papi_api(
"get", "cm/income", signed=True, data=params
)
```
```python
async def papi_get_um_account(self, **params):
return await self._request_papi_api(
"get", "um/account", signed=True, data=params
)
```
```python
async def papi_get_um_account_v2(self, **params):
return await self._request_papi_api(
"get", "um/account", version=2, signed=True, data=params
)
```
```python
async def papi_get_cm_account(self, **params):
return await self._request_papi_api(
"get", "cm/account", signed=True, data=params
)
```
```python
async def papi_get_um_account_config(self, **params):
return await self._request_papi_api(
"get", "um/accountConfig", signed=True, data=params
)
```
```python
async def papi_get_um_symbol_config(self, **params):
return await self._request_papi_api(
"get", "um/symbolConfig", signed=True, data=params
)
```
```python
async def papi_get_um_trade_asyn(self, **params):
return await self._request_papi_api(
"get", "um/trade/asyn", signed=True, data=params
)
```
```python
async def papi_get_um_trade_asyn_id(self, **params):
return await self._request_papi_api(
"get", "um/trade/asyn/id", signed=True, data=params
)
```
```python
async def papi_get_um_order_asyn(self, **params):
return await self._request_papi_api(
"get", "um/order/asyn", signed=True, data=params
)
```
```python
async def papi_get_um_order_asyn_id(self, **params):
return await self._request_papi_api(
"get", "um/order/asyn/id", signed=True, data=params
)
```
```python
async def papi_get_um_income_asyn(self, **params):
return await self._request_papi_api(
"get", "um/income/asyn", signed=True, data=params
)
```
```python
async def papi_get_um_income_asyn_id(self, **params):
return await self._request_papi_api(
"get", "um/income/asyn/id", signed=True, data=params
)
```
```python
async def papi_ping(self, **params):
return await self._request_papi_api("get", "ping", signed=False, data=params)
```
Place new UM order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade](https://developers.binance.com/docs/derivatives/portfolio-margin/trade)
:returns: API response
```python
async def papi_create_um_order(self, **params):
"""Place new UM order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_papi_api(
"post", "um/order", signed=True, data=params
)
```
Place new UM Conditional order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-UM-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-UM-Conditional-Order)
:returns: API response
```python
async def papi_create_um_conditional_order(self, **params):
"""Place new UM Conditional order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-UM-Conditional-Order
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_papi_api(
"post", "um/conditional/order", signed=True, data=params
)
```
Place new CM order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Order)
:returns: API response
```python
async def papi_create_cm_order(self, **params):
"""Place new CM order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Order
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_papi_api(
"post", "cm/order", signed=True, data=params
)
```
Place new CM Conditional order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Conditional-Order)
:returns: API response
```python
async def papi_create_cm_conditional_order(self, **params):
"""Place new CM Conditional order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Conditional-Order
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_papi_api(
"post", "cm/conditional/order", signed=True, data=params
)
```
New Margin Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-Margin-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-Margin-Order)
:returns: API response
```python
async def papi_create_margin_order(self, **params):
"""New Margin Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-Margin-Order
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._request_papi_api(
"post", "margin/order", signed=True, data=params
)
```
Apply for a margin loan.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Borrow](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Borrow)
:returns: API response
```python
async def papi_margin_loan(self, **params):
"""Apply for a margin loan.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Borrow
:returns: API response
"""
return await self._request_papi_api(
"post", "marginLoan", signed=True, data=params
)
```
Repay for a margin loan.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay)
:returns: API response
```python
async def papi_repay_loan(self, **params):
"""Repay for a margin loan.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay
:returns: API response
"""
return await self._request_papi_api(
"post", "repayLoan", signed=True, data=params
)
```
Send in a new OCO for a margin account.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-New-OCO](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-New-OCO)
:returns: API response
```python
async def papi_margin_order_oco(self, **params):
"""Send in a new OCO for a margin account.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-New-OCO
:returns: API response
"""
return await self._request_papi_api(
"post", "margin/order/oco", signed=True, data=params
)
```
Cancel an active UM LIMIT order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Order)
:returns: API response
```python
async def papi_cancel_um_order(self, **params):
"""Cancel an active UM LIMIT order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Order
:returns: API response
"""
return await self._request_papi_api(
"delete", "um/order", signed=True, data=params
)
```
Cancel an active UM LIMIT order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Orders)
:returns: API response
```python
async def papi_cancel_um_all_open_orders(self, **params):
"""Cancel an active UM LIMIT order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Orders
:returns: API response
"""
return await self._request_papi_api(
"delete", "um/allOpenOrders", signed=True, data=params
)
```
Cancel UM Conditional Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Conditional-Order)
:returns: API response
```python
async def papi_cancel_um_conditional_order(self, **params):
"""Cancel UM Conditional Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Conditional-Order
:returns: API response
"""
return await self._request_papi_api(
"delete", "um/conditional/order", signed=True, data=params
)
```
Cancel All UM Open Conditional Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Conditional-Orders)
:returns: API response
```python
async def papi_cancel_um_conditional_all_open_orders(self, **params):
"""Cancel All UM Open Conditional Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Conditional-Orders
:returns: API response
"""
return await self._request_papi_api(
"delete", "um/conditional/allOpenOrders", signed=True, data=params
)
```
Cancel an active CM LIMIT order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Order)
:returns: API response
```python
async def papi_cancel_cm_order(self, **params):
"""Cancel an active CM LIMIT order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Order
:returns: API response
"""
return await self._request_papi_api(
"delete", "cm/order", signed=True, data=params
)
```
Cancel an active CM LIMIT order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Orders)
:returns: API response
```python
async def papi_cancel_cm_all_open_orders(self, **params):
"""Cancel an active CM LIMIT order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Orders
:returns: API response
"""
return await self._request_papi_api(
"delete", "cm/allOpenOrders", signed=True, data=params
)
```
Cancel CM Conditional Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Conditional-Order)
:returns: API response
```python
async def papi_cancel_cm_conditional_order(self, **params):
"""Cancel CM Conditional Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Conditional-Order
:returns: API response
"""
return await self._request_papi_api(
"delete", "cm/conditional/order", signed=True, data=params
)
```
Cancel All CM Open Conditional Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Conditional-Orders)
:returns: API response
```python
async def papi_cancel_cm_conditional_all_open_orders(self, **params):
"""Cancel All CM Open Conditional Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Conditional-Orders
:returns: API response
"""
return await self._request_papi_api(
"delete", "cm/conditional/allOpenOrders", signed=True, data=params
)
```
Cancel Margin Account Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-Order)
:returns: API response
```python
async def papi_cancel_margin_order(self, **params):
"""Cancel Margin Account Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-Order
:returns: API response
"""
return await self._request_papi_api(
"delete", "margin/order", signed=True, data=params
)
```
Cancel Margin Account OCO Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-OCO-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-OCO-Orders)
:returns: API response
```python
async def papi_cancel_margin_order_list(self, **params):
"""Cancel Margin Account OCO Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-OCO-Orders
:returns: API response
"""
return await self._request_papi_api(
"delete", "margin/orderList", signed=True, data=params
)
```
Cancel Margin Account All Open Orders on a Symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-All-Open-Orders-on-a-Symbol](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-All-Open-Orders-on-a-Symbol)
:returns: API response
```python
async def papi_cancel_margin_all_open_orders(self, **params):
"""Cancel Margin Account All Open Orders on a Symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-All-Open-Orders-on-a-Symbol
:returns: API response
"""
return await self._request_papi_api(
"delete", "margin/allOpenOrders", signed=True, data=params
)
```
Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-UM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-UM-Order)
:returns: API response
```python
async def papi_modify_um_order(self, **params):
"""Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-UM-Order
:returns: API response
"""
return await self._request_papi_api("put", "um/order", signed=True, data=params)
```
Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-CM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-CM-Order)
:returns: API response
```python
async def papi_modify_cm_order(self, **params):
"""Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-CM-Order
:returns: API response
"""
return await self._request_papi_api("put", "cm/order", signed=True, data=params)
```
Check an UM order's status.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order)
:returns: API response
```python
async def papi_get_um_order(self, **params):
"""Check an UM order's status.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order
:returns: API response
"""
return await self._request_papi_api("get", "um/order", signed=True, data=params)
```
Get all account UM orders; active, canceled, or filled.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order)
:returns: API response
```python
async def papi_get_um_all_orders(self, **params):
"""Get all account UM orders; active, canceled, or filled.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order
:returns: API response
"""
return await self._request_papi_api(
"get", "um/allOrders", signed=True, data=params
)
```
Query current UM open order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Order)
:returns: API response
```python
async def papi_get_um_open_order(self, **params):
"""Query current UM open order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Order
:returns: API response
"""
return await self._request_papi_api(
"get", "um/openOrder", signed=True, data=params
)
```
Get all open orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders)
:returns: API response
```python
async def papi_get_um_open_orders(self, **params):
"""Get all open orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "um/openOrders", signed=True, data=params
)
```
Query All UM Conditional Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Conditional-Orders)
:returns: API response
```python
async def papi_get_um_conditional_all_orders(self, **params):
"""Query All UM Conditional Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Conditional-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "um/conditional/allOrders", signed=True, data=params
)
```
Get all open conditional orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Conditional-Orders)
:returns: API response
```python
async def papi_get_um_conditional_open_orders(self, **params):
"""Get all open conditional orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Conditional-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "um/conditional/openOrders", signed=True, data=params
)
```
Query Current UM Open Conditional Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Conditional-Order)
:returns: API response
```python
async def papi_get_um_conditional_open_order(self, **params):
"""Query Current UM Open Conditional Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Conditional-Order
:returns: API response
"""
return await self._request_papi_api(
"get", "um/conditional/openOrder", signed=True, data=params
)
```
Get all open conditional orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Conditional-Order-History](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Conditional-Order-History)
:returns: API response
```python
async def papi_get_um_conditional_order_history(self, **params):
"""Get all open conditional orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Conditional-Order-History
:returns: API response
"""
return await self._request_papi_api(
"get", "um/conditional/orderHistory", signed=True, data=params
)
```
Check an CM order's status.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order)
:returns: API response
```python
async def papi_get_cm_order(self, **params):
"""Check an CM order's status.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order
:returns: API response
"""
return await self._request_papi_api("get", "cm/order", signed=True, data=params)
```
Get all account CM orders; active, canceled, or filled.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order)
:returns: API response
```python
async def papi_get_cm_all_orders(self, **params):
"""Get all account CM orders; active, canceled, or filled.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/allOrders", signed=True, data=params
)
```
Query current CM open order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Order)
:returns: API response
```python
async def papi_get_cm_open_order(self, **params):
"""Query current CM open order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Order
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/openOrder", signed=True, data=params
)
```
Get all open orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Orders)
:returns: API response
```python
async def papi_get_cm_open_orders(self, **params):
"""Get all open orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/openOrders", signed=True, data=params
)
```
Query All CM Conditional Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Conditional-Orders)
:returns: API response
```python
async def papi_get_cm_conditional_all_orders(self, **params):
"""Query All CM Conditional Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Conditional-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/conditional/allOrders", signed=True, data=params
)
```
Get all open conditional orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Conditional-Orders)
:returns: API response
```python
async def papi_get_cm_conditional_open_orders(self, **params):
"""Get all open conditional orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Conditional-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/conditional/openOrders", signed=True, data=params
)
```
Query Current UM Open Conditional Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Conditional-Order)
:returns: API response
```python
async def papi_get_cm_conditional_open_order(self, **params):
"""Query Current UM Open Conditional Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Conditional-Order
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/conditional/openOrder", signed=True, data=params
)
```
Get all open conditional orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Conditional-Order-History](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Conditional-Order-History)
:returns: API response
```python
async def papi_get_cm_conditional_order_history(self, **params):
"""Get all open conditional orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Conditional-Order-History
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/conditional/orderHistory", signed=True, data=params
)
```
Query User's UM Force Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-UM-Force-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-UM-Force-Orders)
:returns: API response
```python
async def papi_get_um_force_orders(self, **params):
"""Query User's UM Force Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-UM-Force-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "um/forceOrders", signed=True, data=params
)
```
Query User's CM Force Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-CM-Force-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-CM-Force-Orders)
:returns: API response
```python
async def papi_get_cm_force_orders(self, **params):
"""Query User's CM Force Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-CM-Force-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/forceOrders", signed=True, data=params
)
```
Get order modification history.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Modify-Order-History](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Modify-Order-History)
:returns: API response
```python
async def papi_get_um_order_amendment(self, **params):
"""Get order modification history.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Modify-Order-History
:returns: API response
"""
return await self._request_papi_api(
"get", "um/orderAmendment", signed=True, data=params
)
```
Get order modification history.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Modify-Order-History](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Modify-Order-History)
:returns: API response
```python
async def papi_get_cm_order_amendment(self, **params):
"""Get order modification history.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Modify-Order-History
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/orderAmendment", signed=True, data=params
)
```
Query user's margin force orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-Margin-Force-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-Margin-Force-Orders)
:returns: API response
```python
async def papi_get_margin_force_orders(self, **params):
"""Query user's margin force orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-Margin-Force-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "margin/forceOrders", signed=True, data=params
)
```
Get trades for a specific account and UM symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Account-Trade-List](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Account-Trade-List)
:returns: API response
```python
async def papi_get_um_user_trades(self, **params):
"""Get trades for a specific account and UM symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Account-Trade-List
:returns: API response
"""
return await self._request_papi_api(
"get", "um/userTrades", signed=True, data=params
)
```
Get trades for a specific account and CM symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Account-Trade-List](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Account-Trade-List)
:returns: API response
```python
async def papi_get_cm_user_trades(self, **params):
"""Get trades for a specific account and CM symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Account-Trade-List
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/userTrades", signed=True, data=params
)
```
Query UM Position ADL Quantile Estimation.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Position-ADL-Quantile-Estimation](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Position-ADL-Quantile-Estimation)
:returns: API response
```python
async def papi_get_um_adl_quantile(self, **params):
"""Query UM Position ADL Quantile Estimation.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Position-ADL-Quantile-Estimation
:returns: API response
"""
return await self._request_papi_api(
"get", "um/adlQuantile", signed=True, data=params
)
```
Query CM Position ADL Quantile Estimation.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Position-ADL-Quantile-Estimation](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Position-ADL-Quantile-Estimation)
:returns: API response
```python
async def papi_get_cm_adl_quantile(self, **params):
"""Query CM Position ADL Quantile Estimation.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Position-ADL-Quantile-Estimation
:returns: API response
"""
return await self._request_papi_api(
"get", "cm/adlQuantile", signed=True, data=params
)
```
Change user's BNB Fee Discount for UM Futures (Fee Discount On or Fee Discount Off ) on EVERY symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Toggle-BNB-Burn-On-UM-Futures-Trade](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Toggle-BNB-Burn-On-UM-Futures-Trade)
:returns: API response
```python
async def papi_set_um_fee_burn(self, **params):
"""Change user's BNB Fee Discount for UM Futures (Fee Discount On or Fee Discount Off ) on EVERY symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Toggle-BNB-Burn-On-UM-Futures-Trade
:returns: API response
"""
return await self._request_papi_api(
"post", "um/feeBurn", signed=True, data=params
)
```
Get user's BNB Fee Discount for UM Futures (Fee Discount On or Fee Discount Off).
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Get-UM-Futures-BNB-Burn-Status](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Get-UM-Futures-BNB-Burn-Status)
:returns: API response
```python
async def papi_get_um_fee_burn(self, **params):
"""Get user's BNB Fee Discount for UM Futures (Fee Discount On or Fee Discount Off).
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Get-UM-Futures-BNB-Burn-Status
:returns: API response
"""
return await self._request_papi_api(
"get", "um/feeBurn", signed=True, data=params
)
```
Query Margin Account Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Order)
:returns: API response
```python
async def papi_get_margin_order(self, **params):
"""Query Margin Account Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Order
:returns: API response
"""
return await self._request_papi_api(
"get", "margin/order", signed=True, data=params
)
```
Query Current Margin Open Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Order)
:returns: API response
```python
async def papi_get_margin_open_orders(self, **params):
"""Query Current Margin Open Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Order
:returns: API response
"""
return await self._request_papi_api(
"get", "margin/openOrders", signed=True, data=params
)
```
Query All Margin Account Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Margin-Account-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Margin-Account-Orders)
:returns: API response
```python
async def papi_get_margin_all_orders(self, **params):
"""Query All Margin Account Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Margin-Account-Orders
:returns: API response
"""
return await self._request_papi_api(
"get", "margin/allOrders", signed=True, data=params
)
```
Retrieves a specific OCO based on provided optional parameters.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-OCO](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-OCO)
:returns: API response
```python
async def papi_get_margin_order_list(self, **params):
"""Retrieves a specific OCO based on provided optional parameters.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-OCO
:returns: API response
"""
return await self._request_papi_api(
"get", "margin/orderList", signed=True, data=params
)
```
Query all OCO for a specific margin account based on provided optional parameters.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-all-OCO](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-all-OCO)
:returns: API response
```python
async def papi_get_margin_all_order_list(self, **params):
"""Query all OCO for a specific margin account based on provided optional parameters.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-all-OCO
:returns: API response
"""
return await self._request_papi_api(
"get", "margin/allOrderList", signed=True, data=params
)
```
Query Margin Account's Open OCO.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Open-OCO](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Open-OCO)
:returns: API response
```python
async def papi_get_margin_open_order_list(self, **params):
"""Query Margin Account's Open OCO.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Open-OCO
:returns: API response
"""
return await self._request_papi_api(
"get", "margin/openOrderList", signed=True, data=params
)
```
Margin Account Trade List.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Trade-List](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Trade-List)
:returns: API response
```python
async def papi_get_margin_my_trades(self, **params):
"""Margin Account Trade List.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Trade-List
:returns: API response
"""
return await self._request_papi_api(
"get", "margin/myTrades", signed=True, data=params
)
```
Repay debt for a margin loan.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Trade-List](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Trade-List)
:returns: API response
```python
async def papi_get_margin_repay_debt(self, **params):
"""Repay debt for a margin loan.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Trade-List
:returns: API response
"""
return await self._request_papi_api(
"post", "margin/repay-debt", signed=True, data=params
)
```
```python
async def create_oco_order(self, **params):
if "listClientOrderId" not in params:
params["listClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return await self._post("orderList/oco", True, data=params)
```
Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.
[https://binance-docs.github.io/apidocs/websocket\_api/en/#test-new-order-trade](https://binance-docs.github.io/apidocs/websocket_api/en/#test-new-order-trade)
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param type: required
:type type: str
:param timeInForce: required if limit order
:type timeInForce: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: The number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
.. code-block:: python
\{}
```python
async def ws_create_test_order(self, **params):
"""Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.
https://binance-docs.github.io/apidocs/websocket_api/en/#test-new-order-trade
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param type: required
:type type: str
:param timeInForce: required if limit order
:type timeInForce: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: The number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
.. code-block:: python
{}
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return await self._ws_api_request("order.test", True, params)
```
Create an order via WebSocket.
[https://binance-docs.github.io/apidocs/websocket\_api/en/#place-new-order-trade](https://binance-docs.github.io/apidocs/websocket_api/en/#place-new-order-trade)
:param id: The request ID to be used. By default uuid22() is used.
:param symbol: The symbol to create an order for
:param side: BUY or SELL
:param type: Order type (e.g., LIMIT, MARKET)
:param quantity: The amount to buy or sell
:param kwargs: Additional order parameters
```python
async def ws_create_order(self, **params):
"""Create an order via WebSocket.
https://binance-docs.github.io/apidocs/websocket_api/en/#place-new-order-trade
:param id: The request ID to be used. By default uuid22() is used.
:param symbol: The symbol to create an order for
:param side: BUY or SELL
:param type: Order type (e.g., LIMIT, MARKET)
:param quantity: The amount to buy or sell
:param kwargs: Additional order parameters
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return await self._ws_api_request("order.place", True, params)
```
Send in a new limit order
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP\_LOSS\_LIMIT, and TAKE\_PROFIT\_LIMIT to create an iceberg order.
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
async def ws_order_limit(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
"""Send in a new limit order
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({
"type": self.ORDER_TYPE_LIMIT,
"timeInForce": timeInForce,
})
return await self.ws_create_order(**params)
```
Send in a new limit buy order
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
async def ws_order_limit_buy(
self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params
):
"""Send in a new limit buy order
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({
"side": self.SIDE_BUY,
})
return await self.ws_order_limit(timeInForce=timeInForce, **params)
```
Send in a new limit sell order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
async def ws_order_limit_sell(
self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params
):
"""Send in a new limit sell order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({"side": self.SIDE_SELL})
return await self.ws_order_limit(timeInForce=timeInForce, **params)
```
Send in a new market order
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: amount the user wants to spend (when buying) or receive (when selling)
of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
async def ws_order_market(self, **params):
"""Send in a new market order
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: amount the user wants to spend (when buying) or receive (when selling)
of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({"type": self.ORDER_TYPE_MARKET})
return await self.ws_create_order(**params)
```
Send in a new market buy order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to spend of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
async def ws_order_market_buy(self, **params):
"""Send in a new market buy order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to spend of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({"side": self.SIDE_BUY})
return await self.ws_order_market(**params)
```
Send in a new market sell order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to receive of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
async def ws_order_market_sell(self, **params):
"""Send in a new market sell order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to receive of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({"side": self.SIDE_SELL})
return await self.ws_order_market(**params)
```
Check an order's status. Either orderId or origClientOrderId must be sent.
[https://binance-docs.github.io/apidocs/websocket\_api/en/#query-order-user\_data](https://binance-docs.github.io/apidocs/websocket_api/en/#query-order-user_data)
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param origClientOrderId: optional
:type origClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
```python
async def ws_get_order(self, **params):
"""Check an order's status. Either orderId or origClientOrderId must be sent.
https://binance-docs.github.io/apidocs/websocket_api/en/#query-order-user_data
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param origClientOrderId: optional
:type origClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
"""
return await self._ws_api_request("order.status", True, params)
```
```python
async def ws_cancel_order(self, **params):
return await self._ws_api_request("order.cancel", True, params)
```
```python
async def cancel_all_open_orders(self, **params):
return await self._delete("openOrders", True, data=params)
```
```python
async def cancel_replace_order(self, **params):
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return await self._post("order/cancelReplace", signed=True, data=params)
```
```python
async def ws_cancel_and_replace_order(self, **params):
return await self._ws_api_request("order.cancelReplace", True, params)
```
```python
async def ws_get_open_orders(self, **params):
return await self._ws_api_request("openOrders.status", True, params)
```
```python
async def ws_cancel_all_open_orders(self, **params):
return await self._ws_api_request("openOrders.cancelAll", True, params)
```
```python
async def ws_create_oco_order(self, **params):
return await self._ws_api_request("orderList.place.oco", True, params)
```
```python
async def ws_create_oto_order(self, **params):
return await self._ws_api_request("orderList.place.oto", True, params)
```
```python
async def ws_create_otoco_order(self, **params):
return await self._ws_api_request("orderList.place.otoco", True, params)
```
```python
async def ws_get_oco_order(self, **params):
return await self._ws_api_request("orderList.status", True, params)
```
```python
async def ws_cancel_oco_order(self, **params):
return await self._ws_api_request("orderList.cancel", True, params)
```
```python
async def ws_get_oco_open_orders(self, **params):
return await self._ws_api_request("openOrderLists.status", True, params)
```
```python
async def ws_create_sor_order(self, **params):
return await self._ws_api_request("sor.order.place", True, params)
```
```python
async def ws_create_test_sor_order(self, **params):
return await self._ws_api_request("sor.order.test", True, params)
```
```python
async def ws_get_account(self, **params):
return await self._ws_api_request("account.status", True, params)
```
```python
async def ws_get_account_rate_limits_orders(self, **params):
return await self._ws_api_request("account.rateLimits.orders", True, params)
```
```python
async def ws_get_all_orders(self, **params):
return await self._ws_api_request("allOrders", True, params)
```
```python
async def ws_get_my_trades(self, **params):
return await self._ws_api_request("myTrades", True, params)
```
```python
async def ws_get_prevented_matches(self, **params):
return await self._ws_api_request("myPreventedMatches", True, params)
```
```python
async def ws_get_allocations(self, **params):
return await self._ws_api_request("myAllocations", True, params)
```
```python
async def ws_get_commission_rates(self, **params):
return await self._ws_api_request("account.commission", True, params)
```
```python
async def ws_get_order_book(self, **params):
return await self._ws_api_request("depth", False, params)
```
```python
async def ws_get_recent_trades(self, **params):
return await self._ws_api_request("trades.recent", False, params)
```
```python
async def ws_get_historical_trades(self, **params):
return await self._ws_api_request("trades.historical", False, params)
```
```python
async def ws_get_aggregate_trades(self, **params):
return await self._ws_api_request("trades.aggregate", False, params)
```
```python
async def ws_get_klines(self, **params):
return await self._ws_api_request("klines", False, params)
```
```python
async def ws_get_uiKlines(self, **params):
return await self._ws_api_request("uiKlines", False, params)
```
```python
async def ws_get_avg_price(self, **params):
return await self._ws_api_request("avgPrice", False, params)
```
```python
async def ws_get_ticker(self, **params):
return await self._ws_api_request("ticker.24hr", False, params)
```
```python
async def ws_get_trading_day_ticker(self, **params):
return await self._ws_api_request("ticker.tradingDay", False, params)
```
```python
async def ws_get_symbol_ticker_window(self, **params):
return await self._ws_api_request("ticker", False, params)
```
```python
async def ws_get_symbol_ticker(self, **params):
return await self._ws_api_request("ticker.price", False, params)
```
```python
async def ws_get_orderbook_ticker(self, **params):
return await self._ws_api_request("ticker.book", False, params)
```
```python
async def ws_ping(self, **params):
return await self._ws_api_request("ping", False, params)
```
```python
async def ws_get_time(self, **params):
return await self._ws_api_request("time", False, params)
```
```python
async def ws_get_exchange_info(self, **params):
return await self._ws_api_request("exchangeInfo", False, params)
```
Get the order book for a symbol
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api)
```python
async def ws_futures_get_order_book(self, **params):
"""
Get the order book for a symbol
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api
"""
return await self._ws_futures_api_request("depth", False, params)
```
Latest price for a symbol or symbols
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Price-Ticker](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Price-Ticker)
```python
async def ws_futures_get_all_tickers(self, **params):
"""
Latest price for a symbol or symbols
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Price-Ticker
"""
return await self._ws_futures_api_request("ticker.price", False, params)
```
Best price/qty on the order book for a symbol or symbols.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Order-Book-Ticker](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Order-Book-Ticker)
```python
async def ws_futures_get_order_book_ticker(self, **params):
"""
Best price/qty on the order book for a symbol or symbols.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Order-Book-Ticker
"""
return await self._ws_futures_api_request("ticker.book", False, params)
```
Send in a new order
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api)
```python
async def ws_futures_create_order(self, **params):
"""
Send in a new order
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api
"""
# Check if this is a conditional order type that needs to use algo endpoint
order_type = params.get("type", "").upper()
conditional_types = [
"STOP",
"STOP_MARKET",
"TAKE_PROFIT",
"TAKE_PROFIT_MARKET",
"TRAILING_STOP_MARKET",
]
if order_type in conditional_types:
# Route to algo order endpoint
if "clientAlgoId" not in params:
params["clientAlgoId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
# Remove newClientOrderId if it was added by default
params.pop("newClientOrderId", None)
if "algoType" not in params:
params["algoType"] = "CONDITIONAL"
# Convert stopPrice to triggerPrice for algo orders
if "stopPrice" in params and "triggerPrice" not in params:
params["triggerPrice"] = params.pop("stopPrice")
return await self._ws_futures_api_request("algoOrder.place", True, params)
else:
# Use regular order endpoint
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._ws_futures_api_request("order.place", True, params)
```
Edit an order
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Modify-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Modify-Order)
```python
async def ws_futures_edit_order(self, **params):
"""
Edit an order
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Modify-Order
"""
return await self._ws_futures_api_request("order.modify", True, params)
```
cancel an order
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order)
```python
async def ws_futures_cancel_order(self, **params):
"""
cancel an order
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order
"""
is_conditional = False
if "algoId" in params or "clientAlgoId" in params:
is_conditional = True
if is_conditional:
return await self._ws_futures_api_request("algoOrder.cancel", True, params)
else:
return await self._ws_futures_api_request("order.cancel", True, params)
```
Get an order
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Query-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Query-Order)
Note: Algo/conditional orders cannot be queried via websocket API
```python
async def ws_futures_get_order(self, **params):
"""
Get an order
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Query-Order
Note: Algo/conditional orders cannot be queried via websocket API
"""
return await self._ws_futures_api_request("order.status", True, params)
```
Get current position information(only symbol that has position or open orders will be return awaited).
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Info-V2](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Info-V2)
```python
async def ws_futures_v2_account_position(self, **params):
"""
Get current position information(only symbol that has position or open orders will be return awaited).
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Info-V2
"""
return await self._ws_futures_api_request("v2/account.position", True, params)
```
Get current position information.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Information](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Information)
```python
async def ws_futures_account_position(self, **params):
"""
Get current position information.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Information
"""
return await self._ws_futures_api_request("account.position", True, params)
```
Get current account information.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api#api-description](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api#api-description)
```python
async def ws_futures_v2_account_balance(self, **params):
"""
Get current account information.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api#api-description
"""
return await self._ws_futures_api_request("v2/account.balance", True, params)
```
Get current account information.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Futures-Account-Balance](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Futures-Account-Balance)
```python
async def ws_futures_account_balance(self, **params):
"""
Get current account information.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Futures-Account-Balance
"""
return await self._ws_futures_api_request("account.balance", True, params)
```
Get current account information. User in single-asset/ multi-assets mode will see different value, see comments in response section for detail.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information-V2](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information-V2)
```python
async def ws_futures_v2_account_status(self, **params):
"""
Get current account information. User in single-asset/ multi-assets mode will see different value, see comments in response section for detail.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information-V2
"""
return await self._ws_futures_api_request("v2/account.status", True, params)
```
Get current account information. User in single-asset/ multi-assets mode will see different value, see comments in response section for detail.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information)
```python
async def ws_futures_account_status(self, **params):
"""
Get current account information. User in single-asset/ multi-assets mode will see different value, see comments in response section for detail.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information
"""
return await self._ws_futures_api_request("account.status", True, params)
```
```python
async def ws_futures_create_algo_order(self, **params):
if "clientAlgoId" not in params:
params["clientAlgoId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return await self._ws_futures_api_request("algoOrder.place", True, params)
```
```python
async def ws_futures_cancel_algo_order(self, **params):
return await self._ws_futures_api_request("algoOrder.cancel", True, params)
```
```python
async def gift_card_fetch_token_limit(self, **params):
return await self._request_margin_api(
"get", "giftcard/buyCode/token-limit", signed=True, data=params
)
```
```python
async def gift_card_fetch_rsa_public_key(self, **params):
return await self._request_margin_api(
"get", "giftcard/cryptography/rsa-public-key", signed=True, data=params
)
```
```python
async def gift_card_verify(self, **params):
return await self._request_margin_api(
"get", "giftcard/verify", signed=True, data=params
)
```
```python
async def gift_card_redeem(self, **params):
return await self._request_margin_api(
"post", "giftcard/redeemCode", signed=True, data=params
)
```
```python
async def gift_card_create(self, **params):
return await self._request_margin_api(
"post", "giftcard/createCode", signed=True, data=params
)
```
```python
async def gift_card_create_dual_token(self, **params):
return await self._request_margin_api(
"post", "giftcard/buyCode", signed=True, data=params
)
```
```python
async def options_create_block_trade_order(self, **params):
return await self._request_options_api(
"post", "block/order/create", signed=True, data=params
)
```
```python
async def options_cancel_block_trade_order(self, **params):
return await self._request_options_api(
"delete", "block/order/create", signed=True, data=params
)
```
```python
async def options_extend_block_trade_order(self, **params):
return await self._request_options_api(
"put", "block/order/create", signed=True, data=params
)
```
```python
async def options_get_block_trade_orders(self, **params):
return await self._request_options_api(
"get", "block/order/orders", signed=True, data=params
)
```
```python
async def options_accept_block_trade_order(self, **params):
return await self._request_options_api(
"post", "block/order/execute", signed=True, data=params
)
```
```python
async def options_get_block_trade_order(self, **params):
return await self._request_options_api(
"get", "block/order/execute", signed=True, data=params
)
```
```python
async def options_account_get_block_trades(self, **params):
return await self._request_options_api(
"get", "block/user-trades", signed=True, data=params
)
```
```python
async def margin_next_hourly_interest_rate(self, **params):
return await self._request_margin_api(
"get", "margin/next-hourly-interest-rate", signed=True, data=params
)
```
```python
async def margin_interest_history(self, **params):
return await self._request_margin_api(
"get", "margin/interestHistory", signed=True, data=params
)
```
```python
async def margin_borrow_repay(self, **params):
return await self._request_margin_api(
"post", "margin/borrow-repay", signed=True, data=params
)
```
```python
async def margin_get_borrow_repay_records(self, **params):
return await self._request_margin_api(
"get", "margin/borrow-repay", signed=True, data=params
)
```
```python
async def margin_interest_rate_history(self, **params):
return await self._request_margin_api(
"get", "margin/interestRateHistory", signed=True, data=params
)
```
```python
async def margin_max_borrowable(self, **params):
return await self._request_margin_api(
"get", "margin/maxBorrowable", signed=True, data=params
)
```
```python
async def futures_historical_data_link(self, **params):
return await self._request_margin_api("get", "futures/data/histDataLink", signed=True, data=params)
```
```python
async def margin_v1_get_loan_vip_ongoing_orders(self, **params):
return await self._request_margin_api("get", "loan/vip/ongoing/orders", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_mining_payment_other(self, **params):
return await self._request_margin_api("get", "mining/payment/other", signed=True, data=params, version=1)
```
```python
async def futures_coin_v1_get_income_asyn_id(self, **params):
return await self._request_futures_coin_api("get", "income/asyn/id", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_simple_earn_flexible_history_subscription_record(self, **params):
return await self._request_margin_api("get", "simple-earn/flexible/history/subscriptionRecord", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_lending_auto_invest_one_off(self, **params):
return await self._request_margin_api("post", "lending/auto-invest/one-off", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_api_commission_coin_futures(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi/commission/coinFutures", signed=True, data=params, version=1)
```
```python
async def v3_post_order_list_otoco(self, **params):
return await self._request_api("post", "orderList/otoco", signed=True, data=params, version="v3")
```
```python
async def futures_v1_get_order_asyn(self, **params):
return await self._request_futures_api("get", "order/asyn", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_asset_custody_transfer_history(self, **params):
return await self._request_margin_api("get", "asset/custody/transfer-history", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_blvt(self, **params):
return await self._request_margin_api("post", "broker/subAccount/blvt", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_sol_staking_sol_redeem(self, **params):
return await self._request_margin_api("post", "sol-staking/sol/redeem", signed=True, data=params, version=1)
```
```python
async def options_v1_get_countdown_cancel_all(self, **params):
return await self._request_options_api("get", "countdownCancelAll", signed=True, data=params)
```
```python
async def margin_v1_get_margin_trade_coeff(self, **params):
return await self._request_margin_api("get", "margin/tradeCoeff", signed=True, data=params, version=1)
```
```python
async def futures_coin_v1_get_order_amendment(self, **params):
return await self._request_futures_coin_api("get", "orderAmendment", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_margin_available_inventory(self, **params):
return await self._request_margin_api("get", "margin/available-inventory", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_account_api_restrictions_ip_restriction_ip_list(self, **params):
return await self._request_margin_api("post", "account/apiRestrictions/ipRestriction/ipList", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_eth_staking_account(self, **params):
return await self._request_margin_api("get", "eth-staking/account", signed=True, data=params, version=2)
```
```python
async def margin_v1_get_loan_income(self, **params):
return await self._request_margin_api("get", "loan/income", signed=True, data=params, version=1)
```
```python
async def futures_coin_v1_get_pm_account_info(self, **params):
return await self._request_futures_coin_api("get", "pmAccountInfo", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_managed_subaccount_query_trans_log_for_investor(self, **params):
return await self._request_margin_api("get", "managed-subaccount/queryTransLogForInvestor", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_dci_product_auto_compound_edit_status(self, **params):
return await self._request_margin_api("post", "dci/product/auto_compound/edit-status", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_trade_asyn(self, **params):
return await self._request_futures_api("get", "trade/asyn", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_loan_vip_request_interest_rate(self, **params):
return await self._request_margin_api("get", "loan/vip/request/interestRate", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_funding_info(self, **params):
return await self._request_futures_api("get", "fundingInfo", signed=False, data=params, version=1)
```
```python
async def v3_get_all_orders(self, **params):
return await self._request_api("get", "allOrders", signed=True, data=params, version="v3")
```
```python
async def margin_v2_get_loan_flexible_repay_rate(self, **params):
return await self._request_margin_api("get", "loan/flexible/repay/rate", signed=True, data=params, version=2)
```
```python
async def margin_v1_get_lending_auto_invest_plan_id(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/plan/id", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_loan_adjust_ltv(self, **params):
return await self._request_margin_api("post", "loan/adjust/ltv", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_mining_statistics_user_status(self, **params):
return await self._request_margin_api("get", "mining/statistics/user/status", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_transfer_futures(self, **params):
return await self._request_margin_api("get", "broker/transfer/futures", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_algo_spot_new_order_twap(self, **params):
return await self._request_margin_api("post", "algo/spot/newOrderTwap", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_lending_auto_invest_target_asset_list(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/target-asset/list", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_capital_deposit_address_list(self, **params):
return await self._request_margin_api("get", "capital/deposit/address/list", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_bnb_burn_margin_interest(self, **params):
return await self._request_margin_api("post", "broker/subAccount/bnbBurn/marginInterest", signed=True, data=params, version=1)
```
```python
async def margin_v2_post_loan_flexible_repay(self, **params):
return await self._request_margin_api("post", "loan/flexible/repay", signed=True, data=params, version=2)
```
```python
async def margin_v2_get_loan_flexible_loanable_data(self, **params):
return await self._request_margin_api("get", "loan/flexible/loanable/data", signed=True, data=params, version=2)
```
```python
async def margin_v1_post_broker_sub_account_api_permission(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi/permission", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_api(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_dci_product_positions(self, **params):
return await self._request_margin_api("get", "dci/product/positions", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_convert_limit_cancel_order(self, **params):
return await self._request_margin_api("post", "convert/limit/cancelOrder", signed=True, data=params, version=1)
```
```python
async def v3_post_order_list_oto(self, **params):
return await self._request_api("post", "orderList/oto", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_mining_hash_transfer_config_details_list(self, **params):
return await self._request_margin_api("get", "mining/hash-transfer/config/details/list", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_mining_hash_transfer_profit_details(self, **params):
return await self._request_margin_api("get", "mining/hash-transfer/profit/details", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_sub_account(self, **params):
return await self._request_margin_api("get", "broker/subAccount", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_portfolio_balance(self, **params):
return await self._request_margin_api("get", "portfolio/balance", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_sub_account_eoptions_enable(self, **params):
return await self._request_margin_api("post", "sub-account/eoptions/enable", signed=True, data=params, version=1)
```
```python
async def papi_v1_post_ping(self, **params):
return await self._request_papi_api("post", "ping", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_loan_loanable_data(self, **params):
return await self._request_margin_api("get", "loan/loanable/data", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_eth_staking_wbeth_unwrap(self, **params):
return await self._request_margin_api("post", "eth-staking/wbeth/unwrap", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_eth_staking_eth_history_staking_history(self, **params):
return await self._request_margin_api("get", "eth-staking/eth/history/stakingHistory", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_staking_staking_record(self, **params):
return await self._request_margin_api("get", "staking/stakingRecord", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_rebate_recent_record(self, **params):
return await self._request_margin_api("get", "broker/rebate/recentRecord", signed=True, data=params, version=1)
```
```python
async def v3_delete_user_data_stream(self, **params):
return await self._request_api("delete", "userDataStream", signed=True, data=params, version="v3")
```
```python
async def v3_get_open_order_list(self, **params):
return await self._request_api("get", "openOrderList", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_loan_vip_collateral_account(self, **params):
return await self._request_margin_api("get", "loan/vip/collateral/account", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_algo_spot_open_orders(self, **params):
return await self._request_margin_api("get", "algo/spot/openOrders", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_loan_repay(self, **params):
return await self._request_margin_api("post", "loan/repay", signed=True, data=params, version=1)
```
```python
async def futures_coin_v1_get_funding_info(self, **params):
return await self._request_futures_coin_api("get", "fundingInfo", signed=False, data=params, version=1)
```
```python
async def margin_v1_get_margin_leverage_bracket(self, **params):
return await self._request_margin_api("get", "margin/leverageBracket", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_portfolio_collateral_rate(self, **params):
return await self._request_margin_api("get", "portfolio/collateralRate", signed=True, data=params, version=2)
```
```python
async def margin_v2_post_loan_flexible_adjust_ltv(self, **params):
return await self._request_margin_api("post", "loan/flexible/adjust/ltv", signed=True, data=params, version=2)
```
```python
async def margin_v1_get_convert_order_status(self, **params):
return await self._request_margin_api("get", "convert/orderStatus", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_sub_account_api_ip_restriction(self, **params):
return await self._request_margin_api("get", "broker/subAccountApi/ipRestriction", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_dci_product_subscribe(self, **params):
return await self._request_margin_api("post", "dci/product/subscribe", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_income_asyn_id(self, **params):
return await self._request_futures_api("get", "income/asyn/id", signed=True, data=params, version=1)
```
```python
async def options_v1_post_countdown_cancel_all(self, **params):
return await self._request_options_api("post", "countdownCancelAll", signed=True, data=params)
```
```python
async def margin_v1_post_mining_hash_transfer_config_cancel(self, **params):
return await self._request_margin_api("post", "mining/hash-transfer/config/cancel", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_sub_account_deposit_hist(self, **params):
return await self._request_margin_api("get", "broker/subAccount/depositHist", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_mining_payment_list(self, **params):
return await self._request_margin_api("get", "mining/payment/list", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_pm_account_info(self, **params):
return await self._request_futures_api("get", "pmAccountInfo", signed=True, data=params, version=1)
```
```python
async def futures_coin_v1_get_adl_quantile(self, **params):
return await self._request_futures_coin_api("get", "adlQuantile", signed=True, data=params, version=1)
```
```python
async def options_v1_get_income_asyn_id(self, **params):
return await self._request_options_api("get", "income/asyn/id", signed=True, data=params)
```
```python
async def v3_post_cancel_replace(self, **params):
return await self._request_api("post", "cancelReplace", signed=True, data=params, version="v3")
```
```python
async def v3_post_order_test(self, **params):
return await self._request_api("post", "order/test", signed=True, data=params, version="v3")
```
```python
async def margin_v1_post_account_enable_fast_withdraw_switch(self, **params):
return await self._request_margin_api("post", "account/enableFastWithdrawSwitch", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_transfer_futures(self, **params):
return await self._request_margin_api("post", "broker/transfer/futures", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_margin_isolated_transfer(self, **params):
return await self._request_margin_api("get", "margin/isolated/transfer", signed=True, data=params, version=1)
```
```python
async def v3_post_order_cancel_replace(self, **params):
return await self._request_api("post", "order/cancelReplace", signed=True, data=params, version="v3")
```
```python
async def margin_v1_post_sol_staking_sol_stake(self, **params):
return await self._request_margin_api("post", "sol-staking/sol/stake", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_loan_borrow(self, **params):
return await self._request_margin_api("post", "loan/borrow", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_managed_subaccount_info(self, **params):
return await self._request_margin_api("get", "managed-subaccount/info", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_lending_auto_invest_plan_edit_status(self, **params):
return await self._request_margin_api("post", "lending/auto-invest/plan/edit-status", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sol_staking_sol_history_unclaimed_rewards(self, **params):
return await self._request_margin_api("get", "sol-staking/sol/history/unclaimedRewards", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_asset_convert_transfer_query_by_page(self, **params):
return await self._request_margin_api("post", "asset/convert-transfer/queryByPage", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sol_staking_sol_history_boost_rewards_history(self, **params):
return await self._request_margin_api("get", "sol-staking/sol/history/boostRewardsHistory", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_lending_auto_invest_one_off_status(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/one-off/status", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account(self, **params):
return await self._request_margin_api("post", "broker/subAccount", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_asset_ledger_transfer_cloud_mining_query_by_page(self, **params):
return await self._request_margin_api("get", "asset/ledger-transfer/cloud-mining/queryByPage", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_mining_pub_coin_list(self, **params):
return await self._request_margin_api("get", "mining/pub/coinList", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_loan_flexible_repay_history(self, **params):
return await self._request_margin_api("get", "loan/flexible/repay/history", signed=True, data=params, version=2)
```
```python
async def v3_post_sor_order(self, **params):
return await self._request_api("post", "sor/order", signed=True, data=params, version="v3")
```
```python
async def margin_v1_post_capital_deposit_credit_apply(self, **params):
return await self._request_margin_api("post", "capital/deposit/credit-apply", signed=True, data=params, version=1)
```
```python
async def futures_v1_put_batch_order(self, **params):
return await self._request_futures_api("put", "batchOrder", signed=True, data=params, version=1)
```
```python
async def v3_get_my_prevented_matches(self, **params):
return await self._request_api("get", "myPreventedMatches", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_mining_statistics_user_list(self, **params):
return await self._request_margin_api("get", "mining/statistics/user/list", signed=True, data=params, version=1)
```
```python
async def futures_v1_post_batch_order(self, **params):
return await self._request_futures_api("post", "batchOrder", signed=True, data=params, version=1)
```
```python
async def v3_get_ticker_trading_day(self, **params):
return await self._request_api("get", "ticker/tradingDay", signed=False, data=params, version="v3")
```
```python
async def margin_v1_get_mining_worker_detail(self, **params):
return await self._request_margin_api("get", "mining/worker/detail", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_managed_subaccount_fetch_future_asset(self, **params):
return await self._request_margin_api("get", "managed-subaccount/fetch-future-asset", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_margin_rate_limit_order(self, **params):
return await self._request_margin_api("get", "margin/rateLimit/order", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_localentity_vasp(self, **params):
return await self._request_margin_api("get", "localentity/vasp", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sol_staking_sol_history_rate_history(self, **params):
return await self._request_margin_api("get", "sol-staking/sol/history/rateHistory", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_api_ip_restriction(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi/ipRestriction", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_transfer(self, **params):
return await self._request_margin_api("get", "broker/transfer", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sol_staking_account(self, **params):
return await self._request_margin_api("get", "sol-staking/account", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_account_info(self, **params):
return await self._request_margin_api("get", "account/info", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_portfolio_repay_futures_switch(self, **params):
return await self._request_margin_api("post", "portfolio/repay-futures-switch", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_loan_vip_borrow(self, **params):
return await self._request_margin_api("post", "loan/vip/borrow", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_loan_flexible_ltv_adjustment_history(self, **params):
return await self._request_margin_api("get", "loan/flexible/ltv/adjustment/history", signed=True, data=params, version=2)
```
```python
async def options_v1_delete_all_open_orders_by_underlying(self, **params):
return await self._request_options_api("delete", "allOpenOrdersByUnderlying", signed=True, data=params)
```
```python
async def margin_v1_get_broker_sub_account_futures_summary(self, **params):
return await self._request_margin_api("get", "broker/subAccount/futuresSummary", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_sub_account_spot_summary(self, **params):
return await self._request_margin_api("get", "broker/subAccount/spotSummary", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_sub_account_blvt_enable(self, **params):
return await self._request_margin_api("post", "sub-account/blvt/enable", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_algo_spot_historical_orders(self, **params):
return await self._request_margin_api("get", "algo/spot/historicalOrders", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_loan_vip_repay_history(self, **params):
return await self._request_margin_api("get", "loan/vip/repay/history", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_loan_borrow_history(self, **params):
return await self._request_margin_api("get", "loan/borrow/history", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_lending_auto_invest_redeem(self, **params):
return await self._request_margin_api("post", "lending/auto-invest/redeem", signed=True, data=params, version=1)
```
```python
async def v3_get_account(self, **params):
return await self._request_api("get", "account", signed=True, data=params, version="v3")
```
```python
async def v3_delete_order(self, **params):
return await self._request_api("delete", "order", signed=True, data=params, version="v3")
```
```python
async def futures_coin_v1_get_income_asyn(self, **params):
return await self._request_futures_coin_api("get", "income/asyn", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_managed_subaccount_deposit(self, **params):
return await self._request_margin_api("post", "managed-subaccount/deposit", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_lending_daily_purchase(self, **params):
return await self._request_margin_api("post", "lending/daily/purchase", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_trade_asyn_id(self, **params):
return await self._request_futures_api("get", "trade/asyn/id", signed=True, data=params, version=1)
```
```python
async def margin_v1_delete_sub_account_sub_account_api_ip_restriction_ip_list(self, **params):
return await self._request_margin_api("delete", "sub-account/subAccountApi/ipRestriction/ipList", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_copy_trading_futures_user_status(self, **params):
return await self._request_margin_api("get", "copyTrading/futures/userStatus", signed=True, data=params, version=1)
```
```python
async def options_v1_get_margin_account(self, **params):
return await self._request_options_api("get", "marginAccount", signed=True, data=params)
```
```python
async def margin_v1_post_localentity_withdraw_apply(self, **params):
return await self._request_margin_api("post", "localentity/withdraw/apply", signed=True, data=params, version=1)
```
```python
async def v3_put_user_data_stream(self, **params):
return await self._request_api("put", "userDataStream", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_asset_wallet_balance(self, **params):
return await self._request_margin_api("get", "asset/wallet/balance", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_transfer(self, **params):
return await self._request_margin_api("post", "broker/transfer", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_lending_customized_fixed_purchase(self, **params):
return await self._request_margin_api("post", "lending/customizedFixed/purchase", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_algo_futures_new_order_twap(self, **params):
return await self._request_margin_api("post", "algo/futures/newOrderTwap", signed=True, data=params, version=1)
```
```python
async def margin_v2_post_eth_staking_eth_stake(self, **params):
return await self._request_margin_api("post", "eth-staking/eth/stake", signed=True, data=params, version=2)
```
```python
async def margin_v1_post_loan_flexible_repay_history(self, **params):
return await self._request_margin_api("post", "loan/flexible/repay/history", signed=True, data=params, version=1)
```
```python
async def v3_post_user_data_stream(self, **params):
return await self._request_api("post", "userDataStream", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_lending_auto_invest_index_info(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/index/info", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sol_staking_sol_history_redemption_history(self, **params):
return await self._request_margin_api("get", "sol-staking/sol/history/redemptionHistory", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_rebate_futures_recent_record(self, **params):
return await self._request_margin_api("get", "broker/rebate/futures/recentRecord", signed=True, data=params, version=1)
```
```python
async def margin_v3_get_broker_sub_account_futures_summary(self, **params):
return await self._request_margin_api("get", "broker/subAccount/futuresSummary", signed=True, data=params, version=3)
```
```python
async def margin_v1_post_margin_manual_liquidation(self, **params):
return await self._request_margin_api("post", "margin/manual-liquidation", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_lending_auto_invest_target_asset_roi_list(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/target-asset/roi/list", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_universal_transfer(self, **params):
return await self._request_margin_api("get", "broker/universalTransfer", signed=True, data=params, version=1)
```
```python
async def futures_v1_put_batch_orders(self, **params):
return await self._request_futures_api("put", "batchOrders", signed=True, data=params, version=1)
```
```python
async def options_v1_post_countdown_cancel_all_heart_beat(self, **params):
return await self._request_options_api("post", "countdownCancelAllHeartBeat", signed=True, data=params)
```
```python
async def margin_v1_get_loan_collateral_data(self, **params):
return await self._request_margin_api("get", "loan/collateral/data", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_loan_repay_history(self, **params):
return await self._request_margin_api("get", "loan/repay/history", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_convert_limit_place_order(self, **params):
return await self._request_margin_api("post", "convert/limit/placeOrder", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_convert_exchange_info(self, **params):
return await self._request_futures_api("get", "convert/exchangeInfo", signed=False, data=params, version=1)
```
```python
async def v3_get_all_order_list(self, **params):
return await self._request_api("get", "allOrderList", signed=True, data=params, version="v3")
```
```python
async def margin_v1_delete_broker_sub_account_api_ip_restriction_ip_list(self, **params):
return await self._request_margin_api("delete", "broker/subAccountApi/ipRestriction/ipList", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_sub_account_virtual_sub_account(self, **params):
return await self._request_margin_api("post", "sub-account/virtualSubAccount", signed=True, data=params, version=1)
```
```python
async def margin_v1_put_localentity_deposit_provide_info(self, **params):
return await self._request_margin_api("put", "localentity/deposit/provide-info", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_portfolio_mint(self, **params):
return await self._request_margin_api("post", "portfolio/mint", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_order_amendment(self, **params):
return await self._request_futures_api("get", "orderAmendment", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_sol_staking_sol_claim(self, **params):
return await self._request_margin_api("post", "sol-staking/sol/claim", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_lending_daily_redeem(self, **params):
return await self._request_margin_api("post", "lending/daily/redeem", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_mining_hash_transfer_config(self, **params):
return await self._request_margin_api("post", "mining/hash-transfer/config", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_lending_auto_invest_rebalance_history(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/rebalance/history", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_loan_repay_collateral_rate(self, **params):
return await self._request_margin_api("get", "loan/repay/collateral/rate", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_income_asyn(self, **params):
return await self._request_futures_api("get", "income/asyn", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_mining_payment_uid(self, **params):
return await self._request_margin_api("get", "mining/payment/uid", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_loan_flexible_borrow_history(self, **params):
return await self._request_margin_api("get", "loan/flexible/borrow/history", signed=True, data=params, version=2)
```
```python
async def v3_get_order(self, **params):
return await self._request_api("get", "order", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_capital_contract_convertible_coins(self, **params):
return await self._request_margin_api("get", "capital/contract/convertible-coins", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_api_permission_vanilla_options(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi/permission/vanillaOptions", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_lending_auto_invest_redeem_history(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/redeem/history", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_localentity_withdraw_history(self, **params):
return await self._request_margin_api("get", "localentity/withdraw/history", signed=True, data=params, version=2)
```
```python
async def margin_v1_get_eth_staking_eth_history_redemption_history(self, **params):
return await self._request_margin_api("get", "eth-staking/eth/history/redemptionHistory", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_fee_burn(self, **params):
return await self._request_futures_api("get", "feeBurn", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_lending_auto_invest_index_user_summary(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/index/user-summary", signed=True, data=params, version=1)
```
```python
async def margin_v2_post_loan_flexible_borrow(self, **params):
return await self._request_margin_api("post", "loan/flexible/borrow", signed=True, data=params, version=2)
```
```python
async def margin_v1_post_loan_vip_repay(self, **params):
return await self._request_margin_api("post", "loan/vip/repay", signed=True, data=params, version=1)
```
```python
async def futures_coin_v1_get_commission_rate(self, **params):
return await self._request_futures_coin_api("get", "commissionRate", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_convert_asset_info(self, **params):
return await self._request_margin_api("get", "convert/assetInfo", signed=True, data=params, version=1)
```
```python
async def v3_post_sor_order_test(self, **params):
return await self._request_api("post", "sor/order/test", signed=True, data=params, version="v3")
```
```python
async def margin_v1_post_broker_universal_transfer(self, **params):
return await self._request_margin_api("post", "broker/universalTransfer", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_account_disable_fast_withdraw_switch(self, **params):
return await self._request_margin_api("post", "account/disableFastWithdrawSwitch", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_asset_index(self, **params):
return await self._request_futures_api("get", "assetIndex", signed=False, data=params, version=1)
```
```python
async def v3_get_rate_limit_order(self, **params):
return await self._request_api("get", "rateLimit/order", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_account_api_restrictions_ip_restriction(self, **params):
return await self._request_margin_api("get", "account/apiRestrictions/ipRestriction", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_bnb_burn_spot(self, **params):
return await self._request_margin_api("post", "broker/subAccount/bnbBurn/spot", signed=True, data=params, version=1)
```
```python
async def futures_coin_v1_put_batch_orders(self, **params):
return await self._request_futures_coin_api("put", "batchOrders", signed=True, data=params, version=1)
```
```python
async def v3_delete_open_orders(self, **params):
return await self._request_api("delete", "openOrders", signed=True, data=params, version="v3")
```
```python
async def margin_v1_post_broker_sub_account_api_permission_universal_transfer(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi/permission/universalTransfer", signed=True, data=params, version=1)
```
```python
async def v3_get_my_allocations(self, **params):
return await self._request_api("get", "myAllocations", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_loan_ltv_adjustment_history(self, **params):
return await self._request_margin_api("get", "loan/ltv/adjustment/history", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_localentity_withdraw_history(self, **params):
return await self._request_margin_api("get", "localentity/withdraw/history", signed=True, data=params, version=1)
```
```python
async def margin_v2_post_sub_account_sub_account_api_ip_restriction(self, **params):
return await self._request_margin_api("post", "sub-account/subAccountApi/ipRestriction", signed=True, data=params, version=2)
```
```python
async def futures_v1_get_rate_limit_order(self, **params):
return await self._request_futures_api("get", "rateLimit/order", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_sub_account_api_commission_futures(self, **params):
return await self._request_margin_api("get", "broker/subAccountApi/commission/futures", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sol_staking_sol_history_staking_history(self, **params):
return await self._request_margin_api("get", "sol-staking/sol/history/stakingHistory", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_open_order(self, **params):
return await self._request_futures_api("get", "openOrder", signed=True, data=params, version=1)
```
```python
async def margin_v1_delete_algo_spot_order(self, **params):
return await self._request_margin_api("delete", "algo/spot/order", signed=True, data=params, version=1)
```
```python
async def v3_post_order(self, **params):
return await self._request_api("post", "order", signed=True, data=params, version="v3")
```
```python
async def margin_v1_delete_account_api_restrictions_ip_restriction_ip_list(self, **params):
return await self._request_margin_api("delete", "account/apiRestrictions/ipRestriction/ipList", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_capital_contract_convertible_coins(self, **params):
return await self._request_margin_api("post", "capital/contract/convertible-coins", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_managed_subaccount_margin_asset(self, **params):
return await self._request_margin_api("get", "managed-subaccount/marginAsset", signed=True, data=params, version=1)
```
```python
async def v3_delete_order_list(self, **params):
return await self._request_api("delete", "orderList", signed=True, data=params, version="v3")
```
```python
async def margin_v1_post_sub_account_sub_account_api_ip_restriction_ip_list(self, **params):
return await self._request_margin_api("post", "sub-account/subAccountApi/ipRestriction/ipList", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_api_commission(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi/commission", signed=True, data=params, version=1)
```
```python
async def futures_v1_post_fee_burn(self, **params):
return await self._request_futures_api("post", "feeBurn", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_sub_account_margin_summary(self, **params):
return await self._request_margin_api("get", "broker/subAccount/marginSummary", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_lending_auto_invest_plan_list(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/plan/list", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_loan_vip_loanable_data(self, **params):
return await self._request_margin_api("get", "loan/vip/loanable/data", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_loan_flexible_collateral_data(self, **params):
return await self._request_margin_api("get", "loan/flexible/collateral/data", signed=True, data=params, version=2)
```
```python
async def margin_v1_delete_broker_sub_account_api(self, **params):
return await self._request_margin_api("delete", "broker/subAccountApi", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sol_staking_sol_history_bnsol_rewards_history(self, **params):
return await self._request_margin_api("get", "sol-staking/sol/history/bnsolRewardsHistory", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_convert_limit_query_open_orders(self, **params):
return await self._request_margin_api("get", "convert/limit/queryOpenOrders", signed=True, data=params, version=1)
```
```python
async def v3_get_account_commission(self, **params):
return await self._request_api("get", "account/commission", signed=True, data=params, version="v3")
```
```python
async def v3_post_order_list_oco(self, **params):
return await self._request_api("post", "orderList/oco", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_managed_subaccount_query_trans_log(self, **params):
return await self._request_margin_api("get", "managed-subaccount/query-trans-log", signed=True, data=params, version=1)
```
```python
async def margin_v2_post_broker_sub_account_api_ip_restriction(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi/ipRestriction", signed=True, data=params, version=2)
```
```python
async def margin_v1_get_lending_auto_invest_all_asset(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/all/asset", signed=True, data=params, version=1)
```
```python
async def futures_v1_post_convert_accept_quote(self, **params):
return await self._request_futures_api("post", "convert/acceptQuote", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_spot_delist_schedule(self, **params):
return await self._request_margin_api("get", "spot/delist-schedule", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_account_api_restrictions_ip_restriction(self, **params):
return await self._request_margin_api("post", "account/apiRestrictions/ipRestriction", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_dci_product_accounts(self, **params):
return await self._request_margin_api("get", "dci/product/accounts", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sub_account_sub_account_api_ip_restriction(self, **params):
return await self._request_margin_api("get", "sub-account/subAccountApi/ipRestriction", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sub_account_transaction_statistics(self, **params):
return await self._request_margin_api("get", "sub-account/transaction-statistics", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_managed_subaccount_deposit_address(self, **params):
return await self._request_margin_api("get", "managed-subaccount/deposit/address", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_portfolio_account(self, **params):
return await self._request_margin_api("get", "portfolio/account", signed=True, data=params, version=2)
```
```python
async def margin_v1_get_simple_earn_locked_history_redemption_record(self, **params):
return await self._request_margin_api("get", "simple-earn/locked/history/redemptionRecord", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_order_asyn_id(self, **params):
return await self._request_futures_api("get", "order/asyn/id", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_managed_subaccount_withdraw(self, **params):
return await self._request_margin_api("post", "managed-subaccount/withdraw", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_localentity_deposit_history(self, **params):
return await self._request_margin_api("get", "localentity/deposit/history", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_eth_staking_wbeth_wrap(self, **params):
return await self._request_margin_api("post", "eth-staking/wbeth/wrap", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_simple_earn_locked_set_redeem_option(self, **params):
return await self._request_margin_api("post", "simple-earn/locked/setRedeemOption", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_api_ip_restriction_ip_list(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi/ipRestriction/ipList", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_broker_sub_account_api_commission_futures(self, **params):
return await self._request_margin_api("post", "broker/subAccountApi/commission/futures", signed=True, data=params, version=1)
```
```python
async def v3_get_open_orders(self, **params):
return await self._request_api("get", "openOrders", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_lending_auto_invest_history_list(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/history/list", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_loan_customize_margin_call(self, **params):
return await self._request_margin_api("post", "loan/customize/margin_call", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_sub_account_bnb_burn_status(self, **params):
return await self._request_margin_api("get", "broker/subAccount/bnbBurn/status", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_managed_subaccount_account_snapshot(self, **params):
return await self._request_margin_api("get", "managed-subaccount/accountSnapshot", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_asset_convert_transfer(self, **params):
return await self._request_margin_api("post", "asset/convert-transfer", signed=True, data=params, version=1)
```
```python
async def options_v1_get_income_asyn(self, **params):
return await self._request_options_api("get", "income/asyn", signed=True, data=params)
```
```python
async def margin_v1_get_broker_sub_account_api_commission_coin_futures(self, **params):
return await self._request_margin_api("get", "broker/subAccountApi/commission/coinFutures", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_broker_sub_account_futures_summary(self, **params):
return await self._request_margin_api("get", "broker/subAccount/futuresSummary", signed=True, data=params, version=2)
```
```python
async def margin_v1_get_loan_ongoing_orders(self, **params):
return await self._request_margin_api("get", "loan/ongoing/orders", signed=True, data=params, version=1)
```
```python
async def margin_v2_get_loan_flexible_ongoing_orders(self, **params):
return await self._request_margin_api("get", "loan/flexible/ongoing/orders", signed=True, data=params, version=2)
```
```python
async def margin_v1_post_algo_futures_new_order_vp(self, **params):
return await self._request_margin_api("post", "algo/futures/newOrderVp", signed=True, data=params, version=1)
```
```python
async def futures_v1_post_convert_get_quote(self, **params):
return await self._request_futures_api("post", "convert/getQuote", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_algo_spot_sub_orders(self, **params):
return await self._request_margin_api("get", "algo/spot/subOrders", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_portfolio_redeem(self, **params):
return await self._request_margin_api("post", "portfolio/redeem", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_lending_auto_invest_plan_add(self, **params):
return await self._request_margin_api("post", "lending/auto-invest/plan/add", signed=True, data=params, version=1)
```
```python
async def v3_get_order_list(self, **params):
return await self._request_api("get", "orderList", signed=True, data=params, version="v3")
```
```python
async def v3_get_my_trades(self, **params):
return await self._request_api("get", "myTrades", signed=True, data=params, version="v3")
```
```python
async def margin_v1_get_lending_auto_invest_source_asset_list(self, **params):
return await self._request_margin_api("get", "lending/auto-invest/source-asset/list", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_margin_all_order_list(self, **params):
return await self._request_margin_api("get", "margin/allOrderList", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_eth_staking_eth_redeem(self, **params):
return await self._request_margin_api("post", "eth-staking/eth/redeem", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_rebate_historical_record(self, **params):
return await self._request_margin_api("get", "broker/rebate/historicalRecord", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_simple_earn_locked_history_subscription_record(self, **params):
return await self._request_margin_api("get", "simple-earn/locked/history/subscriptionRecord", signed=True, data=params, version=1)
```
```python
async def futures_coin_v1_put_order(self, **params):
return await self._request_futures_coin_api("put", "order", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_managed_subaccount_asset(self, **params):
return await self._request_margin_api("get", "managed-subaccount/asset", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_sol_staking_sol_quota(self, **params):
return await self._request_margin_api("get", "sol-staking/sol/quota", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_loan_vip_renew(self, **params):
return await self._request_margin_api("post", "loan/vip/renew", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_managed_subaccount_query_trans_log_for_trade_parent(self, **params):
return await self._request_margin_api("get", "managed-subaccount/queryTransLogForTradeParent", signed=True, data=params, version=1)
```
```python
async def margin_v1_post_sub_account_sub_account_api_ip_restriction(self, **params):
return await self._request_margin_api("post", "sub-account/subAccountApi/ipRestriction", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_simple_earn_flexible_history_redemption_record(self, **params):
return await self._request_margin_api("get", "simple-earn/flexible/history/redemptionRecord", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_broker_sub_account_api(self, **params):
return await self._request_margin_api("get", "broker/subAccountApi", signed=True, data=params, version=1)
```
```python
async def options_v1_get_exercise_history(self, **params):
return await self._request_options_api("get", "exerciseHistory", signed=False, data=params)
```
```python
async def margin_v1_get_convert_exchange_info(self, **params):
return await self._request_margin_api("get", "convert/exchangeInfo", signed=False, data=params, version=1)
```
```python
async def futures_v1_delete_batch_order(self, **params):
return await self._request_futures_api("delete", "batchOrder", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_eth_staking_eth_history_wbeth_rewards_history(self, **params):
return await self._request_margin_api("get", "eth-staking/eth/history/wbethRewardsHistory", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_mining_pub_algo_list(self, **params):
return await self._request_margin_api("get", "mining/pub/algoList", signed=True, data=params, version=1)
```
```python
async def options_v1_get_block_trades(self, **params):
return await self._request_options_api("get", "blockTrades", signed=False, data=params)
```
```python
async def margin_v1_get_copy_trading_futures_lead_symbol(self, **params):
return await self._request_margin_api("get", "copyTrading/futures/leadSymbol", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_mining_worker_list(self, **params):
return await self._request_margin_api("get", "mining/worker/list", signed=True, data=params, version=1)
```
```python
async def margin_v1_get_dci_product_list(self, **params):
return await self._request_margin_api("get", "dci/product/list", signed=True, data=params, version=1)
```
```python
async def futures_v1_get_convert_order_status(self, **params):
return await self._request_futures_api("get", "convert/orderStatus", signed=True, data=params, version=1)
```
# async_client (/docs/api/async_client)
# BaseClient (/docs/api/base_client/BaseClient)
Attributes [#attributes]
Functions [#functions]
Binance API Client constructor
:param api\_key: Api Key
:type api\_key: str.
:param api\_secret: Api Secret
:type api\_secret: str.
:param requests\_params: optional - Dictionary of requests params to use for all calls
:type requests\_params: dict.
:param testnet: Use testnet environment - only available for vanilla options at the moment
:type testnet: bool
:param private\_key: Path to private key, or string of file contents
:type private\_key: optional - str or Path
:param private\_key\_pass: Password of private key
:type private\_key\_pass: optional - str
:param time\_unit: Time unit to use for requests. Supported values: "MILLISECOND", "MICROSECOND"
:type time\_unit: optional - str
:param verbose: Enable verbose logging for debugging
:type verbose: bool
```python
def __init__(
self,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
requests_params: Optional[Dict[str, Any]] = None,
tld: str = "com",
base_endpoint: str = BASE_ENDPOINT_DEFAULT,
testnet: bool = False,
demo: bool = False,
private_key: Optional[Union[str, Path]] = None,
private_key_pass: Optional[str] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
time_unit: Optional[str] = None,
verbose: bool = False,
):
"""Binance API Client constructor
:param api_key: Api Key
:type api_key: str.
:param api_secret: Api Secret
:type api_secret: str.
:param requests_params: optional - Dictionary of requests params to use for all calls
:type requests_params: dict.
:param testnet: Use testnet environment - only available for vanilla options at the moment
:type testnet: bool
:param private_key: Path to private key, or string of file contents
:type private_key: optional - str or Path
:param private_key_pass: Password of private key
:type private_key_pass: optional - str
:param time_unit: Time unit to use for requests. Supported values: "MILLISECOND", "MICROSECOND"
:type time_unit: optional - str
:param verbose: Enable verbose logging for debugging
:type verbose: bool
"""
self.tld = tld
self.verbose = verbose
self.logger = logging.getLogger(__name__)
# Set logger level based on verbose flag
# Users can override this by configuring logging externally
if verbose:
self.logger.setLevel(logging.DEBUG)
self.API_URL = self.API_URL.format(base_endpoint, tld)
self.MARGIN_API_URL = self.MARGIN_API_URL.format(base_endpoint, tld)
self.WEBSITE_URL = self.WEBSITE_URL.format(tld)
self.FUTURES_URL = self.FUTURES_URL.format(tld)
self.FUTURES_DATA_URL = self.FUTURES_DATA_URL.format(tld)
self.FUTURES_COIN_URL = self.FUTURES_COIN_URL.format(tld)
self.FUTURES_COIN_DATA_URL = self.FUTURES_COIN_DATA_URL.format(tld)
self.OPTIONS_URL = self.OPTIONS_URL.format(tld)
self.OPTIONS_TESTNET_URL = self.OPTIONS_TESTNET_URL.format(tld)
self.API_KEY = api_key
self.API_SECRET = api_secret
self.TIME_UNIT = time_unit
self._is_rsa = False
self.PRIVATE_KEY: Any = self._init_private_key(private_key, private_key_pass)
self.session = self._init_session()
self._requests_params = requests_params
self.response = None
self.testnet = testnet
self.demo = demo
self.timestamp_offset = 0
ws_api_url = self.WS_API_URL.format(tld)
if testnet:
ws_api_url = self.WS_API_TESTNET_URL
elif demo:
ws_api_url = self.WS_API_DEMO_URL
if self.TIME_UNIT:
ws_api_url += f"?timeUnit={self.TIME_UNIT}"
# Extract proxy from requests_params for WebSocket connections
https_proxy = None
if requests_params and 'proxies' in requests_params:
https_proxy = requests_params['proxies'].get('https') or requests_params['proxies'].get('http')
self.ws_api = WebsocketAPI(url=ws_api_url, tld=tld, https_proxy=https_proxy)
ws_future_url = self.WS_FUTURES_URL.format(tld)
if testnet:
ws_future_url = self.WS_FUTURES_TESTNET_URL
elif demo:
ws_future_url = self.WS_FUTURES_DEMO_URL
self.ws_future = WebsocketAPI(url=ws_future_url, tld=tld, https_proxy=https_proxy)
self.loop = loop or get_loop()
```
```python
def _get_headers(self) -> Dict:
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36", # noqa
}
if self.API_KEY:
assert self.API_KEY
headers["X-MBX-APIKEY"] = self.API_KEY
if self.TIME_UNIT:
assert self.TIME_UNIT
headers["X-MBX-TIME-UNIT"] = self.TIME_UNIT
return headers
```
```python
def _init_session(self):
raise NotImplementedError
```
```python
def _init_private_key(
self,
private_key: Optional[Union[str, Path]],
private_key_pass: Optional[str] = None,
):
if not private_key:
return
if isinstance(private_key, Path):
with open(private_key, "r") as f:
private_key = f.read()
if len(private_key) > 120:
self._is_rsa = True
return RSA.import_key(private_key, passphrase=private_key_pass)
return ECC.import_key(private_key)
```
```python
def _create_api_uri(
self, path: str, signed: bool = True, version: str = PUBLIC_API_VERSION
) -> str:
url = self.API_URL
if self.testnet:
url = self.API_TESTNET_URL
elif self.demo:
url = self.API_DEMO_URL
v = self.PRIVATE_API_VERSION if signed else version
return url + "/" + v + "/" + path
```
```python
def _create_margin_api_uri(self, path: str, version: int = 1) -> str:
options = {
1: self.MARGIN_API_VERSION,
2: self.MARGIN_API_VERSION2,
3: self.MARGIN_API_VERSION3,
4: self.MARGIN_API_VERSION4,
}
return self.MARGIN_API_URL + "/" + options[version] + "/" + path
```
```python
def _create_papi_api_uri(self, path: str, version: int = 1) -> str:
options = {1: self.PORTFOLIO_API_VERSION, 2: self.PORTFOLIO_API_VERSION2}
return self.PAPI_URL.format(self.tld) + "/" + options[version] + "/" + path
```
```python
def _create_website_uri(self, path: str) -> str:
return self.WEBSITE_URL + "/" + path
```
```python
def _create_futures_api_uri(self, path: str, version: int = 1) -> str:
url = self.FUTURES_URL
if self.testnet:
url = self.FUTURES_TESTNET_URL
elif self.demo:
url = self.FUTURES_DEMO_URL
options = {
1: self.FUTURES_API_VERSION,
2: self.FUTURES_API_VERSION2,
3: self.FUTURES_API_VERSION3,
}
return url + "/" + options[version] + "/" + path
```
```python
def _create_futures_data_api_uri(self, path: str) -> str:
url = self.FUTURES_DATA_URL
if self.testnet:
url = self.FUTURES_DATA_TESTNET_URL
return url + "/" + path
```
```python
def _create_futures_coin_api_url(self, path: str, version: int = 1) -> str:
url = self.FUTURES_COIN_URL
if self.testnet:
url = self.FUTURES_COIN_TESTNET_URL
elif self.demo:
url = self.FUTURES_COIN_DEMO_URL
options = {
1: self.FUTURES_API_VERSION,
2: self.FUTURES_API_VERSION2,
3: self.FUTURES_API_VERSION3,
}
return url + "/" + options[version] + "/" + path
```
```python
def _create_futures_coin_data_api_url(self, path: str, version: int = 1) -> str:
url = self.FUTURES_COIN_DATA_URL
if self.testnet:
url = self.FUTURES_COIN_DATA_TESTNET_URL
return url + "/" + path
```
```python
def _create_options_api_uri(self, path: str) -> str:
url = self.OPTIONS_URL
if self.testnet:
url = self.OPTIONS_TESTNET_URL
return url + "/" + self.OPTIONS_API_VERSION + "/" + path
```
```python
def _rsa_signature(self, query_string: str):
assert self.PRIVATE_KEY
h = SHA256.new(query_string.encode("utf-8"))
signature = pkcs1_15.new(self.PRIVATE_KEY).sign(h) # type: ignore
res = b64encode(signature).decode()
# return self.encode_uri_component(res)
return res
```
```python
@staticmethod
def encode_uri_component(uri, safe="~()*!.'"):
return _urlencode.quote(uri, safe=safe)
```
```python
@staticmethod
def convert_to_dict(list_tuples):
dictionary = dict((key, value) for key, value in list_tuples)
return dictionary
```
Validate client is configured for required TLD.
:param required\_tld: The required TLD (e.g., "us")
:param endpoint\_name: Description of the endpoint for error messages
:raises BinanceRegionException: If the client TLD doesn't match
```python
def _require_tld(self, required_tld: str, endpoint_name: str = "endpoint") -> None:
"""Validate client is configured for required TLD.
:param required_tld: The required TLD (e.g., "us")
:param endpoint_name: Description of the endpoint for error messages
:raises BinanceRegionException: If the client TLD doesn't match
"""
if self.tld != required_tld:
from binance.exceptions import BinanceRegionException
raise BinanceRegionException(required_tld, self.tld, endpoint_name)
```
```python
def _ed25519_signature(self, query_string: str):
assert self.PRIVATE_KEY
res = b64encode(
eddsa.new(self.PRIVATE_KEY, "rfc8032").sign(query_string.encode())
).decode() # type: ignore
# return self.encode_uri_component(res)
return res
```
```python
def _hmac_signature(self, query_string: str) -> str:
assert self.API_SECRET, "API Secret required for private endpoints"
m = hmac.new(
self.API_SECRET.encode("utf-8"),
query_string.encode("utf-8"),
hashlib.sha256,
)
return m.hexdigest()
```
```python
def _generate_signature(self, data: Dict, uri_encode=True) -> str:
sig_func = self._hmac_signature
if self.PRIVATE_KEY:
if self._is_rsa:
sig_func = self._rsa_signature
else:
sig_func = self._ed25519_signature
query_string = "&".join([f"{d[0]}={_urlencode.quote(d[1]) if d[0] == 'symbol' else d[1]}" for d in self._order_params(data)])
res = sig_func(query_string)
return self.encode_uri_component(res) if uri_encode else res
```
```python
def _sign_ws_params(self, params, signature_func):
if "signature" in params:
return params
params.setdefault("apiKey", self.API_KEY)
params.setdefault("timestamp", int(time.time() * 1000 + self.timestamp_offset))
params = dict(sorted(params.items()))
return {**params, "signature": signature_func(params)}
```
```python
def _generate_ws_api_signature(self, data: Dict) -> str:
sig_func = self._hmac_signature
if self.PRIVATE_KEY:
if self._is_rsa:
sig_func = self._rsa_signature
else:
sig_func = self._ed25519_signature
query_string = urlencode(data)
return sig_func(query_string)
```
Send request and wait for response
```python
async def _ws_futures_api_request(self, method: str, signed: bool, params: dict):
"""Send request and wait for response"""
id = params.pop("id", self.uuid22())
payload = {
"id": id,
"method": method,
"params": params,
}
if signed:
payload["params"] = self._sign_ws_params(params, self._generate_signature)
return await self.ws_future.request(id, payload)
```
```python
def _ws_futures_api_request_sync(self, method: str, signed: bool, params: dict):
self.loop = get_loop()
return self.loop.run_until_complete(
self._ws_futures_api_request(method, signed, params)
)
```
```python
async def _make_sync(self, method):
return asyncio.run(method)
```
Send request and wait for response
```python
async def _ws_api_request(self, method: str, signed: bool, params: dict):
"""Send request and wait for response"""
id = params.pop("id", self.uuid22())
payload = {
"id": id,
"method": method,
"params": params,
}
if signed:
payload["params"] = self._sign_ws_params(
params, self._generate_ws_api_signature
)
return await self.ws_api.request(id, payload)
```
Send request to WS API and wait for response
```python
def _ws_api_request_sync(self, method: str, signed: bool, params: dict):
"""Send request to WS API and wait for response"""
self.loop = get_loop()
return self.loop.run_until_complete(
self._ws_api_request(method, signed, params)
)
```
```python
@staticmethod
def _get_version(version: int, **kwargs) -> int:
if "data" in kwargs and "version" in kwargs["data"]:
version_override = kwargs["data"].get("version")
del kwargs["data"]["version"]
return version_override
return version
```
```python
@staticmethod
def uuid22(length=22):
return format(random.getrandbits(length * 4), "x")
```
Convert params to list with signature as last element
:param data:
:return:
```python
@staticmethod
def _order_params(data: Dict) -> List[Tuple[str, str]]:
"""Convert params to list with signature as last element
:param data:
:return:
"""
data = dict(filter(lambda el: el[1] is not None, data.items()))
has_signature = False
params = []
for key, value in data.items():
if key == "signature":
has_signature = True
else:
params.append((key, str(value)))
# sort parameters by key
params.sort(key=itemgetter(0))
if has_signature:
params.append(("signature", data["signature"]))
return params
```
```python
def _get_request_kwargs(
self, method, signed: bool, force_params: bool = False, **kwargs
) -> Dict:
# set default requests timeout
kwargs["timeout"] = self.REQUEST_TIMEOUT
# add our global requests params
if self._requests_params:
kwargs.update(self._requests_params)
data = kwargs.get("data", None)
if data and isinstance(data, dict):
kwargs["data"] = data
# find any requests params passed and apply them
if "requests_params" in kwargs["data"]:
# merge requests params into kwargs
kwargs.update(kwargs["data"]["requests_params"])
del kwargs["data"]["requests_params"]
if signed:
# generate signature
kwargs["data"]["timestamp"] = int(
time.time() * 1000 + self.timestamp_offset
)
if self.REQUEST_RECVWINDOW:
kwargs["data"]["recvWindow"] = self.REQUEST_RECVWINDOW
kwargs["data"]["signature"] = self._generate_signature(kwargs["data"])
# sort get and post params to match signature order
if data:
# sort post params and remove any arguments with values of None
kwargs["data"] = self._order_params(kwargs["data"])
# Remove any arguments with values of None.
null_args = [
i for i, (key, value) in enumerate(kwargs["data"]) if value is None
]
for i in reversed(null_args):
del kwargs["data"][i]
# if get request assign data array to params value for requests lib
if data and (method == "get" or force_params):
kwargs["params"] = "&".join(
"%s=%s" % (data[0], _urlencode.quote(data[1]) if data[0] == 'symbol' else data[1]) for data in kwargs["data"]
)
del kwargs["data"]
# Temporary fix for Signature issue while using batchOrders in AsyncClient
if "params" in kwargs.keys():
if (
"batchOrders" in kwargs["params"]
or "orderidlist" in kwargs["params"]
or "origclientorderidlist" in kwargs["params"]
):
kwargs["data"] = kwargs["params"]
del kwargs["params"]
return kwargs
```
# base_client (/docs/api/base_client)
# Client (/docs/api/client/Client)
Functions [#functions]
```python
def __init__(
self,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
requests_params: Optional[Dict[str, Any]] = None,
tld: str = "com",
base_endpoint: str = BaseClient.BASE_ENDPOINT_DEFAULT,
testnet: bool = False,
demo: bool = False,
private_key: Optional[Union[str, Path]] = None,
private_key_pass: Optional[str] = None,
ping: Optional[bool] = True,
time_unit: Optional[str] = None,
verbose: bool = False,
):
super().__init__(
api_key,
api_secret,
requests_params,
tld,
base_endpoint,
testnet,
demo,
private_key,
private_key_pass,
time_unit=time_unit,
verbose=verbose,
)
# init DNS and SSL cert
if ping:
self.ping()
```
```python
def _init_session(self) -> requests.Session:
headers = self._get_headers()
session = requests.session()
session.headers.update(headers)
return session
```
```python
def _request(
self, method, uri: str, signed: bool, force_params: bool = False, **kwargs
):
headers = {}
if method.upper() in ["POST", "PUT", "DELETE"]:
headers.update({"Content-Type": "application/x-www-form-urlencoded"})
if "data" in kwargs:
for key in kwargs["data"]:
if key == "headers":
headers.update(kwargs["data"][key])
del kwargs["data"][key]
break
kwargs = self._get_request_kwargs(method, signed, force_params, **kwargs)
data = kwargs.get("data")
if data is not None:
del kwargs["data"]
if signed and self.PRIVATE_KEY and data: # handle issues with signing using eddsa/rsa and POST requests
dict_data = Client.convert_to_dict(data)
signature = dict_data["signature"] if "signature" in dict_data else None
if signature:
del dict_data["signature"]
url_encoded_data = urlencode(dict_data)
data = f"{url_encoded_data}&signature={signature}"
self.response = getattr(self.session, method)(uri, headers=headers, data=data, **kwargs)
if self.verbose:
self.logger.debug(
"\nRequest: %s %s\nRequestHeaders: %s\nRequestBody: %s\nResponse: %s\nResponseHeaders: %s\nResponseBody: %s",
method.upper(),
uri,
headers,
data,
self.response.status_code,
dict(self.response.headers),
self.response.text[:1000] if self.response.text else None
)
return self._handle_response(self.response)
```
Internal helper for handling API responses from the Binance server.
Raises the appropriate exceptions when necessary; otherwise, returns the
response.
```python
@staticmethod
def _handle_response(response: requests.Response):
"""Internal helper for handling API responses from the Binance server.
Raises the appropriate exceptions when necessary; otherwise, returns the
response.
"""
if not (200 <= response.status_code < 300):
raise BinanceAPIException(response, response.status_code, response.text)
if response.text == "":
return {}
try:
return response.json()
except ValueError:
raise BinanceRequestException("Invalid Response: %s" % response.text)
```
```python
def _request_api(
self,
method,
path: str,
signed: bool = False,
version=BaseClient.PUBLIC_API_VERSION,
**kwargs,
):
uri = self._create_api_uri(path, signed, version)
return self._request(method, uri, signed, **kwargs)
```
```python
def _request_futures_api(
self, method, path, signed=False, version: int = 1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_futures_api_uri(path, version)
force_params = kwargs.pop("force_params", False)
return self._request(method, uri, signed, force_params, **kwargs)
```
```python
def _request_futures_data_api(self, method, path, signed=False, **kwargs) -> Dict:
uri = self._create_futures_data_api_uri(path)
force_params = kwargs.pop("force_params", True)
return self._request(method, uri, signed, force_params, **kwargs)
```
```python
def _request_futures_coin_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_futures_coin_api_url(path, version=version)
force_params = kwargs.pop("force_params", False)
return self._request(method, uri, signed, force_params, **kwargs)
```
```python
def _request_futures_coin_data_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_futures_coin_data_api_url(path, version=version)
force_params = kwargs.pop("force_params", True)
return self._request(method, uri, signed, force_params, **kwargs)
```
[https://developers.binance.com/docs/derivatives/option/market-data](https://developers.binance.com/docs/derivatives/option/market-data)
```python
def _request_options_api(self, method, path, signed=False, **kwargs) -> Dict:
"""
https://developers.binance.com/docs/derivatives/option/market-data
"""
uri = self._create_options_api_uri(path)
force_params = kwargs.pop("force_params", True)
return self._request(method, uri, signed, force_params, **kwargs)
```
```python
def _request_margin_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_margin_api_uri(path, version)
force_params = kwargs.pop("force_params", False)
return self._request(method, uri, signed, force_params, **kwargs)
```
```python
def _request_papi_api(
self, method, path, signed=False, version=1, **kwargs
) -> Dict:
version = self._get_version(version, **kwargs)
uri = self._create_papi_api_uri(path, version)
force_params = kwargs.pop("force_params", False)
return self._request(method, uri, signed, force_params, **kwargs)
```
```python
def _request_website(self, method, path, signed=False, **kwargs) -> Dict:
uri = self._create_website_uri(path)
return self._request(method, uri, signed, **kwargs)
```
```python
def _get(self, path, signed=False, version=BaseClient.PUBLIC_API_VERSION, **kwargs):
return self._request_api("get", path, signed, version, **kwargs)
```
```python
def _post(
self, path, signed=False, version=BaseClient.PUBLIC_API_VERSION, **kwargs
) -> Dict:
return self._request_api("post", path, signed, version, **kwargs)
```
```python
def _put(
self, path, signed=False, version=BaseClient.PUBLIC_API_VERSION, **kwargs
) -> Dict:
return self._request_api("put", path, signed, version, **kwargs)
```
```python
def _delete(
self, path, signed=False, version=BaseClient.PUBLIC_API_VERSION, **kwargs
) -> Dict:
return self._request_api("delete", path, signed, version, **kwargs)
```
Return list of products currently listed on Binance
Use get\_exchange\_info() call instead
:returns: list - List of product dictionaries
:raises: BinanceRequestException, BinanceAPIException
```python
def get_products(self) -> Dict:
"""Return list of products currently listed on Binance
Use get_exchange_info() call instead
:returns: list - List of product dictionaries
:raises: BinanceRequestException, BinanceAPIException
"""
products = self._request_website(
"get",
"bapi/asset/v2/public/asset-service/product/get-products?includeEtf=true",
)
return products
```
Return rate limits and list of symbols
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information)
:returns: list - List of product dictionaries
.. code-block:: python
\{
"timezone": "UTC",
"serverTime": 1508631584636,
"rateLimits": \[
\{
"rateLimitType": "REQUESTS",
"interval": "MINUTE",
"limit": 1200
},
\{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"limit": 10
},
\{
"rateLimitType": "ORDERS",
"interval": "DAY",
"limit": 100000
}
],
"exchangeFilters": \[],
"symbols": \[
\{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"orderTypes": \["LIMIT", "MARKET"],
"icebergAllowed": false,
"filters": \[
\{
"filterType": "PRICE\_FILTER",
"minPrice": "0.00000100",
"maxPrice": "100000.00000000",
"tickSize": "0.00000100"
}, \{
"filterType": "LOT\_SIZE",
"minQty": "0.00100000",
"maxQty": "100000.00000000",
"stepSize": "0.00100000"
}, \{
"filterType": "MIN\_NOTIONAL",
"minNotional": "0.00100000"
}
]
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_exchange_info(self) -> Dict:
"""Return rate limits and list of symbols
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information
:returns: list - List of product dictionaries
.. code-block:: python
{
"timezone": "UTC",
"serverTime": 1508631584636,
"rateLimits": [
{
"rateLimitType": "REQUESTS",
"interval": "MINUTE",
"limit": 1200
},
{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"limit": 10
},
{
"rateLimitType": "ORDERS",
"interval": "DAY",
"limit": 100000
}
],
"exchangeFilters": [],
"symbols": [
{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"orderTypes": ["LIMIT", "MARKET"],
"icebergAllowed": false,
"filters": [
{
"filterType": "PRICE_FILTER",
"minPrice": "0.00000100",
"maxPrice": "100000.00000000",
"tickSize": "0.00000100"
}, {
"filterType": "LOT_SIZE",
"minQty": "0.00100000",
"maxQty": "100000.00000000",
"stepSize": "0.00100000"
}, {
"filterType": "MIN_NOTIONAL",
"minNotional": "0.00100000"
}
]
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("exchangeInfo")
```
Return information about a symbol
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information)
:param symbol: required e.g. BNBBTC
:type symbol: str
:returns: Dict if found, None if not
.. code-block:: python
\{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"orderTypes": \["LIMIT", "MARKET"],
"icebergAllowed": false,
"filters": \[
\{
"filterType": "PRICE\_FILTER",
"minPrice": "0.00000100",
"maxPrice": "100000.00000000",
"tickSize": "0.00000100"
}, \{
"filterType": "LOT\_SIZE",
"minQty": "0.00100000",
"maxQty": "100000.00000000",
"stepSize": "0.00100000"
}, \{
"filterType": "MIN\_NOTIONAL",
"minNotional": "0.00100000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_symbol_info(self, symbol) -> Optional[Dict]:
"""Return information about a symbol
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#exchange-information
:param symbol: required e.g. BNBBTC
:type symbol: str
:returns: Dict if found, None if not
.. code-block:: python
{
"symbol": "ETHBTC",
"status": "TRADING",
"baseAsset": "ETH",
"baseAssetPrecision": 8,
"quoteAsset": "BTC",
"quotePrecision": 8,
"orderTypes": ["LIMIT", "MARKET"],
"icebergAllowed": false,
"filters": [
{
"filterType": "PRICE_FILTER",
"minPrice": "0.00000100",
"maxPrice": "100000.00000000",
"tickSize": "0.00000100"
}, {
"filterType": "LOT_SIZE",
"minQty": "0.00100000",
"maxQty": "100000.00000000",
"stepSize": "0.00100000"
}, {
"filterType": "MIN_NOTIONAL",
"minNotional": "0.00100000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
res = self.get_exchange_info()
for item in res["symbols"]:
if item["symbol"] == symbol.upper():
return item
return None
```
Test connectivity to the Rest API.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#test-connectivity](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#test-connectivity)
:returns: Empty array
.. code-block:: python
\{}
:raises: BinanceRequestException, BinanceAPIException
```python
def ping(self) -> Dict:
"""Test connectivity to the Rest API.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#test-connectivity
:returns: Empty array
.. code-block:: python
{}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("ping")
```
Test connectivity to the Rest API and get the current server time.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#check-server-time](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#check-server-time)
:returns: Current server time
.. code-block:: python
\{
"serverTime": 1499827319559
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_server_time(self) -> Dict:
"""Test connectivity to the Rest API and get the current server time.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/general-endpoints#check-server-time
:returns: Current server time
.. code-block:: python
{
"serverTime": 1499827319559
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("time")
```
Latest price for all symbols.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-price-ticker](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-price-ticker)
:returns: List of market tickers
.. code-block:: python
\[
\{
"symbol": "LTCBTC",
"price": "4.00000200"
},
\{
"symbol": "ETHBTC",
"price": "0.07946600"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_all_tickers(self) -> List[Dict[str, str]]:
"""Latest price for all symbols.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-price-ticker
:returns: List of market tickers
.. code-block:: python
[
{
"symbol": "LTCBTC",
"price": "4.00000200"
},
{
"symbol": "ETHBTC",
"price": "0.07946600"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
response = self._get("ticker/price")
if isinstance(response, list) and all(isinstance(item, dict) for item in response):
return response
raise TypeError("Expected a list of dictionaries")
```
Best price/qty on the order book for all symbols.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-order-book-ticker](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-order-book-ticker)
:param symbol: optional
:type symbol: str
:param symbols: optional accepted format \["BTCUSDT","BNBUSDT"] or %5B%22BTCUSDT%22,%22BNBUSDT%22%5D
:type symbols: str
:returns: List of order book market entries
.. code-block:: python
\[
\{
"symbol": "LTCBTC",
"bidPrice": "4.00000000",
"bidQty": "431.00000000",
"askPrice": "4.00000200",
"askQty": "9.00000000"
},
\{
"symbol": "ETHBTC",
"bidPrice": "0.07946700",
"bidQty": "9.00000000",
"askPrice": "100000.00000000",
"askQty": "1000.00000000"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_orderbook_tickers(self, **params) -> Dict:
"""Best price/qty on the order book for all symbols.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-order-book-ticker
:param symbol: optional
:type symbol: str
:param symbols: optional accepted format ["BTCUSDT","BNBUSDT"] or %5B%22BTCUSDT%22,%22BNBUSDT%22%5D
:type symbols: str
:returns: List of order book market entries
.. code-block:: python
[
{
"symbol": "LTCBTC",
"bidPrice": "4.00000000",
"bidQty": "431.00000000",
"askPrice": "4.00000200",
"askQty": "9.00000000"
},
{
"symbol": "ETHBTC",
"bidPrice": "0.07946700",
"bidQty": "9.00000000",
"askPrice": "100000.00000000",
"askQty": "1000.00000000"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
data = {}
if "symbol" in params:
data["symbol"] = params["symbol"]
elif "symbols" in params:
data["symbols"] = params["symbols"]
return self._get(
"ticker/bookTicker", data=data
)
```
Get the Order Book for the market
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#order-book](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#order-book)
:param symbol: required
:type symbol: str
:param limit: Default 100; max 1000
:type limit: int
:returns: API response
.. code-block:: python
\{
"lastUpdateId": 1027024,
"bids": \[
\[
"4.00000000", # PRICE
"431.00000000", # QTY
\[] # Can be ignored
]
],
"asks": \[
\[
"4.00000200",
"12.00000000",
\[]
]
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_order_book(self, **params) -> Dict:
"""Get the Order Book for the market
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#order-book
:param symbol: required
:type symbol: str
:param limit: Default 100; max 1000
:type limit: int
:returns: API response
.. code-block:: python
{
"lastUpdateId": 1027024,
"bids": [
[
"4.00000000", # PRICE
"431.00000000", # QTY
[] # Can be ignored
]
],
"asks": [
[
"4.00000200",
"12.00000000",
[]
]
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("depth", data=params)
```
Get recent trades (up to last 500).
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#recent-trades-list](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#recent-trades-list)
:param symbol: required
:type symbol: str
:param limit: Default 500; max 1000.
:type limit: int
:returns: API response
.. code-block:: python
\[
\{
"id": 28457,
"price": "4.00000100",
"qty": "12.00000000",
"time": 1499865549590,
"isBuyerMaker": true,
"isBestMatch": true
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_recent_trades(self, **params) -> Dict:
"""Get recent trades (up to last 500).
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#recent-trades-list
:param symbol: required
:type symbol: str
:param limit: Default 500; max 1000.
:type limit: int
:returns: API response
.. code-block:: python
[
{
"id": 28457,
"price": "4.00000100",
"qty": "12.00000000",
"time": 1499865549590,
"isBuyerMaker": true,
"isBestMatch": true
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("trades", data=params)
```
Get older trades.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#old-trade-lookup](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#old-trade-lookup)
:param symbol: required
:type symbol: str
:param limit: Default 500; max 1000.
:type limit: int
:param fromId: TradeId to fetch from. Default gets most recent trades.
:type fromId: str
:returns: API response
.. code-block:: python
\[
\{
"id": 28457,
"price": "4.00000100",
"qty": "12.00000000",
"time": 1499865549590,
"isBuyerMaker": true,
"isBestMatch": true
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_historical_trades(self, **params) -> Dict:
"""Get older trades.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#old-trade-lookup
:param symbol: required
:type symbol: str
:param limit: Default 500; max 1000.
:type limit: int
:param fromId: TradeId to fetch from. Default gets most recent trades.
:type fromId: str
:returns: API response
.. code-block:: python
[
{
"id": 28457,
"price": "4.00000100",
"qty": "12.00000000",
"time": 1499865549590,
"isBuyerMaker": true,
"isBestMatch": true
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get(
"historicalTrades", data=params
)
```
Get compressed, aggregate trades. Trades that fill at the time,
from the same order, with the same price will have the quantity aggregated.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#compressedaggregate-trades-list](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#compressedaggregate-trades-list)
:param symbol: required
:type symbol: str
:param fromId: ID to get aggregate trades from INCLUSIVE.
:type fromId: str
:param startTime: Timestamp in ms to get aggregate trades from INCLUSIVE.
:type startTime: int
:param endTime: Timestamp in ms to get aggregate trades until INCLUSIVE.
:type endTime: int
:param limit: Default 500; max 1000.
:type limit: int
:returns: API response
.. code-block:: python
\[
\{
"a": 26129, # Aggregate tradeId
"p": "0.01633102", # Price
"q": "4.70443515", # Quantity
"f": 27781, # First tradeId
"l": 27781, # Last tradeId
"T": 1498793709153, # Timestamp
"m": true, # Was the buyer the maker?
"M": true # Was the trade the best price match?
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_aggregate_trades(self, **params) -> Dict:
"""Get compressed, aggregate trades. Trades that fill at the time,
from the same order, with the same price will have the quantity aggregated.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#compressedaggregate-trades-list
:param symbol: required
:type symbol: str
:param fromId: ID to get aggregate trades from INCLUSIVE.
:type fromId: str
:param startTime: Timestamp in ms to get aggregate trades from INCLUSIVE.
:type startTime: int
:param endTime: Timestamp in ms to get aggregate trades until INCLUSIVE.
:type endTime: int
:param limit: Default 500; max 1000.
:type limit: int
:returns: API response
.. code-block:: python
[
{
"a": 26129, # Aggregate tradeId
"p": "0.01633102", # Price
"q": "4.70443515", # Quantity
"f": 27781, # First tradeId
"l": 27781, # Last tradeId
"T": 1498793709153, # Timestamp
"m": true, # Was the buyer the maker?
"M": true # Was the trade the best price match?
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("aggTrades", data=params)
```
Iterate over aggregate trade data from (start\_time or last\_id) to
the end of the history so far.
If start\_time is specified, start with the first trade after
start\_time. Meant to initialise a local cache of trade data.
If last\_id is specified, start with the trade after it. This is meant
for updating a pre-existing local trade data cache.
Only allows start\_str or last\_id—not both. Not guaranteed to work
right if you're running more than one of these simultaneously. You
will probably hit your rate limit.
See dateparser docs for valid start and end string formats [http://dateparser.readthedocs.io/en/latest/](http://dateparser.readthedocs.io/en/latest/)
If using offset strings for dates add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"
:param symbol: Symbol string e.g. ETHBTC
:type symbol: str
:param start\_str: Start date string in UTC format or timestamp in milliseconds. The iterator will
return the first trade occurring later than this time.
:type start\_str: str|int
:param last\_id: aggregate trade ID of the last known aggregate trade.
Not a regular trade ID. See [https://binance-docs.github.io/apidocs/spot/en/#compressed-aggregate-trades-list](https://binance-docs.github.io/apidocs/spot/en/#compressed-aggregate-trades-list)
:returns: an iterator of JSON objects, one per trade. The format of
each object is identical to Client.aggregate\_trades().
:type last\_id: int
```python
def aggregate_trade_iter(self, symbol: str, start_str=None, last_id=None):
"""Iterate over aggregate trade data from (start_time or last_id) to
the end of the history so far.
If start_time is specified, start with the first trade after
start_time. Meant to initialise a local cache of trade data.
If last_id is specified, start with the trade after it. This is meant
for updating a pre-existing local trade data cache.
Only allows start_str or last_id—not both. Not guaranteed to work
right if you're running more than one of these simultaneously. You
will probably hit your rate limit.
See dateparser docs for valid start and end string formats http://dateparser.readthedocs.io/en/latest/
If using offset strings for dates add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"
:param symbol: Symbol string e.g. ETHBTC
:type symbol: str
:param start_str: Start date string in UTC format or timestamp in milliseconds. The iterator will
return the first trade occurring later than this time.
:type start_str: str|int
:param last_id: aggregate trade ID of the last known aggregate trade.
Not a regular trade ID. See https://binance-docs.github.io/apidocs/spot/en/#compressed-aggregate-trades-list
:returns: an iterator of JSON objects, one per trade. The format of
each object is identical to Client.aggregate_trades().
:type last_id: int
"""
if start_str is not None and last_id is not None:
raise ValueError(
"start_time and last_id may not be simultaneously specified."
)
# If there's no last_id, get one.
if last_id is None:
# Without a last_id, we actually need the first trade. Normally,
# we'd get rid of it. See the next loop.
if start_str is None:
trades = self.get_aggregate_trades(symbol=symbol, fromId=0)
else:
# The difference between startTime and endTime should be less
# or equal than an hour and the result set should contain at
# least one trade.
start_ts = convert_ts_str(start_str)
# If the resulting set is empty (i.e. no trades in that interval)
# then we just move forward hour by hour until we find at least one
# trade or reach present moment
while True:
end_ts = start_ts + (60 * 60 * 1000)
trades = self.get_aggregate_trades(
symbol=symbol, startTime=start_ts, endTime=end_ts
)
if len(trades) > 0:
break
# If we reach present moment and find no trades then there is
# nothing to iterate, so we're done
if end_ts > int(time.time() * 1000):
return
start_ts = end_ts
for t in trades:
yield t
last_id = trades[-1][self.AGG_ID]
while True:
# There is no need to wait between queries, to avoid hitting the
# rate limit. We're using blocking IO, and as long as we're the
# only thread running calls like this, Binance will automatically
# add the right delay time on their end, forcing us to wait for
# data. That really simplifies this function's job. Binance is
# fucking awesome.
trades = self.get_aggregate_trades(symbol=symbol, fromId=last_id)
# fromId=n returns a set starting with id n, but we already have
# that one. So get rid of the first item in the result set.
trades = trades[1:]
if len(trades) == 0:
return
for t in trades:
yield t
last_id = trades[-1][self.AGG_ID]
```
Kline/candlestick bars for a symbol with UI enhancements. Klines are uniquely identified by their open time.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#uiklines](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#uiklines)
:param symbol: required
:type symbol: str
:param interval: required - The interval for the klines (e.g., 1m, 3m, 5m, etc.)
:type interval: str
:param limit: optional - Default 500; max 1000.
:type limit: int
:param startTime: optional - Start time in milliseconds
:type startTime: int
:param endTime: optional - End time in milliseconds
:type endTime: int
:returns: API response
.. code-block:: python
\[
\[
1499040000000, # Open time
"0.01634790", # Open
"0.80000000", # High
"0.01575800", # Low
"0.01577100", # Close
"148976.11427815", # Volume
1499644799999, # Close time
"2434.19055334", # Quote asset volume
308, # Number of trades
"1756.87402397", # Taker buy base asset volume
"28.46694368", # Taker buy quote asset volume
"17928899.62484339" # Can be ignored
]
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_ui_klines(self, **params) -> Dict:
"""Kline/candlestick bars for a symbol with UI enhancements. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#uiklines
:param symbol: required
:type symbol: str
:param interval: required - The interval for the klines (e.g., 1m, 3m, 5m, etc.)
:type interval: str
:param limit: optional - Default 500; max 1000.
:type limit: int
:param startTime: optional - Start time in milliseconds
:type startTime: int
:param endTime: optional - End time in milliseconds
:type endTime: int
:returns: API response
.. code-block:: python
[
[
1499040000000, # Open time
"0.01634790", # Open
"0.80000000", # High
"0.01575800", # Low
"0.01577100", # Close
"148976.11427815", # Volume
1499644799999, # Close time
"2434.19055334", # Quote asset volume
308, # Number of trades
"1756.87402397", # Taker buy base asset volume
"28.46694368", # Taker buy quote asset volume
"17928899.62484339" # Can be ignored
]
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("uiKlines", data=params)
```
Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data)
:param symbol: required
:type symbol: str
:param interval: -
:type interval: str
:param limit: - Default 500; max 1000.
:type limit: int
:param startTime:
:type startTime: int
:param endTime:
:type endTime: int
:returns: API response
.. code-block:: python
\[
\[
1499040000000, # Open time
"0.01634790", # Open
"0.80000000", # High
"0.01575800", # Low
"0.01577100", # Close
"148976.11427815", # Volume
1499644799999, # Close time
"2434.19055334", # Quote asset volume
308, # Number of trades
"1756.87402397", # Taker buy base asset volume
"28.46694368", # Taker buy quote asset volume
"17928899.62484339" # Can be ignored
]
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_klines(self, **params) -> Dict:
"""Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data
:param symbol: required
:type symbol: str
:param interval: -
:type interval: str
:param limit: - Default 500; max 1000.
:type limit: int
:param startTime:
:type startTime: int
:param endTime:
:type endTime: int
:returns: API response
.. code-block:: python
[
[
1499040000000, # Open time
"0.01634790", # Open
"0.80000000", # High
"0.01575800", # Low
"0.01577100", # Close
"148976.11427815", # Volume
1499644799999, # Close time
"2434.19055334", # Quote asset volume
308, # Number of trades
"1756.87402397", # Taker buy base asset volume
"28.46694368", # Taker buy quote asset volume
"17928899.62484339" # Can be ignored
]
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("klines", data=params)
```
Get klines of spot (get\_klines) or futures (futures\_klines) endpoints.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data)
[https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
:param klines\_type: Historical klines type: SPOT or FUTURES
:type klines\_type: HistoricalKlinesType
:return: klines, see get\_klines
```python
def _klines(
self, klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT, **params
) -> Dict:
"""Get klines of spot (get_klines) or futures (futures_klines) endpoints.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data
https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
:param klines_type: Historical klines type: SPOT or FUTURES
:type klines_type: HistoricalKlinesType
:return: klines, see get_klines
"""
if "endTime" in params and not params["endTime"]:
del params["endTime"]
if HistoricalKlinesType.SPOT == klines_type:
return self.get_klines(**params)
elif HistoricalKlinesType.FUTURES == klines_type:
return self.futures_klines(**params)
elif HistoricalKlinesType.FUTURES_COIN == klines_type:
return self.futures_coin_klines(**params)
elif HistoricalKlinesType.FUTURES_MARK_PRICE == klines_type:
return self.futures_mark_price_klines(**params)
elif HistoricalKlinesType.FUTURES_INDEX_PRICE == klines_type:
return self.futures_index_price_klines(**params)
elif HistoricalKlinesType.FUTURES_COIN_MARK_PRICE == klines_type:
return self.futures_coin_mark_price_klines(**params)
elif HistoricalKlinesType.FUTURES_COIN_INDEX_PRICE == klines_type:
return self.futures_coin_index_price_klines(**params)
else:
raise NotImplementedException(klines_type)
```
Get the earliest valid open timestamp from Binance
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data)
[https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param klines\_type: Historical klines type: SPOT or FUTURES
:type klines\_type: HistoricalKlinesType
:return: first valid timestamp
```python
def _get_earliest_valid_timestamp(
self,
symbol,
interval,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
"""Get the earliest valid open timestamp from Binance
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data
https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param klines_type: Historical klines type: SPOT or FUTURES
:type klines_type: HistoricalKlinesType
:return: first valid timestamp
"""
kline = self._klines(
klines_type=klines_type,
symbol=symbol,
interval=interval,
limit=1,
startTime=0,
endTime=int(time.time() * 1000),
)
return kline[0][0]
```
Get Historical Klines from Binance
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data)
[https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start\_str: optional - start date string in UTC format or timestamp in milliseconds
:type start\_str: str|int
:param end\_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end\_str: str|int
:param limit: Default 1000; max 1000.
:type limit: int
:param klines\_type: Historical klines type: SPOT or FUTURES
:type klines\_type: HistoricalKlinesType
:return: list of OHLCV values (Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore)
```python
def get_historical_klines(
self,
symbol,
interval,
start_str=None,
end_str=None,
limit=None,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
"""Get Historical Klines from Binance
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data
https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start_str: optional - start date string in UTC format or timestamp in milliseconds
:type start_str: str|int
:param end_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end_str: str|int
:param limit: Default 1000; max 1000.
:type limit: int
:param klines_type: Historical klines type: SPOT or FUTURES
:type klines_type: HistoricalKlinesType
:return: list of OHLCV values (Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore)
"""
return self._historical_klines(
symbol,
interval,
start_str=start_str,
end_str=end_str,
limit=limit,
klines_type=klines_type,
)
```
Get Historical Klines from Binance (spot or futures)
See dateparser docs for valid start and end string formats [https://dateparser.readthedocs.io/en/latest/](https://dateparser.readthedocs.io/en/latest/)
If using offset strings for dates add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start\_str: optional - start date string in UTC format or timestamp in milliseconds
:type start\_str: str|int
:param end\_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end\_str: None|str|int
:param limit: Default 1000; max 1000.
:type limit: int
:param klines\_type: Historical klines type: SPOT or FUTURES
:type klines\_type: HistoricalKlinesType
:return: list of OHLCV values (Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore)
```python
def _historical_klines(
self,
symbol,
interval,
start_str=None,
end_str=None,
limit=None,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
"""Get Historical Klines from Binance (spot or futures)
See dateparser docs for valid start and end string formats https://dateparser.readthedocs.io/en/latest/
If using offset strings for dates add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start_str: optional - start date string in UTC format or timestamp in milliseconds
:type start_str: str|int
:param end_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end_str: None|str|int
:param limit: Default 1000; max 1000.
:type limit: int
:param klines_type: Historical klines type: SPOT or FUTURES
:type klines_type: HistoricalKlinesType
:return: list of OHLCV values (Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore)
"""
initial_limit_set = True
if limit is None:
limit = 1000
initial_limit_set = False
# init our list
output_data = []
# convert interval to useful value in seconds
timeframe = interval_to_milliseconds(interval)
# if a start time was passed convert it
start_ts = convert_ts_str(start_str)
# establish first available start timestamp
if start_ts is not None:
first_valid_ts = self._get_earliest_valid_timestamp(
symbol, interval, klines_type
)
start_ts = max(start_ts, first_valid_ts)
# if an end time was passed convert it
end_ts = convert_ts_str(end_str)
if end_ts and start_ts and end_ts <= start_ts:
return output_data
idx = 0
while True:
# fetch the klines from start_ts up to max 500 entries or the end_ts if set
temp_data = self._klines(
klines_type=klines_type,
symbol=symbol,
interval=interval,
limit=limit,
startTime=start_ts,
endTime=end_ts,
)
# append this loops data to our output data
if temp_data:
output_data += temp_data
# check if output_data is greater than limit and truncate if needed and break loop
if initial_limit_set and len(output_data) > limit:
output_data = output_data[:limit]
break
# handle the case where exactly the limit amount of data was returned last loop
# check if we received less than the required limit and exit the loop
if not len(temp_data) or len(temp_data) < limit:
# exit the while loop
break
# increment next call by our timeframe
start_ts = temp_data[-1][0] + timeframe
# exit loop if we reached end_ts before reaching klines
if end_ts and start_ts >= end_ts:
break
# sleep after every 3rd call to be kind to the API
idx += 1
if idx % 3 == 0:
time.sleep(1)
return output_data
```
Get Historical Klines generator from Binance
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data)
[https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start\_str: optional - Start date string in UTC format or timestamp in milliseconds
:type start\_str: str|int
:param end\_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end\_str: str|int
:param limit: amount of candles to return per request (default 1000)
:type limit: int
:param klines\_type: Historical klines type: SPOT or FUTURES
:type klines\_type: HistoricalKlinesType
:return: generator of OHLCV values
```python
def get_historical_klines_generator(
self,
symbol,
interval,
start_str=None,
end_str=None,
limit=None,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
"""Get Historical Klines generator from Binance
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#klinecandlestick-data
https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start_str: optional - Start date string in UTC format or timestamp in milliseconds
:type start_str: str|int
:param end_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end_str: str|int
:param limit: amount of candles to return per request (default 1000)
:type limit: int
:param klines_type: Historical klines type: SPOT or FUTURES
:type klines_type: HistoricalKlinesType
:return: generator of OHLCV values
"""
return self._historical_klines_generator(
symbol, interval, start_str, end_str, limit, klines_type=klines_type
)
```
Get Historical Klines generator from Binance (spot or futures)
See dateparser docs for valid start and end string formats [https://dateparser.readthedocs.io/en/latest/](https://dateparser.readthedocs.io/en/latest/)
If using offset strings for dates add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start\_str: optional - Start date string in UTC format or timestamp in milliseconds
:type start\_str: str|int
:param end\_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end\_str: str|int
:param klines\_type: Historical klines type: SPOT or FUTURES
:type klines\_type: HistoricalKlinesType
:return: generator of OHLCV values
```python
def _historical_klines_generator(
self,
symbol,
interval,
start_str=None,
end_str=None,
limit=None,
klines_type: HistoricalKlinesType = HistoricalKlinesType.SPOT,
):
"""Get Historical Klines generator from Binance (spot or futures)
See dateparser docs for valid start and end string formats https://dateparser.readthedocs.io/en/latest/
If using offset strings for dates add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start_str: optional - Start date string in UTC format or timestamp in milliseconds
:type start_str: str|int
:param end_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end_str: str|int
:param klines_type: Historical klines type: SPOT or FUTURES
:type klines_type: HistoricalKlinesType
:return: generator of OHLCV values
"""
initial_limit_set = True
if limit is None:
limit = 1000
initial_limit_set = False
# convert interval to useful value in seconds
timeframe = interval_to_milliseconds(interval)
# if a start time was passed convert it
start_ts = convert_ts_str(start_str)
# establish first available start timestamp
if start_ts is not None:
first_valid_ts = self._get_earliest_valid_timestamp(
symbol, interval, klines_type
)
start_ts = max(start_ts, first_valid_ts)
# if an end time was passed convert it
end_ts = convert_ts_str(end_str)
if end_ts and start_ts and end_ts <= start_ts:
return
idx = 0
while True:
# fetch the klines from start_ts up to max 500 entries or the end_ts if set
output_data = self._klines(
klines_type=klines_type,
symbol=symbol,
interval=interval,
limit=limit,
startTime=start_ts,
endTime=end_ts,
)
# yield data
if output_data:
for o in output_data:
yield o
# handle the case where exactly the limit amount of data was returned last loop
# check if we received less than the required limit and exit the loop
if not len(output_data) or len(output_data) < limit:
# exit the while loop
break
# set our start timestamp using the last value in the array
# increment next call by our timeframe
start_ts = output_data[-1][0] + timeframe
# exit loop if we reached end_ts before reaching klines
if end_ts and start_ts >= end_ts:
break
# sleep after every 3rd call to be kind to the API
idx += 1
if idx % 3 == 0:
time.sleep(1)
```
Current average price for a symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#current-average-price](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#current-average-price)
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
\{
"mins": 5,
"price": "9.35751834"
}
```python
def get_avg_price(self, **params):
"""Current average price for a symbol.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#current-average-price
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
{
"mins": 5,
"price": "9.35751834"
}
"""
return self._get("avgPrice", data=params)
```
24 hour price change statistics.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#24hr-ticker-price-change-statistics](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#24hr-ticker-price-change-statistics)
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
\{
"priceChange": "-94.99999800",
"priceChangePercent": "-95.960",
"weightedAvgPrice": "0.29628482",
"prevClosePrice": "0.10002000",
"lastPrice": "4.00000200",
"bidPrice": "4.00000000",
"askPrice": "4.00000200",
"openPrice": "99.00000000",
"highPrice": "100.00000000",
"lowPrice": "0.10000000",
"volume": "8913.30000000",
"openTime": 1499783499040,
"closeTime": 1499869899040,
"fristId": 28385, # First tradeId
"lastId": 28460, # Last tradeId
"count": 76 # Trade count
}
OR
.. code-block:: python
\[
\{
"priceChange": "-94.99999800",
"priceChangePercent": "-95.960",
"weightedAvgPrice": "0.29628482",
"prevClosePrice": "0.10002000",
"lastPrice": "4.00000200",
"bidPrice": "4.00000000",
"askPrice": "4.00000200",
"openPrice": "99.00000000",
"highPrice": "100.00000000",
"lowPrice": "0.10000000",
"volume": "8913.30000000",
"openTime": 1499783499040,
"closeTime": 1499869899040,
"fristId": 28385, # First tradeId
"lastId": 28460, # Last tradeId
"count": 76 # Trade count
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_ticker(self, **params):
"""24 hour price change statistics.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#24hr-ticker-price-change-statistics
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
{
"priceChange": "-94.99999800",
"priceChangePercent": "-95.960",
"weightedAvgPrice": "0.29628482",
"prevClosePrice": "0.10002000",
"lastPrice": "4.00000200",
"bidPrice": "4.00000000",
"askPrice": "4.00000200",
"openPrice": "99.00000000",
"highPrice": "100.00000000",
"lowPrice": "0.10000000",
"volume": "8913.30000000",
"openTime": 1499783499040,
"closeTime": 1499869899040,
"fristId": 28385, # First tradeId
"lastId": 28460, # Last tradeId
"count": 76 # Trade count
}
OR
.. code-block:: python
[
{
"priceChange": "-94.99999800",
"priceChangePercent": "-95.960",
"weightedAvgPrice": "0.29628482",
"prevClosePrice": "0.10002000",
"lastPrice": "4.00000200",
"bidPrice": "4.00000000",
"askPrice": "4.00000200",
"openPrice": "99.00000000",
"highPrice": "100.00000000",
"lowPrice": "0.10000000",
"volume": "8913.30000000",
"openTime": 1499783499040,
"closeTime": 1499869899040,
"fristId": 28385, # First tradeId
"lastId": 28460, # Last tradeId
"count": 76 # Trade count
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("ticker/24hr", data=params)
```
Latest price for a symbol or symbols.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-price-ticker](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-price-ticker)
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
\{
"symbol": "LTCBTC",
"price": "4.00000200"
}
OR
.. code-block:: python
\[
\{
"symbol": "LTCBTC",
"price": "4.00000200"
},
\{
"symbol": "ETHBTC",
"price": "0.07946600"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_symbol_ticker(self, **params):
"""Latest price for a symbol or symbols.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-price-ticker
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
{
"symbol": "LTCBTC",
"price": "4.00000200"
}
OR
.. code-block:: python
[
{
"symbol": "LTCBTC",
"price": "4.00000200"
},
{
"symbol": "ETHBTC",
"price": "0.07946600"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("ticker/price", data=params)
```
Latest price for a symbol or symbols.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#rolling-window-price-change-statistics](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#rolling-window-price-change-statistics)
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
\{
"symbol": "LTCBTC",
"price": "4.00000200"
}
OR
.. code-block:: python
\[
\{
"symbol": "LTCBTC",
"price": "4.00000200"
},
\{
"symbol": "ETHBTC",
"price": "0.07946600"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_symbol_ticker_window(self, **params):
"""Latest price for a symbol or symbols.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#rolling-window-price-change-statistics
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
{
"symbol": "LTCBTC",
"price": "4.00000200"
}
OR
.. code-block:: python
[
{
"symbol": "LTCBTC",
"price": "4.00000200"
},
{
"symbol": "ETHBTC",
"price": "0.07946600"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("ticker", data=params)
```
Latest price for a symbol or symbols.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-order-book-ticker](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-order-book-ticker)
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
\{
"symbol": "LTCBTC",
"bidPrice": "4.00000000",
"bidQty": "431.00000000",
"askPrice": "4.00000200",
"askQty": "9.00000000"
}
OR
.. code-block:: python
\[
\{
"symbol": "LTCBTC",
"bidPrice": "4.00000000",
"bidQty": "431.00000000",
"askPrice": "4.00000200",
"askQty": "9.00000000"
},
\{
"symbol": "ETHBTC",
"bidPrice": "0.07946700",
"bidQty": "9.00000000",
"askPrice": "100000.00000000",
"askQty": "1000.00000000"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_orderbook_ticker(self, **params):
"""Latest price for a symbol or symbols.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#symbol-order-book-ticker
:param symbol:
:type symbol: str
:returns: API response
.. code-block:: python
{
"symbol": "LTCBTC",
"bidPrice": "4.00000000",
"bidQty": "431.00000000",
"askPrice": "4.00000200",
"askQty": "9.00000000"
}
OR
.. code-block:: python
[
{
"symbol": "LTCBTC",
"bidPrice": "4.00000000",
"bidQty": "431.00000000",
"askPrice": "4.00000200",
"askQty": "9.00000000"
},
{
"symbol": "ETHBTC",
"bidPrice": "0.07946700",
"bidQty": "9.00000000",
"askPrice": "100000.00000000",
"askQty": "1000.00000000"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get(
"ticker/bookTicker", data=params
)
```
Send in a new order
Any order with an icebergQty MUST have timeInForce set to GTC.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade)
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param type: required
:type type: str
:param timeInForce: required if limit order
:type timeInForce: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: amount the user wants to spend (when buying) or receive (when selling)
of the quote asset, applicable to MARKET orders
:type quoteOrderQty: decimal
:param price: required
:type price: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP\_LOSS\_LIMIT, and TAKE\_PROFIT\_LIMIT to create an iceberg order.
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
Response ACK:
.. code-block:: python
\{
"symbol":"LTCBTC",
"orderId": 1,
"clientOrderId": "myOrder1" # Will be newClientOrderId
"transactTime": 1499827319559
}
Response RESULT:
.. code-block:: python
\{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "0.00000000",
"origQty": "10.00000000",
"executedQty": "10.00000000",
"cummulativeQuoteQty": "10.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "MARKET",
"side": "SELL"
}
Response FULL:
.. code-block:: python
\{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "0.00000000",
"origQty": "10.00000000",
"executedQty": "10.00000000",
"cummulativeQuoteQty": "10.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "MARKET",
"side": "SELL",
"fills": \[
\{
"price": "4000.00000000",
"qty": "1.00000000",
"commission": "4.00000000",
"commissionAsset": "USDT"
},
\{
"price": "3999.00000000",
"qty": "5.00000000",
"commission": "19.99500000",
"commissionAsset": "USDT"
},
\{
"price": "3998.00000000",
"qty": "2.00000000",
"commission": "7.99600000",
"commissionAsset": "USDT"
},
\{
"price": "3997.00000000",
"qty": "1.00000000",
"commission": "3.99700000",
"commissionAsset": "USDT"
},
\{
"price": "3995.00000000",
"qty": "1.00000000",
"commission": "3.99500000",
"commissionAsset": "USDT"
}
]
}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def create_order(self, **params):
"""Send in a new order
Any order with an icebergQty MUST have timeInForce set to GTC.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param type: required
:type type: str
:param timeInForce: required if limit order
:type timeInForce: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: amount the user wants to spend (when buying) or receive (when selling)
of the quote asset, applicable to MARKET orders
:type quoteOrderQty: decimal
:param price: required
:type price: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
Response ACK:
.. code-block:: python
{
"symbol":"LTCBTC",
"orderId": 1,
"clientOrderId": "myOrder1" # Will be newClientOrderId
"transactTime": 1499827319559
}
Response RESULT:
.. code-block:: python
{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "0.00000000",
"origQty": "10.00000000",
"executedQty": "10.00000000",
"cummulativeQuoteQty": "10.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "MARKET",
"side": "SELL"
}
Response FULL:
.. code-block:: python
{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "0.00000000",
"origQty": "10.00000000",
"executedQty": "10.00000000",
"cummulativeQuoteQty": "10.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "MARKET",
"side": "SELL",
"fills": [
{
"price": "4000.00000000",
"qty": "1.00000000",
"commission": "4.00000000",
"commissionAsset": "USDT"
},
{
"price": "3999.00000000",
"qty": "5.00000000",
"commission": "19.99500000",
"commissionAsset": "USDT"
},
{
"price": "3998.00000000",
"qty": "2.00000000",
"commission": "7.99600000",
"commissionAsset": "USDT"
},
{
"price": "3997.00000000",
"qty": "1.00000000",
"commission": "3.99700000",
"commissionAsset": "USDT"
},
{
"price": "3995.00000000",
"qty": "1.00000000",
"commission": "3.99500000",
"commissionAsset": "USDT"
}
]
}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return self._post("order", True, data=params)
```
Send in a new limit order
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade)
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP\_LOSS\_LIMIT, and TAKE\_PROFIT\_LIMIT to create an iceberg order.
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def order_limit(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
"""Send in a new limit order
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
params.update({"type": self.ORDER_TYPE_LIMIT, "timeInForce": timeInForce})
return self.create_order(**params)
```
Send in a new limit buy order
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade)
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def order_limit_buy(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
"""Send in a new limit buy order
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
params.update({
"side": self.SIDE_BUY,
})
return self.order_limit(timeInForce=timeInForce, **params)
```
Send in a new limit sell order
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade)
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def order_limit_sell(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
"""Send in a new limit sell order
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
params.update({"side": self.SIDE_SELL})
return self.order_limit(timeInForce=timeInForce, **params)
```
Send in a new market order
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade)
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: amount the user wants to spend (when buying) or receive (when selling)
of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def order_market(self, **params):
"""Send in a new market order
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: amount the user wants to spend (when buying) or receive (when selling)
of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
params.update({"type": self.ORDER_TYPE_MARKET})
return self.create_order(**params)
```
Send in a new market buy order
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade)
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to spend of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def order_market_buy(self, **params):
"""Send in a new market buy order
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to spend of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
params.update({"side": self.SIDE_BUY})
return self.order_market(**params)
```
Send in a new market sell order
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade)
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to receive of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def order_market_sell(self, **params):
"""Send in a new market sell order
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-trade
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to receive of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
params.update({"side": self.SIDE_SELL})
return self.order_market(**params)
```
Send in an one-cancels-the-other (OCO) pair, where activation of one order immediately cancels the other.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade)
An OCO has 2 orders called the above order and below order.
One of the orders must be a LIMIT\_MAKER/TAKE\_PROFIT/TAKE\_PROFIT\_LIMIT order and the other must be STOP\_LOSS or STOP\_LOSS\_LIMIT order.
Price restrictions:
If the OCO is on the SELL side:
LIMIT\_MAKER/TAKE\_PROFIT\_LIMIT price > Last Traded Price > STOP\_LOSS/STOP\_LOSS\_LIMIT stopPrice
TAKE\_PROFIT stopPrice > Last Traded Price > STOP\_LOSS/STOP\_LOSS\_LIMIT stopPrice
If the OCO is on the BUY side:
LIMIT\_MAKER/TAKE\_PROFIT\_LIMIT price \< Last Traded Price \< stopPrice
TAKE\_PROFIT stopPrice \< Last Traded Price \< STOP\_LOSS/STOP\_LOSS\_LIMIT stopPrice
Weight: 1
:param symbol: required
:type symbol: str
:param listClientOrderId: Arbitrary unique ID among open order lists. Automatically generated if not sent.
:type listClientOrderId: str
:param side: required - BUY or SELL
:type side: str
:param quantity: required - Quantity for both orders of the order list
:type quantity: decimal
:param aboveType: required - STOP\_LOSS\_LIMIT, STOP\_LOSS, LIMIT\_MAKER, TAKE\_PROFIT, TAKE\_PROFIT\_LIMIT
:type aboveType: str
:param aboveClientOrderId: Arbitrary unique ID among open orders for the above order
:type aboveClientOrderId: str
:param aboveIcebergQty: Note that this can only be used if aboveTimeInForce is GTC
:type aboveIcebergQty: decimal
:param abovePrice: Can be used if aboveType is STOP\_LOSS\_LIMIT, LIMIT\_MAKER, or TAKE\_PROFIT\_LIMIT
:type abovePrice: decimal
:param aboveStopPrice: Can be used if aboveType is STOP\_LOSS, STOP\_LOSS\_LIMIT, TAKE\_PROFIT, TAKE\_PROFIT\_LIMIT
:type aboveStopPrice: decimal
:param aboveTrailingDelta: See Trailing Stop order FAQ
:type aboveTrailingDelta: int
:param aboveTimeInForce: Required if aboveType is STOP\_LOSS\_LIMIT or TAKE\_PROFIT\_LIMIT
:type aboveTimeInForce: str
:param aboveStrategyId: Arbitrary numeric value identifying the above order within an order strategy
:type aboveStrategyId: int
:param aboveStrategyType: Arbitrary numeric value identifying the above order strategy (>= 1000000)
:type aboveStrategyType: int
:param belowType: required - STOP\_LOSS, STOP\_LOSS\_LIMIT, TAKE\_PROFIT, TAKE\_PROFIT\_LIMIT
:type belowType: str
:param belowClientOrderId: Arbitrary unique ID among open orders for the below order
:type belowClientOrderId: str
:param belowIcebergQty: Note that this can only be used if belowTimeInForce is GTC
:type belowIcebergQty: decimal
:param belowPrice: Can be used if belowType is STOP\_LOSS\_LIMIT, LIMIT\_MAKER, or TAKE\_PROFIT\_LIMIT
:type belowPrice: decimal
:param belowStopPrice: Can be used if belowType is STOP\_LOSS, STOP\_LOSS\_LIMIT, TAKE\_PROFIT or TAKE\_PROFIT\_LIMIT
:type belowStopPrice: decimal
:param belowTrailingDelta: See Trailing Stop order FAQ
:type belowTrailingDelta: int
:param belowTimeInForce: Required if belowType is STOP\_LOSS\_LIMIT or TAKE\_PROFIT\_LIMIT
:type belowTimeInForce: str
:param belowStrategyId: Arbitrary numeric value identifying the below order within an order strategy
:type belowStrategyId: int
:param belowStrategyType: Arbitrary numeric value identifying the below order strategy (>= 1000000)
:type belowStrategyType: int
:param newOrderRespType: Select response format: ACK, RESULT, FULL
:type newOrderRespType: str
:param selfTradePreventionMode: The allowed enums is dependent on what is configured on the symbol
:type selfTradePreventionMode: str
:param recvWindow: The value cannot be greater than 60000
:type recvWindow: int
:param timestamp: required
:type timestamp: int
:returns: API response
\{
"orderListId": 1,
"contingencyType": "OCO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "lH1YDkuQKWiXVXHPSKYEIp",
"transactionTime": 1710485608839,
"symbol": "LTCBTC",
"orders": \[
\{
"symbol": "LTCBTC",
"orderId": 10,
"clientOrderId": "44nZvqpemY7sVYgPYbvPih"
},
\{
"symbol": "LTCBTC",
"orderId": 11,
"clientOrderId": "NuMp0nVYnciDiFmVqfpBqK"
}
],
"orderReports": \[
\{
"symbol": "LTCBTC",
"orderId": 10,
"orderListId": 1,
"clientOrderId": "44nZvqpemY7sVYgPYbvPih",
"transactTime": 1710485608839,
"price": "1.00000000",
"origQty": "5.00000000",
"executedQty": "0.00000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "STOP\_LOSS\_LIMIT",
"side": "SELL",
"stopPrice": "1.00000000",
"workingTime": -1,
"icebergQty": "1.00000000",
"selfTradePreventionMode": "NONE"
},
\{
"symbol": "LTCBTC",
"orderId": 11,
"orderListId": 1,
"clientOrderId": "NuMp0nVYnciDiFmVqfpBqK",
"transactTime": 1710485608839,
"price": "3.00000000",
"origQty": "5.00000000",
"executedQty": "0.00000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT\_MAKER",
"side": "SELL",
"workingTime": 1710485608839,
"selfTradePreventionMode": "NONE"
}
]
}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException,
BinanceOrderMinAmountException, BinanceOrderMinPriceException,
BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException,
BinanceOrderInactiveSymbolException
```python
def create_oco_order(self, **params):
"""Send in an one-cancels-the-other (OCO) pair, where activation of one order immediately cancels the other.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade
An OCO has 2 orders called the above order and below order.
One of the orders must be a LIMIT_MAKER/TAKE_PROFIT/TAKE_PROFIT_LIMIT order and the other must be STOP_LOSS or STOP_LOSS_LIMIT order.
Price restrictions:
If the OCO is on the SELL side:
LIMIT_MAKER/TAKE_PROFIT_LIMIT price > Last Traded Price > STOP_LOSS/STOP_LOSS_LIMIT stopPrice
TAKE_PROFIT stopPrice > Last Traded Price > STOP_LOSS/STOP_LOSS_LIMIT stopPrice
If the OCO is on the BUY side:
LIMIT_MAKER/TAKE_PROFIT_LIMIT price < Last Traded Price < stopPrice
TAKE_PROFIT stopPrice < Last Traded Price < STOP_LOSS/STOP_LOSS_LIMIT stopPrice
Weight: 1
:param symbol: required
:type symbol: str
:param listClientOrderId: Arbitrary unique ID among open order lists. Automatically generated if not sent.
:type listClientOrderId: str
:param side: required - BUY or SELL
:type side: str
:param quantity: required - Quantity for both orders of the order list
:type quantity: decimal
:param aboveType: required - STOP_LOSS_LIMIT, STOP_LOSS, LIMIT_MAKER, TAKE_PROFIT, TAKE_PROFIT_LIMIT
:type aboveType: str
:param aboveClientOrderId: Arbitrary unique ID among open orders for the above order
:type aboveClientOrderId: str
:param aboveIcebergQty: Note that this can only be used if aboveTimeInForce is GTC
:type aboveIcebergQty: decimal
:param abovePrice: Can be used if aboveType is STOP_LOSS_LIMIT, LIMIT_MAKER, or TAKE_PROFIT_LIMIT
:type abovePrice: decimal
:param aboveStopPrice: Can be used if aboveType is STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT
:type aboveStopPrice: decimal
:param aboveTrailingDelta: See Trailing Stop order FAQ
:type aboveTrailingDelta: int
:param aboveTimeInForce: Required if aboveType is STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT
:type aboveTimeInForce: str
:param aboveStrategyId: Arbitrary numeric value identifying the above order within an order strategy
:type aboveStrategyId: int
:param aboveStrategyType: Arbitrary numeric value identifying the above order strategy (>= 1000000)
:type aboveStrategyType: int
:param belowType: required - STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT
:type belowType: str
:param belowClientOrderId: Arbitrary unique ID among open orders for the below order
:type belowClientOrderId: str
:param belowIcebergQty: Note that this can only be used if belowTimeInForce is GTC
:type belowIcebergQty: decimal
:param belowPrice: Can be used if belowType is STOP_LOSS_LIMIT, LIMIT_MAKER, or TAKE_PROFIT_LIMIT
:type belowPrice: decimal
:param belowStopPrice: Can be used if belowType is STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT or TAKE_PROFIT_LIMIT
:type belowStopPrice: decimal
:param belowTrailingDelta: See Trailing Stop order FAQ
:type belowTrailingDelta: int
:param belowTimeInForce: Required if belowType is STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT
:type belowTimeInForce: str
:param belowStrategyId: Arbitrary numeric value identifying the below order within an order strategy
:type belowStrategyId: int
:param belowStrategyType: Arbitrary numeric value identifying the below order strategy (>= 1000000)
:type belowStrategyType: int
:param newOrderRespType: Select response format: ACK, RESULT, FULL
:type newOrderRespType: str
:param selfTradePreventionMode: The allowed enums is dependent on what is configured on the symbol
:type selfTradePreventionMode: str
:param recvWindow: The value cannot be greater than 60000
:type recvWindow: int
:param timestamp: required
:type timestamp: int
:returns: API response
{
"orderListId": 1,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "lH1YDkuQKWiXVXHPSKYEIp",
"transactionTime": 1710485608839,
"symbol": "LTCBTC",
"orders": [
{
"symbol": "LTCBTC",
"orderId": 10,
"clientOrderId": "44nZvqpemY7sVYgPYbvPih"
},
{
"symbol": "LTCBTC",
"orderId": 11,
"clientOrderId": "NuMp0nVYnciDiFmVqfpBqK"
}
],
"orderReports": [
{
"symbol": "LTCBTC",
"orderId": 10,
"orderListId": 1,
"clientOrderId": "44nZvqpemY7sVYgPYbvPih",
"transactTime": 1710485608839,
"price": "1.00000000",
"origQty": "5.00000000",
"executedQty": "0.00000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "STOP_LOSS_LIMIT",
"side": "SELL",
"stopPrice": "1.00000000",
"workingTime": -1,
"icebergQty": "1.00000000",
"selfTradePreventionMode": "NONE"
},
{
"symbol": "LTCBTC",
"orderId": 11,
"orderListId": 1,
"clientOrderId": "NuMp0nVYnciDiFmVqfpBqK",
"transactTime": 1710485608839,
"price": "3.00000000",
"origQty": "5.00000000",
"executedQty": "0.00000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT_MAKER",
"side": "SELL",
"workingTime": 1710485608839,
"selfTradePreventionMode": "NONE"
}
]
}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException,
BinanceOrderMinAmountException, BinanceOrderMinPriceException,
BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException,
BinanceOrderInactiveSymbolException
"""
if "listClientOrderId" not in params:
params["listClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return self._post("orderList/oco", True, data=params)
```
Send in a new OCO buy order
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade)
:param symbol: required
:type symbol: str
:param listClientOrderId: A unique id for the list order. Automatically generated if not sent.
:type listClientOrderId: str
:param quantity: required
:type quantity: decimal
:param limitClientOrderId: A unique id for the limit order. Automatically generated if not sent.
:type limitClientOrderId: str
:param price: required
:type price: str
:param limitIcebergQty: Used to make the LIMIT\_MAKER leg an iceberg order.
:type limitIcebergQty: decimal
:param stopClientOrderId: A unique id for the stop order. Automatically generated if not sent.
:type stopClientOrderId: str
:param stopPrice: required
:type stopPrice: str
:param stopLimitPrice: If provided, stopLimitTimeInForce is required.
:type stopLimitPrice: str
:param stopIcebergQty: Used with STOP\_LOSS\_LIMIT leg to make an iceberg order.
:type stopIcebergQty: decimal
:param stopLimitTimeInForce: Valid values are GTC/FOK/IOC.
:type stopLimitTimeInForce: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See OCO order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def order_oco_buy(self, **params):
"""Send in a new OCO buy order
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade
:param symbol: required
:type symbol: str
:param listClientOrderId: A unique id for the list order. Automatically generated if not sent.
:type listClientOrderId: str
:param quantity: required
:type quantity: decimal
:param limitClientOrderId: A unique id for the limit order. Automatically generated if not sent.
:type limitClientOrderId: str
:param price: required
:type price: str
:param limitIcebergQty: Used to make the LIMIT_MAKER leg an iceberg order.
:type limitIcebergQty: decimal
:param stopClientOrderId: A unique id for the stop order. Automatically generated if not sent.
:type stopClientOrderId: str
:param stopPrice: required
:type stopPrice: str
:param stopLimitPrice: If provided, stopLimitTimeInForce is required.
:type stopLimitPrice: str
:param stopIcebergQty: Used with STOP_LOSS_LIMIT leg to make an iceberg order.
:type stopIcebergQty: decimal
:param stopLimitTimeInForce: Valid values are GTC/FOK/IOC.
:type stopLimitTimeInForce: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See OCO order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
params.update({"side": self.SIDE_BUY})
return self.create_oco_order(**params)
```
Send in a new OCO sell order
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade)
:param symbol: required
:type symbol: str
:param listClientOrderId: A unique id for the list order. Automatically generated if not sent.
:type listClientOrderId: str
:param quantity: required
:type quantity: decimal
:param limitClientOrderId: A unique id for the limit order. Automatically generated if not sent.
:type limitClientOrderId: str
:param price: required
:type price: str
:param limitIcebergQty: Used to make the LIMIT\_MAKER leg an iceberg order.
:type limitIcebergQty: decimal
:param stopClientOrderId: A unique id for the stop order. Automatically generated if not sent.
:type stopClientOrderId: str
:param stopPrice: required
:type stopPrice: str
:param stopLimitPrice: If provided, stopLimitTimeInForce is required.
:type stopLimitPrice: str
:param stopIcebergQty: Used with STOP\_LOSS\_LIMIT leg to make an iceberg order.
:type stopIcebergQty: decimal
:param stopLimitTimeInForce: Valid values are GTC/FOK/IOC.
:type stopLimitTimeInForce: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See OCO order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def order_oco_sell(self, **params):
"""Send in a new OCO sell order
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#new-order-list---oco-trade
:param symbol: required
:type symbol: str
:param listClientOrderId: A unique id for the list order. Automatically generated if not sent.
:type listClientOrderId: str
:param quantity: required
:type quantity: decimal
:param limitClientOrderId: A unique id for the limit order. Automatically generated if not sent.
:type limitClientOrderId: str
:param price: required
:type price: str
:param limitIcebergQty: Used to make the LIMIT_MAKER leg an iceberg order.
:type limitIcebergQty: decimal
:param stopClientOrderId: A unique id for the stop order. Automatically generated if not sent.
:type stopClientOrderId: str
:param stopPrice: required
:type stopPrice: str
:param stopLimitPrice: If provided, stopLimitTimeInForce is required.
:type stopLimitPrice: str
:param stopIcebergQty: Used with STOP_LOSS_LIMIT leg to make an iceberg order.
:type stopIcebergQty: decimal
:param stopLimitTimeInForce: Valid values are GTC/FOK/IOC.
:type stopLimitTimeInForce: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
See OCO order endpoint for full response options
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
params.update({"side": self.SIDE_SELL})
return self.create_oco_order(**params)
```
Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#test-new-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#test-new-order-trade)
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param type: required
:type type: str
:param timeInForce: required if limit order
:type timeInForce: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: The number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
```python
def create_test_order(self, **params):
"""Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#test-new-order-trade
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param type: required
:type type: str
:param timeInForce: required if limit order
:type timeInForce: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: The number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException, BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException, BinanceOrderInactiveSymbolException
"""
return self._post("order/test", True, data=params)
```
Check an order's status. Either orderId or origClientOrderId must be sent.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-order-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-order-user_data)
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param origClientOrderId: optional
:type origClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"symbol": "LTCBTC",
"orderId": 1,
"clientOrderId": "myOrder1",
"price": "0.1",
"origQty": "1.0",
"executedQty": "0.0",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"stopPrice": "0.0",
"icebergQty": "0.0",
"time": 1499827319559
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_order(self, **params):
"""Check an order's status. Either orderId or origClientOrderId must be sent.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-order-user_data
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param origClientOrderId: optional
:type origClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"symbol": "LTCBTC",
"orderId": 1,
"clientOrderId": "myOrder1",
"price": "0.1",
"origQty": "1.0",
"executedQty": "0.0",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"stopPrice": "0.0",
"icebergQty": "0.0",
"time": 1499827319559
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("order", True, data=params)
```
Get all account orders; active, canceled, or filled.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#all-orders-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#all-orders-user_data)
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: Default 500; max 1000.
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"symbol": "LTCBTC",
"orderId": 1,
"clientOrderId": "myOrder1",
"price": "0.1",
"origQty": "1.0",
"executedQty": "0.0",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"stopPrice": "0.0",
"icebergQty": "0.0",
"time": 1499827319559
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_all_orders(self, **params):
"""Get all account orders; active, canceled, or filled.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#all-orders-user_data
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: Default 500; max 1000.
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"symbol": "LTCBTC",
"orderId": 1,
"clientOrderId": "myOrder1",
"price": "0.1",
"origQty": "1.0",
"executedQty": "0.0",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"stopPrice": "0.0",
"icebergQty": "0.0",
"time": 1499827319559
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("allOrders", True, data=params)
```
Cancel an active order. Either orderId or origClientOrderId must be sent.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-order-trade)
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param origClientOrderId: optional
:type origClientOrderId: str
:param newClientOrderId: Used to uniquely identify this cancel. Automatically generated by default.
:type newClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"symbol": "LTCBTC",
"origClientOrderId": "myOrder1",
"orderId": 1,
"clientOrderId": "cancelMyOrder1"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def cancel_order(self, **params):
"""Cancel an active order. Either orderId or origClientOrderId must be sent.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-order-trade
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param origClientOrderId: optional
:type origClientOrderId: str
:param newClientOrderId: Used to uniquely identify this cancel. Automatically generated by default.
:type newClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"symbol": "LTCBTC",
"origClientOrderId": "myOrder1",
"orderId": 1,
"clientOrderId": "cancelMyOrder1"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._delete("order", True, data=params)
```
Cancel all open orders on a symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-all-open-orders-on-a-symbol-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-all-open-orders-on-a-symbol-trade)
:param symbol: required
:type symbol: str
:returns: API response
```python
def cancel_all_open_orders(self, **params):
"""
Cancel all open orders on a symbol.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-all-open-orders-on-a-symbol-trade
:param symbol: required
:type symbol: str
:returns: API response
"""
return self._delete("openOrders", True, data=params)
```
Cancels an existing order and places a new order on the same symbol.
Filters and Order Count are evaluated before the processing of the cancellation and order placement occurs.
A new order that was not attempted (i.e. when newOrderResult: NOT\_ATTEMPTED), will still increase the order count by 1.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-an-existing-order-and-send-a-new-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-an-existing-order-and-send-a-new-order-trade)
:param symbol: required
:type symbol: str
:param side: required
:type side: enum
:param type: required
:type type: enum
:param cancelReplaceMode: required - STOP\_ON\_FAILURE or ALLOW\_FAILURE
:type cancelReplaceMode: enum
:param timeInForce: optional
:type timeInForce: enum
:param quantity: optional
:type quantity: decimal
:param quoteOrderQty: optional
:type quoteOrderQty: decimal
:param price: optional
:type price: decimal
:param cancelNewClientOrderId: optional - Used to uniquely identify this cancel. Automatically generated by default.
:type cancelNewClientOrderId: str
:param cancelOrigClientOrderId: optional - Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
:type cancelOrigClientOrderId: str
:param cancelOrderId: optional - Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
:type cancelOrderId: long
:param newClientOrderId: optional - Used to identify the new order.
:type newClientOrderId: str
:param strategyId: optional
:type strategyId: int
:param strategyType: optional - The value cannot be less than 1000000.
:type strategyType: int
:param stopPrice: optional
:type stopPrice: decimal
:param trailingDelta: optional
:type trailingDelta: long
:param icebergQty: optional
:type icebergQty: decimal
:param newOrderRespType: optional - ACK, RESULT or FULL. MARKET and LIMIT orders types default to FULL; all other orders default to ACK
:type newOrderRespType: enum
:param selfTradePreventionMode: optional - EXPIRE\_TAKER, EXPIRE\_MAKER, EXPIRE\_BOTH or NONE.
:type selfTradePreventionMode: enum
:param cancelRestrictions: optional - ONLY\_NEW or ONLY\_PARTIALLY\_FILLED
:type cancelRestrictions: enum
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
//Both the cancel order placement and new order placement succeeded.
\{
"cancelResult": "SUCCESS",
"newOrderResult": "SUCCESS",
"cancelResponse": \{
"symbol": "BTCUSDT",
"origClientOrderId": "DnLo3vTAQcjha43lAZhZ0y",
"orderId": 9,
"orderListId": -1,
"clientOrderId": "osxN3JXAtJvKvCqGeMWMVR",
"transactTime": 1684804350068,
"price": "0.01000000",
"origQty": "0.000100",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"selfTradePreventionMode": "NONE"
},
"newOrderResponse": \{
"symbol": "BTCUSDT",
"orderId": 10,
"orderListId": -1,
"clientOrderId": "wOceeeOzNORyLiQfw7jd8S",
"transactTime": 1652928801803,
"price": "0.02000000",
"origQty": "0.040000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"workingTime": 1669277163808,
"fills": \[],
"selfTradePreventionMode": "NONE"
}
}
Similar to POST /api/v3/order, additional mandatory parameters are determined by type.
Response format varies depending on whether the processing of the message succeeded, partially succeeded, or failed.
:raises: BinanceRequestException, BinanceAPIException
```python
def cancel_replace_order(self, **params):
"""Cancels an existing order and places a new order on the same symbol.
Filters and Order Count are evaluated before the processing of the cancellation and order placement occurs.
A new order that was not attempted (i.e. when newOrderResult: NOT_ATTEMPTED), will still increase the order count by 1.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/trading-endpoints#cancel-an-existing-order-and-send-a-new-order-trade
:param symbol: required
:type symbol: str
:param side: required
:type side: enum
:param type: required
:type type: enum
:param cancelReplaceMode: required - STOP_ON_FAILURE or ALLOW_FAILURE
:type cancelReplaceMode: enum
:param timeInForce: optional
:type timeInForce: enum
:param quantity: optional
:type quantity: decimal
:param quoteOrderQty: optional
:type quoteOrderQty: decimal
:param price: optional
:type price: decimal
:param cancelNewClientOrderId: optional - Used to uniquely identify this cancel. Automatically generated by default.
:type cancelNewClientOrderId: str
:param cancelOrigClientOrderId: optional - Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
:type cancelOrigClientOrderId: str
:param cancelOrderId: optional - Either the cancelOrigClientOrderId or cancelOrderId must be provided. If both are provided, cancelOrderId takes precedence.
:type cancelOrderId: long
:param newClientOrderId: optional - Used to identify the new order.
:type newClientOrderId: str
:param strategyId: optional
:type strategyId: int
:param strategyType: optional - The value cannot be less than 1000000.
:type strategyType: int
:param stopPrice: optional
:type stopPrice: decimal
:param trailingDelta: optional
:type trailingDelta: long
:param icebergQty: optional
:type icebergQty: decimal
:param newOrderRespType: optional - ACK, RESULT or FULL. MARKET and LIMIT orders types default to FULL; all other orders default to ACK
:type newOrderRespType: enum
:param selfTradePreventionMode: optional - EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH or NONE.
:type selfTradePreventionMode: enum
:param cancelRestrictions: optional - ONLY_NEW or ONLY_PARTIALLY_FILLED
:type cancelRestrictions: enum
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
//Both the cancel order placement and new order placement succeeded.
{
"cancelResult": "SUCCESS",
"newOrderResult": "SUCCESS",
"cancelResponse": {
"symbol": "BTCUSDT",
"origClientOrderId": "DnLo3vTAQcjha43lAZhZ0y",
"orderId": 9,
"orderListId": -1,
"clientOrderId": "osxN3JXAtJvKvCqGeMWMVR",
"transactTime": 1684804350068,
"price": "0.01000000",
"origQty": "0.000100",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"selfTradePreventionMode": "NONE"
},
"newOrderResponse": {
"symbol": "BTCUSDT",
"orderId": 10,
"orderListId": -1,
"clientOrderId": "wOceeeOzNORyLiQfw7jd8S",
"transactTime": 1652928801803,
"price": "0.02000000",
"origQty": "0.040000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"workingTime": 1669277163808,
"fills": [],
"selfTradePreventionMode": "NONE"
}
}
Similar to POST /api/v3/order, additional mandatory parameters are determined by type.
Response format varies depending on whether the processing of the message succeeded, partially succeeded, or failed.
:raises: BinanceRequestException, BinanceAPIException
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return self._post("order/cancelReplace", True, data=params)
```
Get all open orders on a symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#current-open-orders-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#current-open-orders-user_data)
:param symbol: optional
:type symbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"symbol": "LTCBTC",
"orderId": 1,
"clientOrderId": "myOrder1",
"price": "0.1",
"origQty": "1.0",
"executedQty": "0.0",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"stopPrice": "0.0",
"icebergQty": "0.0",
"time": 1499827319559
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_open_orders(self, **params):
"""Get all open orders on a symbol.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#current-open-orders-user_data
:param symbol: optional
:type symbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"symbol": "LTCBTC",
"orderId": 1,
"clientOrderId": "myOrder1",
"price": "0.1",
"origQty": "1.0",
"executedQty": "0.0",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"stopPrice": "0.0",
"icebergQty": "0.0",
"time": 1499827319559
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("openOrders", True, data=params)
```
Get all open orders on a symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-open-order-lists-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-open-order-lists-user_data)
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"orderListId": 31,
"contingencyType": "OCO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "wuB13fmulKj3YjdqWEcsnp",
"transactionTime": 1565246080644,
"symbol": "LTCBTC",
"orders": \[
\{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "r3EH2N76dHfLoSZWIUw1bT"
},
\{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "Cv1SnyPD3qhqpbjpYEHbd2"
}
]
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_open_oco_orders(self, **params):
"""Get all open orders on a symbol.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-open-order-lists-user_data
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"orderListId": 31,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "wuB13fmulKj3YjdqWEcsnp",
"transactionTime": 1565246080644,
"symbol": "LTCBTC",
"orders": [
{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "r3EH2N76dHfLoSZWIUw1bT"
},
{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "Cv1SnyPD3qhqpbjpYEHbd2"
}
]
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("openOrderList", True, data=params)
```
Get current account information.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-information-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-information-user_data)
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"makerCommission": 15,
"takerCommission": 15,
"buyerCommission": 0,
"sellerCommission": 0,
"canTrade": true,
"canWithdraw": true,
"canDeposit": true,
"balances": \[
\{
"asset": "BTC",
"free": "4723846.89208129",
"locked": "0.00000000"
},
\{
"asset": "LTC",
"free": "4763368.68006011",
"locked": "0.00000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_account(self, **params):
"""Get current account information.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-information-user_data
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"makerCommission": 15,
"takerCommission": 15,
"buyerCommission": 0,
"sellerCommission": 0,
"canTrade": true,
"canWithdraw": true,
"canDeposit": true,
"balances": [
{
"asset": "BTC",
"free": "4723846.89208129",
"locked": "0.00000000"
},
{
"asset": "LTC",
"free": "4763368.68006011",
"locked": "0.00000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("account", True, data=params)
```
Get current asset balance.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-information-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-information-user_data)
:param asset: optional - the asset to get the balance of
:type asset: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: dictionary or None if not found
.. code-block:: python
\{
"asset": "BTC",
"free": "4723846.89208129",
"locked": "0.00000000"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_asset_balance(self, asset=None, **params):
"""Get current asset balance.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-information-user_data
:param asset: optional - the asset to get the balance of
:type asset: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: dictionary or None if not found
.. code-block:: python
{
"asset": "BTC",
"free": "4723846.89208129",
"locked": "0.00000000"
}
:raises: BinanceRequestException, BinanceAPIException
"""
res = self.get_account(**params)
# find asset balance in list of balances
if "balances" in res:
if asset:
for bal in res["balances"]:
if bal["asset"].lower() == asset.lower():
return bal
else:
return res["balances"]
return None
```
Get trades for a specific symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-trade-list-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-trade-list-user_data)
:param symbol: required
:type symbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: Default 500; max 1000.
:type limit: int
:param fromId: TradeId to fetch from. Default gets most recent trades.
:type fromId: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"id": 28457,
"price": "4.00000100",
"qty": "12.00000000",
"commission": "10.10000000",
"commissionAsset": "BNB",
"time": 1499865549590,
"isBuyer": true,
"isMaker": false,
"isBestMatch": true
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_my_trades(self, **params):
"""Get trades for a specific symbol.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#account-trade-list-user_data
:param symbol: required
:type symbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: Default 500; max 1000.
:type limit: int
:param fromId: TradeId to fetch from. Default gets most recent trades.
:type fromId: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"id": 28457,
"price": "4.00000100",
"qty": "12.00000000",
"commission": "10.10000000",
"commissionAsset": "BNB",
"time": 1499865549590,
"isBuyer": true,
"isMaker": false,
"isBestMatch": true
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("myTrades", True, data=params)
```
Displays the user's current order count usage for all intervals.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-unfilled-order-count-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-unfilled-order-count-user_data)
:returns: API response
.. code-block:: python
\[
\{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 10,
"limit": 10000,
"count": 0
},
\{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 20000,
"count": 0
}
]
```python
def get_current_order_count(self, **params):
"""Displays the user's current order count usage for all intervals.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-unfilled-order-count-user_data
:returns: API response
.. code-block:: python
[
{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 10,
"limit": 10000,
"count": 0
},
{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 20000,
"count": 0
}
]
"""
return self._get("rateLimit/order", True, data=params)
```
Displays the list of orders that were expired because of STP.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-prevented-matches-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-prevented-matches-user_data)
:param symbol: required
:type symbol: str
:param preventedMatchId: optional
:type preventedMatchId: int
:param orderId: optional
:type orderId: int
:param fromPreventedMatchId: optional
:type fromPreventedMatchId: int
:param limit: optional, Default: 500; Max: 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"symbol": "BTCUSDT",
"preventedMatchId": 1,
"takerOrderId": 5,
"makerOrderId": 3,
"tradeGroupId": 1,
"selfTradePreventionMode": "EXPIRE\_MAKER",
"price": "1.100000",
"makerPreventedQuantity": "1.300000",
"transactTime": 1669101687094
}
]
```python
def get_prevented_matches(self, **params):
"""Displays the list of orders that were expired because of STP.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-prevented-matches-user_data
:param symbol: required
:type symbol: str
:param preventedMatchId: optional
:type preventedMatchId: int
:param orderId: optional
:type orderId: int
:param fromPreventedMatchId: optional
:type fromPreventedMatchId: int
:param limit: optional, Default: 500; Max: 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"symbol": "BTCUSDT",
"preventedMatchId": 1,
"takerOrderId": 5,
"makerOrderId": 3,
"tradeGroupId": 1,
"selfTradePreventionMode": "EXPIRE_MAKER",
"price": "1.100000",
"makerPreventedQuantity": "1.300000",
"transactTime": 1669101687094
}
]
"""
return self._get("myPreventedMatches", True, data=params)
```
Retrieves allocations resulting from SOR order placement.
[https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-allocations-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-allocations-user_data)
:param symbol: required
:type symbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param fromAllocationId: optional
:type fromAllocationId: int
:param orderId: optional
:type orderId: int
:param limit: optional, Default: 500; Max: 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"symbol": "BTCUSDT",
"allocationId": 0,
"allocationType": "SOR",
"orderId": 1,
"orderListId": -1,
"price": "1.00000000",
"qty": "5.00000000",
"quoteQty": "5.00000000",
"commission": "0.00000000",
"commissionAsset": "BTC",
"time": 1687506878118,
"isBuyer": true,
"isMaker": false,
"isAllocator": false
}
]
```python
def get_allocations(self, **params):
"""Retrieves allocations resulting from SOR order placement.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/account-endpoints#query-allocations-user_data
:param symbol: required
:type symbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param fromAllocationId: optional
:type fromAllocationId: int
:param orderId: optional
:type orderId: int
:param limit: optional, Default: 500; Max: 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"symbol": "BTCUSDT",
"allocationId": 0,
"allocationType": "SOR",
"orderId": 1,
"orderListId": -1,
"price": "1.00000000",
"qty": "5.00000000",
"quoteQty": "5.00000000",
"commission": "0.00000000",
"commissionAsset": "BTC",
"time": 1687506878118,
"isBuyer": true,
"isMaker": false,
"isAllocator": false
}
]
"""
return self._get("myAllocations", True, data=params)
```
Get system status detail.
[https://developers.binance.com/docs/wallet/others/system-status](https://developers.binance.com/docs/wallet/others/system-status)
:returns: API response
.. code-block:: python
\{
"status": 0, # 0: normal,1:system maintenance
"msg": "normal" # normal or System maintenance.
}
:raises: BinanceAPIException
```python
def get_system_status(self):
"""Get system status detail.
https://developers.binance.com/docs/wallet/others/system-status
:returns: API response
.. code-block:: python
{
"status": 0, # 0: normal,1:system maintenance
"msg": "normal" # normal or System maintenance.
}
:raises: BinanceAPIException
"""
return self._request_margin_api("get", "system/status")
```
Get account status detail.
[https://binance-docs.github.io/apidocs/spot/en/#account-status-sapi-user\_data](https://binance-docs.github.io/apidocs/spot/en/#account-status-sapi-user_data)
[https://developers.binance.com/docs/wallet/account/account-status](https://developers.binance.com/docs/wallet/account/account-status)
:param version: the api version
:param version: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"data": "Normal"
}
```python
def get_account_status(self, version=1, **params):
"""Get account status detail.
https://binance-docs.github.io/apidocs/spot/en/#account-status-sapi-user_data
https://developers.binance.com/docs/wallet/account/account-status
:param version: the api version
:param version: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"data": "Normal"
}
"""
if self.tld == "us":
path = "accountStatus"
else:
path = "account/status"
return self._request_margin_api("get", path, True, version, data=params)
```
Fetch account api trading status detail.
[https://developers.binance.com/docs/wallet/account/account-api-trading-status](https://developers.binance.com/docs/wallet/account/account-api-trading-status)
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"data": \{ // API trading status detail
"isLocked": false, // API trading function is locked or not
"plannedRecoverTime": 0, // If API trading function is locked, this is the planned recover time
"triggerCondition": \{
"GCR": 150, // Number of GTC orders
"IFER": 150, // Number of FOK/IOC orders
"UFR": 300 // Number of orders
},
"indicators": \{ // The indicators updated every 30 seconds
"BTCUSDT": \[ // The symbol
\{
"i": "UFR", // Unfilled Ratio (UFR)
"c": 20, // Count of all orders
"v": 0.05, // Current UFR value
"t": 0.995 // Trigger UFR value
},
\{
"i": "IFER", // IOC/FOK Expiration Ratio (IFER)
"c": 20, // Count of FOK/IOC orders
"v": 0.99, // Current IFER value
"t": 0.99 // Trigger IFER value
},
\{
"i": "GCR", // GTC Cancellation Ratio (GCR)
"c": 20, // Count of GTC orders
"v": 0.99, // Current GCR value
"t": 0.99 // Trigger GCR value
}
],
"ETHUSDT": \[
\{
"i": "UFR",
"c": 20,
"v": 0.05,
"t": 0.995
},
\{
"i": "IFER",
"c": 20,
"v": 0.99,
"t": 0.99
},
\{
"i": "GCR",
"c": 20,
"v": 0.99,
"t": 0.99
}
]
},
"updateTime": 1547630471725
}
}
```python
def get_account_api_trading_status(self, **params):
"""Fetch account api trading status detail.
https://developers.binance.com/docs/wallet/account/account-api-trading-status
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"data": { // API trading status detail
"isLocked": false, // API trading function is locked or not
"plannedRecoverTime": 0, // If API trading function is locked, this is the planned recover time
"triggerCondition": {
"GCR": 150, // Number of GTC orders
"IFER": 150, // Number of FOK/IOC orders
"UFR": 300 // Number of orders
},
"indicators": { // The indicators updated every 30 seconds
"BTCUSDT": [ // The symbol
{
"i": "UFR", // Unfilled Ratio (UFR)
"c": 20, // Count of all orders
"v": 0.05, // Current UFR value
"t": 0.995 // Trigger UFR value
},
{
"i": "IFER", // IOC/FOK Expiration Ratio (IFER)
"c": 20, // Count of FOK/IOC orders
"v": 0.99, // Current IFER value
"t": 0.99 // Trigger IFER value
},
{
"i": "GCR", // GTC Cancellation Ratio (GCR)
"c": 20, // Count of GTC orders
"v": 0.99, // Current GCR value
"t": 0.99 // Trigger GCR value
}
],
"ETHUSDT": [
{
"i": "UFR",
"c": 20,
"v": 0.05,
"t": 0.995
},
{
"i": "IFER",
"c": 20,
"v": 0.99,
"t": 0.99
},
{
"i": "GCR",
"c": 20,
"v": 0.99,
"t": 0.99
}
]
},
"updateTime": 1547630471725
}
}
"""
return self._request_margin_api(
"get", "account/apiTradingStatus", True, data=params
)
```
Fetch api key permissions.
[https://developers.binance.com/docs/wallet/account/api-key-permission](https://developers.binance.com/docs/wallet/account/api-key-permission)
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"ipRestrict": false,
"createTime": 1623840271000,
"enableWithdrawals": false, // This option allows you to withdraw via API. You must apply the IP Access Restriction filter in order to enable withdrawals
"enableInternalTransfer": true, // This option authorizes this key to transfer funds between your master account and your sub account instantly
"permitsUniversalTransfer": true, // Authorizes this key to be used for a dedicated universal transfer API to transfer multiple supported currencies. Each business's own transfer API rights are not affected by this authorization
"enableVanillaOptions": false, // Authorizes this key to Vanilla options trading
"enableReading": true,
"enableFutures": false, // API Key created before your futures account opened does not support futures API service
"enableMargin": false, // This option can be adjusted after the Cross Margin account transfer is completed
"enableSpotAndMarginTrading": false, // Spot and margin trading
"tradingAuthorityExpirationTime": 1628985600000 // Expiration time for spot and margin trading permission
}
```python
def get_account_api_permissions(self, **params):
"""Fetch api key permissions.
https://developers.binance.com/docs/wallet/account/api-key-permission
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"ipRestrict": false,
"createTime": 1623840271000,
"enableWithdrawals": false, // This option allows you to withdraw via API. You must apply the IP Access Restriction filter in order to enable withdrawals
"enableInternalTransfer": true, // This option authorizes this key to transfer funds between your master account and your sub account instantly
"permitsUniversalTransfer": true, // Authorizes this key to be used for a dedicated universal transfer API to transfer multiple supported currencies. Each business's own transfer API rights are not affected by this authorization
"enableVanillaOptions": false, // Authorizes this key to Vanilla options trading
"enableReading": true,
"enableFutures": false, // API Key created before your futures account opened does not support futures API service
"enableMargin": false, // This option can be adjusted after the Cross Margin account transfer is completed
"enableSpotAndMarginTrading": false, // Spot and margin trading
"tradingAuthorityExpirationTime": 1628985600000 // Expiration time for spot and margin trading permission
}
"""
return self._request_margin_api(
"get", "account/apiRestrictions", True, data=params
)
```
Get assets that can be converted into BNB
[https://developers.binance.com/docs/wallet/asset/assets-can-convert-bnb](https://developers.binance.com/docs/wallet/asset/assets-can-convert-bnb)
:returns: API response
.. code-block:: python
\{
"details": \[
\{
"asset": "ADA",
"assetFullName": "ADA",
"amountFree": "6.21", //Convertible amount
"toBTC": "0.00016848", //BTC amount
"toBNB": "0.01777302", //BNB amount(Not deducted commission fee)
"toBNBOffExchange": "0.01741756", //BNB amount(Deducted commission fee)
"exchange": "0.00035546" //Commission fee
}
],
"totalTransferBtc": "0.00016848",
"totalTransferBNB": "0.01777302",
"dribbletPercentage": "0.02" //Commission fee
}
```python
def get_dust_assets(self, **params):
"""Get assets that can be converted into BNB
https://developers.binance.com/docs/wallet/asset/assets-can-convert-bnb
:returns: API response
.. code-block:: python
{
"details": [
{
"asset": "ADA",
"assetFullName": "ADA",
"amountFree": "6.21", //Convertible amount
"toBTC": "0.00016848", //BTC amount
"toBNB": "0.01777302", //BNB amount(Not deducted commission fee)
"toBNBOffExchange": "0.01741756", //BNB amount(Deducted commission fee)
"exchange": "0.00035546" //Commission fee
}
],
"totalTransferBtc": "0.00016848",
"totalTransferBNB": "0.01777302",
"dribbletPercentage": "0.02" //Commission fee
}
"""
return self._request_margin_api("post", "asset/dust-btc", True, data=params)
```
Get log of small amounts exchanged for BNB.
[https://developers.binance.com/docs/wallet/asset/dust-log](https://developers.binance.com/docs/wallet/asset/dust-log)
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"total": 8, //Total counts of exchange
"userAssetDribblets": \[
\{
"totalTransferedAmount": "0.00132256", // Total transfered BNB amount for this exchange.
"totalServiceChargeAmount": "0.00002699", //Total service charge amount for this exchange.
"transId": 45178372831,
"userAssetDribbletDetails": \[ //Details of this exchange.
\{
"transId": 4359321,
"serviceChargeAmount": "0.000009",
"amount": "0.0009",
"operateTime": 1615985535000,
"transferedAmount": "0.000441",
"fromAsset": "USDT"
},
\{
"transId": 4359321,
"serviceChargeAmount": "0.00001799",
"amount": "0.0009",
"operateTime": "2018-05-03 17:07:04",
"transferedAmount": "0.00088156",
"fromAsset": "ETH"
}
]
},
\{
"operateTime":1616203180000,
"totalTransferedAmount": "0.00058795",
"totalServiceChargeAmount": "0.000012",
"transId": 4357015,
"userAssetDribbletDetails": \[
\{
"transId": 4357015,
"serviceChargeAmount": "0.00001"
"amount": "0.001",
"operateTime": 1616203180000,
"transferedAmount": "0.00049",
"fromAsset": "USDT"
},
\{
"transId": 4357015,
"serviceChargeAmount": "0.000002"
"amount": "0.0001",
"operateTime": 1616203180000,
"transferedAmount": "0.00009795",
"fromAsset": "ETH"
}
]
}
]
}
```python
def get_dust_log(self, **params):
"""Get log of small amounts exchanged for BNB.
https://developers.binance.com/docs/wallet/asset/dust-log
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"total": 8, //Total counts of exchange
"userAssetDribblets": [
{
"totalTransferedAmount": "0.00132256", // Total transfered BNB amount for this exchange.
"totalServiceChargeAmount": "0.00002699", //Total service charge amount for this exchange.
"transId": 45178372831,
"userAssetDribbletDetails": [ //Details of this exchange.
{
"transId": 4359321,
"serviceChargeAmount": "0.000009",
"amount": "0.0009",
"operateTime": 1615985535000,
"transferedAmount": "0.000441",
"fromAsset": "USDT"
},
{
"transId": 4359321,
"serviceChargeAmount": "0.00001799",
"amount": "0.0009",
"operateTime": "2018-05-03 17:07:04",
"transferedAmount": "0.00088156",
"fromAsset": "ETH"
}
]
},
{
"operateTime":1616203180000,
"totalTransferedAmount": "0.00058795",
"totalServiceChargeAmount": "0.000012",
"transId": 4357015,
"userAssetDribbletDetails": [
{
"transId": 4357015,
"serviceChargeAmount": "0.00001"
"amount": "0.001",
"operateTime": 1616203180000,
"transferedAmount": "0.00049",
"fromAsset": "USDT"
},
{
"transId": 4357015,
"serviceChargeAmount": "0.000002"
"amount": "0.0001",
"operateTime": 1616203180000,
"transferedAmount": "0.00009795",
"fromAsset": "ETH"
}
]
}
]
}
"""
return self._request_margin_api("get", "asset/dribblet", True, data=params)
```
Convert dust assets to BNB.
[https://developers.binance.com/docs/wallet/asset/dust-transfer](https://developers.binance.com/docs/wallet/asset/dust-transfer)
:param asset: The asset being converted. e.g: 'ONE'
:type asset: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
result = client.transfer\_dust(asset='ONE')
:returns: API response
.. code-block:: python
\{
"totalServiceCharge":"0.02102542",
"totalTransfered":"1.05127099",
"transferResult":\[
\{
"amount":"0.03000000",
"fromAsset":"ETH",
"operateTime":1563368549307,
"serviceChargeAmount":"0.00500000",
"tranId":2970932918,
"transferedAmount":"0.25000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def transfer_dust(self, **params):
"""Convert dust assets to BNB.
https://developers.binance.com/docs/wallet/asset/dust-transfer
:param asset: The asset being converted. e.g: 'ONE'
:type asset: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
result = client.transfer_dust(asset='ONE')
:returns: API response
.. code-block:: python
{
"totalServiceCharge":"0.02102542",
"totalTransfered":"1.05127099",
"transferResult":[
{
"amount":"0.03000000",
"fromAsset":"ETH",
"operateTime":1563368549307,
"serviceChargeAmount":"0.00500000",
"tranId":2970932918,
"transferedAmount":"0.25000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("post", "asset/dust", True, data=params)
```
Query asset dividend record.
[https://developers.binance.com/docs/wallet/asset/assets-divided-record](https://developers.binance.com/docs/wallet/asset/assets-divided-record)
:param asset: optional
:type asset: str
:param startTime: optional
:type startTime: long
:param endTime: optional
:type endTime: long
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
result = client.get\_asset\_dividend\_history()
:returns: API response
.. code-block:: python
\{
"rows":\[
\{
"amount":"10.00000000",
"asset":"BHFT",
"divTime":1563189166000,
"enInfo":"BHFT distribution",
"tranId":2968885920
},
\{
"amount":"10.00000000",
"asset":"BHFT",
"divTime":1563189165000,
"enInfo":"BHFT distribution",
"tranId":2968885920
}
],
"total":2
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_asset_dividend_history(self, **params):
"""Query asset dividend record.
https://developers.binance.com/docs/wallet/asset/assets-divided-record
:param asset: optional
:type asset: str
:param startTime: optional
:type startTime: long
:param endTime: optional
:type endTime: long
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
result = client.get_asset_dividend_history()
:returns: API response
.. code-block:: python
{
"rows":[
{
"amount":"10.00000000",
"asset":"BHFT",
"divTime":1563189166000,
"enInfo":"BHFT distribution",
"tranId":2968885920
},
{
"amount":"10.00000000",
"asset":"BHFT",
"divTime":1563189165000,
"enInfo":"BHFT distribution",
"tranId":2968885920
}
],
"total":2
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "asset/assetDividend", True, data=params)
```
User Universal Transfer
[https://developers.binance.com/docs/wallet/asset/user-universal-transfer](https://developers.binance.com/docs/wallet/asset/user-universal-transfer)
:param type: required
:type type: str (ENUM)
:param asset: required
:type asset: str
:param amount: required
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer\_status = client.make\_universal\_transfer(params)
:returns: API response
.. code-block:: python
\{
"tranId":13526853623
}
:raises: BinanceRequestException, BinanceAPIException
```python
def make_universal_transfer(self, **params):
"""User Universal Transfer
https://developers.binance.com/docs/wallet/asset/user-universal-transfer
:param type: required
:type type: str (ENUM)
:param asset: required
:type asset: str
:param amount: required
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer_status = client.make_universal_transfer(params)
:returns: API response
.. code-block:: python
{
"tranId":13526853623
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "asset/transfer", signed=True, data=params
)
```
Query User Universal Transfer History
[https://developers.binance.com/docs/wallet/asset/query-user-universal-transfer](https://developers.binance.com/docs/wallet/asset/query-user-universal-transfer)
:param type: required
:type type: str (ENUM)
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param current: optional - Default 1
:type current: int
:param size: required - Default 10, Max 100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer\_status = client.query\_universal\_transfer\_history(params)
:returns: API response
.. code-block:: python
\{
"total":2,
"rows":\[
\{
"asset":"USDT",
"amount":"1",
"type":"MAIN\_UMFUTURE"
"status": "CONFIRMED",
"tranId": 11415955596,
"timestamp":1544433328000
},
\{
"asset":"USDT",
"amount":"2",
"type":"MAIN\_UMFUTURE",
"status": "CONFIRMED",
"tranId": 11366865406,
"timestamp":1544433328000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def query_universal_transfer_history(self, **params):
"""Query User Universal Transfer History
https://developers.binance.com/docs/wallet/asset/query-user-universal-transfer
:param type: required
:type type: str (ENUM)
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param current: optional - Default 1
:type current: int
:param size: required - Default 10, Max 100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer_status = client.query_universal_transfer_history(params)
:returns: API response
.. code-block:: python
{
"total":2,
"rows":[
{
"asset":"USDT",
"amount":"1",
"type":"MAIN_UMFUTURE"
"status": "CONFIRMED",
"tranId": 11415955596,
"timestamp":1544433328000
},
{
"asset":"USDT",
"amount":"2",
"type":"MAIN_UMFUTURE",
"status": "CONFIRMED",
"tranId": 11366865406,
"timestamp":1544433328000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "asset/transfer", signed=True, data=params
)
```
Get trade fee.
[https://developers.binance.com/docs/wallet/asset/trade-fee](https://developers.binance.com/docs/wallet/asset/trade-fee)
:param symbol: optional
:type symbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"symbol": "ADABNB",
"makerCommission": "0.001",
"takerCommission": "0.001"
},
\{
"symbol": "BNBBTC",
"makerCommission": "0.001",
"takerCommission": "0.001"
}
]
```python
def get_trade_fee(self, **params):
"""Get trade fee.
https://developers.binance.com/docs/wallet/asset/trade-fee
:param symbol: optional
:type symbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"symbol": "ADABNB",
"makerCommission": "0.001",
"takerCommission": "0.001"
},
{
"symbol": "BNBBTC",
"makerCommission": "0.001",
"takerCommission": "0.001"
}
]
"""
if self.tld == "us":
endpoint = "asset/query/trading-fee"
else:
endpoint = "asset/tradeFee"
return self._request_margin_api("get", endpoint, True, data=params)
```
Fetch details on assets.
[https://developers.binance.com/docs/wallet/asset](https://developers.binance.com/docs/wallet/asset)
:param asset: optional
:type asset: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"CTR": \{
"minWithdrawAmount": "70.00000000", //min withdraw amount
"depositStatus": false,//deposit status (false if ALL of networks' are false)
"withdrawFee": 35, // withdraw fee
"withdrawStatus": true, //withdraw status (false if ALL of networks' are false)
"depositTip": "Delisted, Deposit Suspended" //reason
},
"SKY": \{
"minWithdrawAmount": "0.02000000",
"depositStatus": true,
"withdrawFee": 0.01,
"withdrawStatus": true
}
}
```python
def get_asset_details(self, **params):
"""Fetch details on assets.
https://developers.binance.com/docs/wallet/asset
:param asset: optional
:type asset: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"CTR": {
"minWithdrawAmount": "70.00000000", //min withdraw amount
"depositStatus": false,//deposit status (false if ALL of networks' are false)
"withdrawFee": 35, // withdraw fee
"withdrawStatus": true, //withdraw status (false if ALL of networks' are false)
"depositTip": "Delisted, Deposit Suspended" //reason
},
"SKY": {
"minWithdrawAmount": "0.02000000",
"depositStatus": true,
"withdrawFee": 0.01,
"withdrawStatus": true
}
}
"""
return self._request_margin_api("get", "asset/assetDetail", True, data=params)
```
Get symbols delist schedule for spot
[https://developers.binance.com/docs/wallet/others/delist-schedule](https://developers.binance.com/docs/wallet/others/delist-schedule)
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"delistTime": 1686161202000,
"symbols": \[
"ADAUSDT",
"BNBUSDT"
]
},
\{
"delistTime": 1686222232000,
"symbols": \[
"ETHUSDT"
]
}
]
```python
def get_spot_delist_schedule(self, **params):
"""Get symbols delist schedule for spot
https://developers.binance.com/docs/wallet/others/delist-schedule
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"delistTime": 1686161202000,
"symbols": [
"ADAUSDT",
"BNBUSDT"
]
},
{
"delistTime": 1686222232000,
"symbols": [
"ETHUSDT"
]
}
]
"""
return self._request_margin_api(
"get", "spot/delist-schedule", True, data=params
)
```
Submit a withdraw request.
[https://developers.binance.com/docs/wallet/capital/withdraw](https://developers.binance.com/docs/wallet/capital/withdraw)
Assumptions:
* You must have Withdraw permissions enabled on your API key
* You must have withdrawn to the address specified through the website and approved the transaction via email
:param coin: required
:type coin: str
:param withdrawOrderId: optional - client id for withdraw
:type withdrawOrderId: str
:param network: optional
:type network: str
:param address: optional
:type address: str
:type addressTag: optional - Secondary address identifier for coins like XRP,XMR etc.
:param amount: required
:type amount: decimal
:param transactionFeeFlag: required - When making internal transfer, true for returning the fee to the destination account; false for returning the fee back to the departure account. Default false.
:type transactionFeeFlag: bool
:param name: optional - Description of the address, default asset value passed will be used
:type name: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"id":"7213fea8e94b4a5593d507237e5a555b"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def withdraw(self, **params):
"""Submit a withdraw request.
https://developers.binance.com/docs/wallet/capital/withdraw
Assumptions:
- You must have Withdraw permissions enabled on your API key
- You must have withdrawn to the address specified through the website and approved the transaction via email
:param coin: required
:type coin: str
:param withdrawOrderId: optional - client id for withdraw
:type withdrawOrderId: str
:param network: optional
:type network: str
:param address: optional
:type address: str
:type addressTag: optional - Secondary address identifier for coins like XRP,XMR etc.
:param amount: required
:type amount: decimal
:param transactionFeeFlag: required - When making internal transfer, true for returning the fee to the destination account; false for returning the fee back to the departure account. Default false.
:type transactionFeeFlag: bool
:param name: optional - Description of the address, default asset value passed will be used
:type name: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"id":"7213fea8e94b4a5593d507237e5a555b"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "capital/withdraw/apply", True, data=params
)
```
Fetch deposit history.
[https://developers.binance.com/docs/wallet/capital/deposite-history](https://developers.binance.com/docs/wallet/capital/deposite-history)
:param coin: optional
:type coin: str
:type status: optional - 0(0:pending,1:success) optional
:type status: int
:param startTime: optional
:type startTime: long
:param endTime: optional
:type endTime: long
:param offset: optional - default:0
:type offset: long
:param limit: optional
:type limit: long
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"amount":"0.00999800",
"coin":"PAXG",
"network":"ETH",
"status":1,
"address":"0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
"addressTag":"",
"txId":"0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
"insertTime":1599621997000,
"transferType":0,
"confirmTimes":"12/12"
},
\{
"amount":"0.50000000",
"coin":"IOTA",
"network":"IOTA",
"status":1,
"address":"SIZ9VLMHWATXKV99LH99CIGFJFUMLEHGWVZVNNZXRJJVWBPHYWPPBOSDORZ9EQSHCZAMPVAPGFYQAUUV9DROOXJLNW",
"addressTag":"",
"txId":"ESBFVQUTPIWQNJSPXFNHNYHSQNTGKRVKPRABQWTAXCDWOAKDKYWPTVG9BGXNVNKTLEJGESAVXIKIZ9999",
"insertTime":1599620082000,
"transferType":0,
"confirmTimes":"1/1"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_deposit_history(self, **params):
"""Fetch deposit history.
https://developers.binance.com/docs/wallet/capital/deposite-history
:param coin: optional
:type coin: str
:type status: optional - 0(0:pending,1:success) optional
:type status: int
:param startTime: optional
:type startTime: long
:param endTime: optional
:type endTime: long
:param offset: optional - default:0
:type offset: long
:param limit: optional
:type limit: long
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"amount":"0.00999800",
"coin":"PAXG",
"network":"ETH",
"status":1,
"address":"0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
"addressTag":"",
"txId":"0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
"insertTime":1599621997000,
"transferType":0,
"confirmTimes":"12/12"
},
{
"amount":"0.50000000",
"coin":"IOTA",
"network":"IOTA",
"status":1,
"address":"SIZ9VLMHWATXKV99LH99CIGFJFUMLEHGWVZVNNZXRJJVWBPHYWPPBOSDORZ9EQSHCZAMPVAPGFYQAUUV9DROOXJLNW",
"addressTag":"",
"txId":"ESBFVQUTPIWQNJSPXFNHNYHSQNTGKRVKPRABQWTAXCDWOAKDKYWPTVG9BGXNVNKTLEJGESAVXIKIZ9999",
"insertTime":1599620082000,
"transferType":0,
"confirmTimes":"1/1"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "capital/deposit/hisrec", True, data=params
)
```
Fetch withdraw history.
[https://developers.binance.com/docs/wallet/capital/withdraw-history](https://developers.binance.com/docs/wallet/capital/withdraw-history)
:param coin: optional
:type coin: str
:type status: 0(0:Email Sent,1:Cancelled 2:Awaiting Approval 3:Rejected 4:Processing 5:Failure 6Completed) optional
:type status: int
:param offset: optional - default:0
:type offset: int
:param limit: optional
:type limit: int
:param startTime: optional - Default: 90 days from current timestamp
:type startTime: int
:param endTime: optional - Default: present timestamp
:type endTime: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"address": "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
"amount": "8.91000000",
"applyTime": "2019-10-12 11:12:02",
"coin": "USDT",
"id": "b6ae22b3aa844210a7041aee7589627c",
"withdrawOrderId": "WITHDRAWtest123", // will not be returned if there's no withdrawOrderId for this withdraw.
"network": "ETH",
"transferType": 0, // 1 for internal transfer, 0 for external transfer
"status": 6,
"txId": "0xb5ef8c13b968a406cc62a93a8bd80f9e9a906ef1b3fcf20a2e48573c17659268"
},
\{
"address": "1FZdVHtiBqMrWdjPyRPULCUceZPJ2WLCsB",
"amount": "0.00150000",
"applyTime": "2019-09-24 12:43:45",
"coin": "BTC",
"id": "156ec387f49b41df8724fa744fa82719",
"network": "BTC",
"status": 6,
"txId": "60fd9007ebfddc753455f95fafa808c4302c836e4d1eebc5a132c36c1d8ac354"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_withdraw_history(self, **params):
"""Fetch withdraw history.
https://developers.binance.com/docs/wallet/capital/withdraw-history
:param coin: optional
:type coin: str
:type status: 0(0:Email Sent,1:Cancelled 2:Awaiting Approval 3:Rejected 4:Processing 5:Failure 6Completed) optional
:type status: int
:param offset: optional - default:0
:type offset: int
:param limit: optional
:type limit: int
:param startTime: optional - Default: 90 days from current timestamp
:type startTime: int
:param endTime: optional - Default: present timestamp
:type endTime: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"address": "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
"amount": "8.91000000",
"applyTime": "2019-10-12 11:12:02",
"coin": "USDT",
"id": "b6ae22b3aa844210a7041aee7589627c",
"withdrawOrderId": "WITHDRAWtest123", // will not be returned if there's no withdrawOrderId for this withdraw.
"network": "ETH",
"transferType": 0, // 1 for internal transfer, 0 for external transfer
"status": 6,
"txId": "0xb5ef8c13b968a406cc62a93a8bd80f9e9a906ef1b3fcf20a2e48573c17659268"
},
{
"address": "1FZdVHtiBqMrWdjPyRPULCUceZPJ2WLCsB",
"amount": "0.00150000",
"applyTime": "2019-09-24 12:43:45",
"coin": "BTC",
"id": "156ec387f49b41df8724fa744fa82719",
"network": "BTC",
"status": 6,
"txId": "60fd9007ebfddc753455f95fafa808c4302c836e4d1eebc5a132c36c1d8ac354"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "capital/withdraw/history", True, data=params
)
```
Fetch withdraw history.
[https://binance-docs.github.io/apidocs/spot/en/#withdraw-history-supporting-network-user\_data](https://binance-docs.github.io/apidocs/spot/en/#withdraw-history-supporting-network-user_data)
:param withdraw\_id: required
:type withdraw\_id: str
:param asset: optional
:type asset: str
:type status: 0(0:Email Sent,1:Cancelled 2:Awaiting Approval 3:Rejected 4:Processing 5:Failure 6Completed) optional
:type status: int
:param startTime: optional
:type startTime: long
:param endTime: optional
:type endTime: long
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"id":"7213fea8e94b4a5593d507237e5a555b",
"withdrawOrderId": None,
"amount": 0.99,
"transactionFee": 0.01,
"address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
"asset": "ETH",
"txId": "0xdf33b22bdb2b28b1f75ccd201a4a4m6e7g83jy5fc5d5a9d1340961598cfcb0a1",
"applyTime": 1508198532000,
"status": 4
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_withdraw_history_id(self, withdraw_id, **params):
"""Fetch withdraw history.
https://binance-docs.github.io/apidocs/spot/en/#withdraw-history-supporting-network-user_data
:param withdraw_id: required
:type withdraw_id: str
:param asset: optional
:type asset: str
:type status: 0(0:Email Sent,1:Cancelled 2:Awaiting Approval 3:Rejected 4:Processing 5:Failure 6Completed) optional
:type status: int
:param startTime: optional
:type startTime: long
:param endTime: optional
:type endTime: long
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"id":"7213fea8e94b4a5593d507237e5a555b",
"withdrawOrderId": None,
"amount": 0.99,
"transactionFee": 0.01,
"address": "0x6915f16f8791d0a1cc2bf47c13a6b2a92000504b",
"asset": "ETH",
"txId": "0xdf33b22bdb2b28b1f75ccd201a4a4m6e7g83jy5fc5d5a9d1340961598cfcb0a1",
"applyTime": 1508198532000,
"status": 4
}
:raises: BinanceRequestException, BinanceAPIException
"""
result = self.get_withdraw_history(**params)
for entry in result:
if "id" in entry and entry["id"] == withdraw_id:
return entry
raise Exception("There is no entry with withdraw id", result)
```
Fetch a deposit address for a symbol
[https://developers.binance.com/docs/wallet/capital/deposite-address](https://developers.binance.com/docs/wallet/capital/deposite-address)
:param coin: required
:type coin: str
:param network: optional
:type network: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"address": "1HPn8Rx2y6nNSfagQBKy27GB99Vbzg89wv",
"coin": "BTC",
"tag": "",
"url": "[https://btc.com/1HPn8Rx2y6nNSfagQBKy27GB99Vbzg89wv](https://btc.com/1HPn8Rx2y6nNSfagQBKy27GB99Vbzg89wv)"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_deposit_address(self, coin: str, network: Optional[str] = None, **params):
"""Fetch a deposit address for a symbol
https://developers.binance.com/docs/wallet/capital/deposite-address
:param coin: required
:type coin: str
:param network: optional
:type network: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"address": "1HPn8Rx2y6nNSfagQBKy27GB99Vbzg89wv",
"coin": "BTC",
"tag": "",
"url": "https://btc.com/1HPn8Rx2y6nNSfagQBKy27GB99Vbzg89wv"
}
:raises: BinanceRequestException, BinanceAPIException
"""
params["coin"] = coin
if network:
params["network"] = network
return self._request_margin_api(
"get", "capital/deposit/address", True, data=params
)
```
Start a new user data stream and return the listen key
If a stream already exists it should return the same key.
If the stream becomes invalid a new key is returned.
Can be used to keep the user stream alive.
[https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot](https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot)
:returns: API response
.. code-block:: python
\{
"listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def stream_get_listen_key(self):
"""Start a new user data stream and return the listen key
If a stream already exists it should return the same key.
If the stream becomes invalid a new key is returned.
Can be used to keep the user stream alive.
https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot
:returns: API response
.. code-block:: python
{
"listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
}
:raises: BinanceRequestException, BinanceAPIException
"""
res = self._post(
"userDataStream", False, data={}
)
return res["listenKey"]
```
PING a user data stream to prevent a time out.
[https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot](https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot)
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
\{}
:raises: BinanceRequestException, BinanceAPIException
```python
def stream_keepalive(self, listenKey):
"""PING a user data stream to prevent a time out.
https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
{}
:raises: BinanceRequestException, BinanceAPIException
"""
params = {"listenKey": listenKey}
return self._put(
"userDataStream", False, data=params
)
```
Close out a user data stream.
[https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot](https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot)
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
\{}
:raises: BinanceRequestException, BinanceAPIException
```python
def stream_close(self, listenKey):
"""Close out a user data stream.
https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
{}
:raises: BinanceRequestException, BinanceAPIException
"""
params = {"listenKey": listenKey}
return self._delete(
"userDataStream", False, data=params, version=self.PRIVATE_API_VERSION
)
```
Query cross-margin account details
[https://developers.binance.com/docs/margin\_trading/account/Query-Cross-Margin-Account-Details](https://developers.binance.com/docs/margin_trading/account/Query-Cross-Margin-Account-Details)
:returns: API response
.. code-block:: python
\{
"borrowEnabled": true,
"marginLevel": "11.64405625",
"totalAssetOfBtc": "6.82728457",
"totalLiabilityOfBtc": "0.58633215",
"totalNetAssetOfBtc": "6.24095242",
"tradeEnabled": true,
"transferEnabled": true,
"userAssets": \[
\{
"asset": "BTC",
"borrowed": "0.00000000",
"free": "0.00499500",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00499500"
},
\{
"asset": "BNB",
"borrowed": "201.66666672",
"free": "2346.50000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "2144.83333328"
},
\{
"asset": "ETH",
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000"
},
\{
"asset": "USDT",
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_account(self, **params):
"""Query cross-margin account details
https://developers.binance.com/docs/margin_trading/account/Query-Cross-Margin-Account-Details
:returns: API response
.. code-block:: python
{
"borrowEnabled": true,
"marginLevel": "11.64405625",
"totalAssetOfBtc": "6.82728457",
"totalLiabilityOfBtc": "0.58633215",
"totalNetAssetOfBtc": "6.24095242",
"tradeEnabled": true,
"transferEnabled": true,
"userAssets": [
{
"asset": "BTC",
"borrowed": "0.00000000",
"free": "0.00499500",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00499500"
},
{
"asset": "BNB",
"borrowed": "201.66666672",
"free": "2346.50000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "2144.83333328"
},
{
"asset": "ETH",
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000"
},
{
"asset": "USDT",
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "margin/account", True, data=params)
```
Query isolated margin account details
[https://developers.binance.com/docs/margin\_trading/account/Query-Isolated-Margin-Account-Info](https://developers.binance.com/docs/margin_trading/account/Query-Isolated-Margin-Account-Info)
:param symbols: optional up to 5 margin pairs as a comma separated string
:type asset: str
.. code:: python
account\_info = client.get\_isolated\_margin\_account()
account\_info = client.get\_isolated\_margin\_account(symbols="BTCUSDT,ETHUSDT")
:returns: API response
.. code-block:: python
If "symbols" is not sent:
\{
"assets":\[
\{
"baseAsset":
\{
"asset": "BTC",
"borrowEnabled": true,
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000",
"netAssetOfBtc": "0.00000000",
"repayEnabled": true,
"totalAsset": "0.00000000"
},
"quoteAsset":
\{
"asset": "USDT",
"borrowEnabled": true,
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000",
"netAssetOfBtc": "0.00000000",
"repayEnabled": true,
"totalAsset": "0.00000000"
},
"symbol": "BTCUSDT"
"isolatedCreated": true,
"marginLevel": "0.00000000",
"marginLevelStatus": "EXCESSIVE", // "EXCESSIVE", "NORMAL", "MARGIN\_CALL", "PRE\_LIQUIDATION", "FORCE\_LIQUIDATION"
"marginRatio": "0.00000000",
"indexPrice": "10000.00000000"
"liquidatePrice": "1000.00000000",
"liquidateRate": "1.00000000"
"tradeEnabled": true
}
],
"totalAssetOfBtc": "0.00000000",
"totalLiabilityOfBtc": "0.00000000",
"totalNetAssetOfBtc": "0.00000000"
}
If "symbols" is sent:
\{
"assets":\[
\{
"baseAsset":
\{
"asset": "BTC",
"borrowEnabled": true,
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000",
"netAssetOfBtc": "0.00000000",
"repayEnabled": true,
"totalAsset": "0.00000000"
},
"quoteAsset":
\{
"asset": "USDT",
"borrowEnabled": true,
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000",
"netAssetOfBtc": "0.00000000",
"repayEnabled": true,
"totalAsset": "0.00000000"
},
"symbol": "BTCUSDT"
"isolatedCreated": true,
"marginLevel": "0.00000000",
"marginLevelStatus": "EXCESSIVE", // "EXCESSIVE", "NORMAL", "MARGIN\_CALL", "PRE\_LIQUIDATION", "FORCE\_LIQUIDATION"
"marginRatio": "0.00000000",
"indexPrice": "10000.00000000"
"liquidatePrice": "1000.00000000",
"liquidateRate": "1.00000000"
"tradeEnabled": true
}
]
}
```python
def get_isolated_margin_account(self, **params):
"""Query isolated margin account details
https://developers.binance.com/docs/margin_trading/account/Query-Isolated-Margin-Account-Info
:param symbols: optional up to 5 margin pairs as a comma separated string
:type asset: str
.. code:: python
account_info = client.get_isolated_margin_account()
account_info = client.get_isolated_margin_account(symbols="BTCUSDT,ETHUSDT")
:returns: API response
.. code-block:: python
If "symbols" is not sent:
{
"assets":[
{
"baseAsset":
{
"asset": "BTC",
"borrowEnabled": true,
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000",
"netAssetOfBtc": "0.00000000",
"repayEnabled": true,
"totalAsset": "0.00000000"
},
"quoteAsset":
{
"asset": "USDT",
"borrowEnabled": true,
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000",
"netAssetOfBtc": "0.00000000",
"repayEnabled": true,
"totalAsset": "0.00000000"
},
"symbol": "BTCUSDT"
"isolatedCreated": true,
"marginLevel": "0.00000000",
"marginLevelStatus": "EXCESSIVE", // "EXCESSIVE", "NORMAL", "MARGIN_CALL", "PRE_LIQUIDATION", "FORCE_LIQUIDATION"
"marginRatio": "0.00000000",
"indexPrice": "10000.00000000"
"liquidatePrice": "1000.00000000",
"liquidateRate": "1.00000000"
"tradeEnabled": true
}
],
"totalAssetOfBtc": "0.00000000",
"totalLiabilityOfBtc": "0.00000000",
"totalNetAssetOfBtc": "0.00000000"
}
If "symbols" is sent:
{
"assets":[
{
"baseAsset":
{
"asset": "BTC",
"borrowEnabled": true,
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000",
"netAssetOfBtc": "0.00000000",
"repayEnabled": true,
"totalAsset": "0.00000000"
},
"quoteAsset":
{
"asset": "USDT",
"borrowEnabled": true,
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000",
"netAssetOfBtc": "0.00000000",
"repayEnabled": true,
"totalAsset": "0.00000000"
},
"symbol": "BTCUSDT"
"isolatedCreated": true,
"marginLevel": "0.00000000",
"marginLevelStatus": "EXCESSIVE", // "EXCESSIVE", "NORMAL", "MARGIN_CALL", "PRE_LIQUIDATION", "FORCE_LIQUIDATION"
"marginRatio": "0.00000000",
"indexPrice": "10000.00000000"
"liquidatePrice": "1000.00000000",
"liquidateRate": "1.00000000"
"tradeEnabled": true
}
]
}
"""
return self._request_margin_api(
"get", "margin/isolated/account", True, data=params
)
```
Enable isolated margin account for a specific symbol.
[https://developers.binance.com/docs/margin\_trading/account/Enable-Isolated-Margin-Account](https://developers.binance.com/docs/margin_trading/account/Enable-Isolated-Margin-Account)
:param symbol:
:type asset: str
:returns: API response
.. code-block:: python
\{
"success": true,
"symbol": "BTCUSDT"
}
```python
def enable_isolated_margin_account(self, **params):
"""Enable isolated margin account for a specific symbol.
https://developers.binance.com/docs/margin_trading/account/Enable-Isolated-Margin-Account
:param symbol:
:type asset: str
:returns: API response
.. code-block:: python
{
"success": true,
"symbol": "BTCUSDT"
}
"""
return self._request_margin_api(
"post", "margin/isolated/account", True, data=params
)
```
Disable isolated margin account for a specific symbol. Each trading pair can only
be deactivated once every 24 hours.
[https://developers.binance.com/docs/margin\_trading/account/Disable-Isolated-Margin-Account](https://developers.binance.com/docs/margin_trading/account/Disable-Isolated-Margin-Account)
:param symbol:
:type asset: str
:returns: API response
.. code-block:: python
\{
"success": true,
"symbol": "BTCUSDT"
}
```python
def disable_isolated_margin_account(self, **params):
"""Disable isolated margin account for a specific symbol. Each trading pair can only
be deactivated once every 24 hours.
https://developers.binance.com/docs/margin_trading/account/Disable-Isolated-Margin-Account
:param symbol:
:type asset: str
:returns: API response
.. code-block:: python
{
"success": true,
"symbol": "BTCUSDT"
}
"""
return self._request_margin_api(
"delete", "margin/isolated/account", True, data=params
)
```
Query enabled isolated margin account limit.
[https://developers.binance.com/docs/margin\_trading/account/Query-Enabled-Isolated-Margin-Account-Limit](https://developers.binance.com/docs/margin_trading/account/Query-Enabled-Isolated-Margin-Account-Limit)
:returns: API response
.. code-block:: python
\{
"enabledAccount": 5,
"maxAccount": 20
}
```python
def get_enabled_isolated_margin_account_limit(self, **params):
"""Query enabled isolated margin account limit.
https://developers.binance.com/docs/margin_trading/account/Query-Enabled-Isolated-Margin-Account-Limit
:returns: API response
.. code-block:: python
{
"enabledAccount": 5,
"maxAccount": 20
}
"""
return self._request_margin_api(
"get", "margin/isolated/accountLimit", True, data=params
)
```
Query the historical information of user's margin account small-value asset conversion BNB.
[https://binance-docs.github.io/apidocs/spot/en/#margin-dustlog-user\_data](https://binance-docs.github.io/apidocs/spot/en/#margin-dustlog-user_data)
:param startTime: optional
:type startTime: long
:param endTime: optional
:type endTime: long
:returns: API response
.. code-block:: python
\{
"total": 8, //Total counts of exchange
"userAssetDribblets": \[
\{
"operateTime": 1615985535000,
"totalTransferedAmount": "0.00132256", // Total transfered BNB amount for this exchange.
"totalServiceChargeAmount": "0.00002699", //Total service charge amount for this exchange.
"transId": 45178372831,
"userAssetDribbletDetails": \[ //Details of this exchange.
\{
"transId": 4359321,
"serviceChargeAmount": "0.000009",
"amount": "0.0009",
"operateTime": 1615985535000,
"transferedAmount": "0.000441",
"fromAsset": "USDT"
},
\{
"transId": 4359321,
"serviceChargeAmount": "0.00001799",
"amount": "0.0009",
"operateTime": 1615985535000,
"transferedAmount": "0.00088156",
"fromAsset": "ETH"
}
]
},
\{
"operateTime":1616203180000,
"totalTransferedAmount": "0.00058795",
"totalServiceChargeAmount": "0.000012",
"transId": 4357015,
"userAssetDribbletDetails": \[
\{
"transId": 4357015,
"serviceChargeAmount": "0.00001",
"amount": "0.001",
"operateTime": 1616203180000,
"transferedAmount": "0.00049",
"fromAsset": "USDT"
},
\{
"transId": 4357015,
"serviceChargeAmount": "0.000002",
"amount": "0.0001",
"operateTime": 1616203180000,
"transferedAmount": "0.00009795",
"fromAsset": "ETH"
}
]
}
]
}
```python
def get_margin_dustlog(self, **params):
"""
Query the historical information of user's margin account small-value asset conversion BNB.
https://binance-docs.github.io/apidocs/spot/en/#margin-dustlog-user_data
:param startTime: optional
:type startTime: long
:param endTime: optional
:type endTime: long
:returns: API response
.. code-block:: python
{
"total": 8, //Total counts of exchange
"userAssetDribblets": [
{
"operateTime": 1615985535000,
"totalTransferedAmount": "0.00132256", // Total transfered BNB amount for this exchange.
"totalServiceChargeAmount": "0.00002699", //Total service charge amount for this exchange.
"transId": 45178372831,
"userAssetDribbletDetails": [ //Details of this exchange.
{
"transId": 4359321,
"serviceChargeAmount": "0.000009",
"amount": "0.0009",
"operateTime": 1615985535000,
"transferedAmount": "0.000441",
"fromAsset": "USDT"
},
{
"transId": 4359321,
"serviceChargeAmount": "0.00001799",
"amount": "0.0009",
"operateTime": 1615985535000,
"transferedAmount": "0.00088156",
"fromAsset": "ETH"
}
]
},
{
"operateTime":1616203180000,
"totalTransferedAmount": "0.00058795",
"totalServiceChargeAmount": "0.000012",
"transId": 4357015,
"userAssetDribbletDetails": [
{
"transId": 4357015,
"serviceChargeAmount": "0.00001",
"amount": "0.001",
"operateTime": 1616203180000,
"transferedAmount": "0.00049",
"fromAsset": "USDT"
},
{
"transId": 4357015,
"serviceChargeAmount": "0.000002",
"amount": "0.0001",
"operateTime": 1616203180000,
"transferedAmount": "0.00009795",
"fromAsset": "ETH"
}
]
}
]
}
"""
return self._request_margin_api("get", "margin/dribblet", True, data=params)
```
Get margin assets that can be converted into BNB.
[https://binance-docs.github.io/apidocs/spot/en/#margin-dustlog-user\_data](https://binance-docs.github.io/apidocs/spot/en/#margin-dustlog-user_data)
:returns: API response
.. code-block:: python
\{
"details": \[
\{
"asset": "ADA",
"assetFullName": "ADA",
"amountFree": "6.21",
"toBTC": "0.00016848",
"toBNB": "0.01777302",
"toBNBOffExchange": "0.01741756",
"exchange": "0.00035546"
}
],
"totalTransferBtc": "0.00016848",
"totalTransferBNB": "0.01777302",
"dribbletPercentage": "0.02"
}
```python
def get_margin_dust_assets(self, **params):
"""Get margin assets that can be converted into BNB.
https://binance-docs.github.io/apidocs/spot/en/#margin-dustlog-user_data
:returns: API response
.. code-block:: python
{
"details": [
{
"asset": "ADA",
"assetFullName": "ADA",
"amountFree": "6.21",
"toBTC": "0.00016848",
"toBNB": "0.01777302",
"toBNBOffExchange": "0.01741756",
"exchange": "0.00035546"
}
],
"totalTransferBtc": "0.00016848",
"totalTransferBNB": "0.01777302",
"dribbletPercentage": "0.02"
}
"""
return self._request_margin_api("get", "margin/dust", True, data=params)
```
Convert dust assets to BNB.
[https://binance-docs.github.io/apidocs/spot/en/#dust-transfer-trade](https://binance-docs.github.io/apidocs/spot/en/#dust-transfer-trade)
:returns: API response
.. code-block:: python
\{
"totalServiceCharge":"0.02102542",
"totalTransfered":"1.05127099",
"transferResult":\[
\{
"amount":"0.03000000",
"fromAsset":"ETH",
"operateTime":1563368549307,
"serviceChargeAmount":"0.00500000",
"tranId":2970932918,
"transferedAmount":"0.25000000"
},
\{
"amount":"0.09000000",
"fromAsset":"LTC",
"operateTime":1563368549404,
"serviceChargeAmount":"0.01548000",
"tranId":2970932918,
"transferedAmount":"0.77400000"
}
]
}
```python
def transfer_margin_dust(self, **params):
"""Convert dust assets to BNB.
https://binance-docs.github.io/apidocs/spot/en/#dust-transfer-trade
:returns: API response
.. code-block:: python
{
"totalServiceCharge":"0.02102542",
"totalTransfered":"1.05127099",
"transferResult":[
{
"amount":"0.03000000",
"fromAsset":"ETH",
"operateTime":1563368549307,
"serviceChargeAmount":"0.00500000",
"tranId":2970932918,
"transferedAmount":"0.25000000"
},
{
"amount":"0.09000000",
"fromAsset":"LTC",
"operateTime":1563368549404,
"serviceChargeAmount":"0.01548000",
"tranId":2970932918,
"transferedAmount":"0.77400000"
}
]
}
"""
return self._request_margin_api("post", "margin/dust", True, data=params)
```
[https://developers.binance.com/docs/margin\_trading/market-data](https://developers.binance.com/docs/margin_trading/market-data)
:param none
:returns: API response
.. code-block:: python
\[
\{
"collaterals": \[
\{
"minUsdValue": "0",
"maxUsdValue": "13000000",
"discountRate": "1"
},
\{
"minUsdValue": "13000000",
"maxUsdValue": "20000000",
"discountRate": "0.975"
},
\{
"minUsdValue": "20000000",
"discountRate": "0"
}
],
"assetNames": \[
"BNX"
]
},
\{
"collaterals": \[
\{
"minUsdValue": "0",
"discountRate": "1"
}
],
"assetNames": \[
"BTC",
"BUSD",
"ETH",
"USDT"
]
}
]
```python
def get_cross_margin_collateral_ratio(self, **params):
"""
https://developers.binance.com/docs/margin_trading/market-data
:param none
:returns: API response
.. code-block:: python
[
{
"collaterals": [
{
"minUsdValue": "0",
"maxUsdValue": "13000000",
"discountRate": "1"
},
{
"minUsdValue": "13000000",
"maxUsdValue": "20000000",
"discountRate": "0.975"
},
{
"minUsdValue": "20000000",
"discountRate": "0"
}
],
"assetNames": [
"BNX"
]
},
{
"collaterals": [
{
"minUsdValue": "0",
"discountRate": "1"
}
],
"assetNames": [
"BTC",
"BUSD",
"ETH",
"USDT"
]
}
]
"""
return self._request_margin_api(
"get", "margin/crossMarginCollateralRatio", True, data=params
)
```
Query the coins which can be small liability exchange
[https://developers.binance.com/docs/margin\_trading/trade/Get-Small-Liability-Exchange-Coin-List](https://developers.binance.com/docs/margin_trading/trade/Get-Small-Liability-Exchange-Coin-List)
:returns: API response
.. code-block:: python
\[
\{
"asset": "ETH",
"interest": "0.00083334",
"principal": "0.001",
"liabilityAsset": "USDT",
"liabilityQty": 0.3552
}
]
```python
def get_small_liability_exchange_assets(self, **params):
"""Query the coins which can be small liability exchange
https://developers.binance.com/docs/margin_trading/trade/Get-Small-Liability-Exchange-Coin-List
:returns: API response
.. code-block:: python
[
{
"asset": "ETH",
"interest": "0.00083334",
"principal": "0.001",
"liabilityAsset": "USDT",
"liabilityQty": 0.3552
}
]
"""
return self._request_margin_api(
"get", "margin/exchange-small-liability", True, data=params
)
```
Cross Margin Small Liability Exchange
[https://developers.binance.com/docs/margin\_trading/trade/Small-Liability-Exchange](https://developers.binance.com/docs/margin_trading/trade/Small-Liability-Exchange)
:param assetNames: The assets list of small liability exchange
:type assetNames: array
:returns: API response
.. code-block:: python
none
```python
def exchange_small_liability_assets(self, **params):
"""Cross Margin Small Liability Exchange
https://developers.binance.com/docs/margin_trading/trade/Small-Liability-Exchange
:param assetNames: The assets list of small liability exchange
:type assetNames: array
:returns: API response
.. code-block:: python
none
"""
return self._request_margin_api(
"post", "margin/exchange-small-liability", True, data=params
)
```
Get Small liability Exchange History
[https://developers.binance.com/docs/margin\_trading/trade/Get-Small-Liability-Exchange-History](https://developers.binance.com/docs/margin_trading/trade/Get-Small-Liability-Exchange-History)
:param current: Currently querying page. Start from 1. Default:1
:type current: int
:param size: Default:10, Max:100
:type size: int
:param startTime: Default: 30 days from current timestamp
:type startTime: long
:param endTime: Default: present timestamp
:type endTIme: long
:returns: API response
.. code-block:: python
\{
"total": 1,
"rows": \[
\{
"asset": "ETH",
"amount": "0.00083434",
"targetAsset": "BUSD",
"targetAmount": "1.37576819",
"bizType": "EXCHANGE\_SMALL\_LIABILITY",
"timestamp": 1672801339253
}
]
}
```python
def get_small_liability_exchange_history(self, **params):
"""Get Small liability Exchange History
https://developers.binance.com/docs/margin_trading/trade/Get-Small-Liability-Exchange-History
:param current: Currently querying page. Start from 1. Default:1
:type current: int
:param size: Default:10, Max:100
:type size: int
:param startTime: Default: 30 days from current timestamp
:type startTime: long
:param endTime: Default: present timestamp
:type endTIme: long
:returns: API response
.. code-block:: python
{
"total": 1,
"rows": [
{
"asset": "ETH",
"amount": "0.00083434",
"targetAsset": "BUSD",
"targetAmount": "1.37576819",
"bizType": "EXCHANGE_SMALL_LIABILITY",
"timestamp": 1672801339253
}
]
}
"""
return self._request_margin_api(
"get", "margin/exchange-small-liability-history", True, data=params
)
```
Get user the next hourly estimate interest
[https://developers.binance.com/docs/margin\_trading/borrow-and-repay](https://developers.binance.com/docs/margin_trading/borrow-and-repay)
:param assets: List of assets, separated by commas, up to 20
:type assets: str
:param isIsolated: for isolated margin or not, "TRUE", "FALSE"
:type isIsolated: bool
:returns: API response
.. code-block:: python
\[
\{
"asset": "BTC",
"nextHourlyInterestRate": "0.00000571"
},
\{
"asset": "ETH",
"nextHourlyInterestRate": "0.00000578"
}
]
```python
def get_future_hourly_interest_rate(self, **params):
"""Get user the next hourly estimate interest
https://developers.binance.com/docs/margin_trading/borrow-and-repay
:param assets: List of assets, separated by commas, up to 20
:type assets: str
:param isIsolated: for isolated margin or not, "TRUE", "FALSE"
:type isIsolated: bool
:returns: API response
.. code-block:: python
[
{
"asset": "BTC",
"nextHourlyInterestRate": "0.00000571"
},
{
"asset": "ETH",
"nextHourlyInterestRate": "0.00000578"
}
]
"""
return self._request_margin_api(
"get", "margin/next-hourly-interest-rate", True, data=params
)
```
Get cross or isolated margin capital flow
[https://developers.binance.com/docs/margin\_trading/account/Query-Cross-Isolated-Margin-Capital-Flow](https://developers.binance.com/docs/margin_trading/account/Query-Cross-Isolated-Margin-Capital-Flow)
:param asset: optional
:type asset: str
:param symbol: Required when querying isolated data
:type symbol: str
:param type: optional
:type type: string
:param startTime: Only supports querying the data of the last 90 days
:type startTime: long
:param endTime: optional
:type endTime: long
:param formId: If fromId is set, the data with id > fromId will be returned. Otherwise the latest data will be returned
:type formId: long
:param limit: The number of data items returned each time is limited. Default 500; Max 1000.
:type limit: long
:returns: API response
.. code-block:: python
\[
\{
"id": 123456,
"tranId": 123123,
"timestamp": 1691116657000,
"asset": "USDT,
"symbol": "BTCUSDT",
"type": "BORROW",
"amount": "101"
},
\{
"id": 123457,
"tranId": 123124,
"timestamp": 1691116658000,
"asset": "BTC",
"symbol": "BTCUSDT",
"type": "REPAY",
"amount": "10"
}
]
```python
def get_margin_capital_flow(self, **params):
"""Get cross or isolated margin capital flow
https://developers.binance.com/docs/margin_trading/account/Query-Cross-Isolated-Margin-Capital-Flow
:param asset: optional
:type asset: str
:param symbol: Required when querying isolated data
:type symbol: str
:param type: optional
:type type: string
:param startTime: Only supports querying the data of the last 90 days
:type startTime: long
:param endTime: optional
:type endTime: long
:param formId: If fromId is set, the data with id > fromId will be returned. Otherwise the latest data will be returned
:type formId: long
:param limit: The number of data items returned each time is limited. Default 500; Max 1000.
:type limit: long
:returns: API response
.. code-block:: python
[
{
"id": 123456,
"tranId": 123123,
"timestamp": 1691116657000,
"asset": "USDT,
"symbol": "BTCUSDT",
"type": "BORROW",
"amount": "101"
},
{
"id": 123457,
"tranId": 123124,
"timestamp": 1691116658000,
"asset": "BTC",
"symbol": "BTCUSDT",
"type": "REPAY",
"amount": "10"
}
]
"""
return self._request_margin_api("get", "margin/capital-flow", True, data=params)
```
Query cross-margin asset
[https://binance-docs.github.io/apidocs/spot/en/#query-margin-asset-market\_data](https://binance-docs.github.io/apidocs/spot/en/#query-margin-asset-market_data)
:param asset: name of the asset
:type asset: str
.. code-block:: python
asset\_details = client.get\_margin\_asset(asset='BNB')
:returns: API response
.. code-block:: python
\{
"assetFullName": "Binance Coin",
"assetName": "BNB",
"isBorrowable": false,
"isMortgageable": true,
"userMinBorrow": "0.00000000",
"userMinRepay": "0.00000000"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_asset(self, **params):
"""Query cross-margin asset
https://binance-docs.github.io/apidocs/spot/en/#query-margin-asset-market_data
:param asset: name of the asset
:type asset: str
.. code-block:: python
asset_details = client.get_margin_asset(asset='BNB')
:returns: API response
.. code-block:: python
{
"assetFullName": "Binance Coin",
"assetName": "BNB",
"isBorrowable": false,
"isMortgageable": true,
"userMinBorrow": "0.00000000",
"userMinRepay": "0.00000000"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "margin/asset", data=params)
```
Query cross-margin symbol info
[https://binance-docs.github.io/apidocs/spot/en/#query-cross-margin-pair-market\_data](https://binance-docs.github.io/apidocs/spot/en/#query-cross-margin-pair-market_data)
:param symbol: name of the symbol pair
:type symbol: str
.. code:: python
pair\_details = client.get\_margin\_symbol(symbol='BTCUSDT')
:returns: API response
.. code-block:: python
\{
"id":323355778339572400,
"symbol":"BTCUSDT",
"base":"BTC",
"quote":"USDT",
"isMarginTrade":true,
"isBuyAllowed":true,
"isSellAllowed":true
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_symbol(self, **params):
"""Query cross-margin symbol info
https://binance-docs.github.io/apidocs/spot/en/#query-cross-margin-pair-market_data
:param symbol: name of the symbol pair
:type symbol: str
.. code:: python
pair_details = client.get_margin_symbol(symbol='BTCUSDT')
:returns: API response
.. code-block:: python
{
"id":323355778339572400,
"symbol":"BTCUSDT",
"base":"BTC",
"quote":"USDT",
"isMarginTrade":true,
"isBuyAllowed":true,
"isSellAllowed":true
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "margin/pair", data=params)
```
Get All Margin Assets (MARKET\_DATA)
[https://developers.binance.com/docs/margin\_trading/market-data/Get-All-Margin-Assets](https://developers.binance.com/docs/margin_trading/market-data/Get-All-Margin-Assets)
.. code:: python
margin\_assets = client.get\_margin\_all\_assets()
:returns: API response
.. code-block:: python
\[
\{
"assetFullName": "USD coin",
"assetName": "USDC",
"isBorrowable": true,
"isMortgageable": true,
"userMinBorrow": "0.00000000",
"userMinRepay": "0.00000000"
},
\{
"assetFullName": "BNB-coin",
"assetName": "BNB",
"isBorrowable": true,
"isMortgageable": true,
"userMinBorrow": "1.00000000",
"userMinRepay": "0.00000000"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_all_assets(self, **params):
"""Get All Margin Assets (MARKET_DATA)
https://developers.binance.com/docs/margin_trading/market-data/Get-All-Margin-Assets
.. code:: python
margin_assets = client.get_margin_all_assets()
:returns: API response
.. code-block:: python
[
{
"assetFullName": "USD coin",
"assetName": "USDC",
"isBorrowable": true,
"isMortgageable": true,
"userMinBorrow": "0.00000000",
"userMinRepay": "0.00000000"
},
{
"assetFullName": "BNB-coin",
"assetName": "BNB",
"isBorrowable": true,
"isMortgageable": true,
"userMinBorrow": "1.00000000",
"userMinRepay": "0.00000000"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "margin/allAssets", data=params)
```
Get All Cross Margin Pairs (MARKET\_DATA)
[https://developers.binance.com/docs/margin\_trading/market-data/Get-All-Cross-Margin-Pairs](https://developers.binance.com/docs/margin_trading/market-data/Get-All-Cross-Margin-Pairs)
.. code:: python
margin\_pairs = client.get\_margin\_all\_pairs()
:returns: API response
.. code-block:: python
\[
\{
"base": "BNB",
"id": 351637150141315861,
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "BNBBTC"
},
\{
"base": "TRX",
"id": 351637923235429141,
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "TRXBTC"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_all_pairs(self, **params):
"""Get All Cross Margin Pairs (MARKET_DATA)
https://developers.binance.com/docs/margin_trading/market-data/Get-All-Cross-Margin-Pairs
.. code:: python
margin_pairs = client.get_margin_all_pairs()
:returns: API response
.. code-block:: python
[
{
"base": "BNB",
"id": 351637150141315861,
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "BNBBTC"
},
{
"base": "TRX",
"id": 351637923235429141,
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "TRXBTC"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "margin/allPairs", data=params)
```
Create isolated margin account for symbol
[https://binance-docs.github.io/apidocs/spot/en/#create-isolated-margin-account-margin](https://binance-docs.github.io/apidocs/spot/en/#create-isolated-margin-account-margin)
:param base: Base asset of symbol
:type base: str
:param quote: Quote asset of symbol
:type quote: str
.. code:: python
pair\_details = client.create\_isolated\_margin\_account(base='USDT', quote='BTC')
:returns: API response
.. code-block:: python
\{
"success": true,
"symbol": "BTCUSDT"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def create_isolated_margin_account(self, **params):
"""Create isolated margin account for symbol
https://binance-docs.github.io/apidocs/spot/en/#create-isolated-margin-account-margin
:param base: Base asset of symbol
:type base: str
:param quote: Quote asset of symbol
:type quote: str
.. code:: python
pair_details = client.create_isolated_margin_account(base='USDT', quote='BTC')
:returns: API response
.. code-block:: python
{
"success": true,
"symbol": "BTCUSDT"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "margin/isolated/create", signed=True, data=params
)
```
Query isolated margin symbol info
[https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-symbol-user\_data](https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-symbol-user_data)
:param symbol: name of the symbol pair
:type symbol: str
.. code:: python
pair\_details = client.get\_isolated\_margin\_symbol(symbol='BTCUSDT')
:returns: API response
.. code-block:: python
\{
"symbol":"BTCUSDT",
"base":"BTC",
"quote":"USDT",
"isMarginTrade":true,
"isBuyAllowed":true,
"isSellAllowed":true
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_isolated_margin_symbol(self, **params):
"""Query isolated margin symbol info
https://binance-docs.github.io/apidocs/spot/en/#query-isolated-margin-symbol-user_data
:param symbol: name of the symbol pair
:type symbol: str
.. code:: python
pair_details = client.get_isolated_margin_symbol(symbol='BTCUSDT')
:returns: API response
.. code-block:: python
{
"symbol":"BTCUSDT",
"base":"BTC",
"quote":"USDT",
"isMarginTrade":true,
"isBuyAllowed":true,
"isSellAllowed":true
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "margin/isolated/pair", signed=True, data=params
)
```
Query isolated margin symbol info for all pairs
[https://developers.binance.com/docs/margin\_trading/market-data/Get-All-Isolated-Margin-Symbol](https://developers.binance.com/docs/margin_trading/market-data/Get-All-Isolated-Margin-Symbol)
.. code:: python
pair\_details = client.get\_all\_isolated\_margin\_symbols()
:returns: API response
.. code-block:: python
\[
\{
"base": "BNB",
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "BNBBTC"
},
\{
"base": "TRX",
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "TRXBTC"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_all_isolated_margin_symbols(self, **params):
"""Query isolated margin symbol info for all pairs
https://developers.binance.com/docs/margin_trading/market-data/Get-All-Isolated-Margin-Symbol
.. code:: python
pair_details = client.get_all_isolated_margin_symbols()
:returns: API response
.. code-block:: python
[
{
"base": "BNB",
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "BNBBTC"
},
{
"base": "TRX",
"isBuyAllowed": true,
"isMarginTrade": true,
"isSellAllowed": true,
"quote": "BTC",
"symbol": "TRXBTC"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "margin/isolated/allPairs", signed=True, data=params
)
```
Get isolated margin fee data collection with any vip level or user's current specific data as [https://www.binance.com/en/margin-fee](https://www.binance.com/en/margin-fee)
[https://developers.binance.com/docs/margin\_trading/account/Query-Isolated-Margin-Fee-Data](https://developers.binance.com/docs/margin_trading/account/Query-Isolated-Margin-Fee-Data)
:param vipLevel: User's current specific margin data will be returned if vipLevel is omitted
:type vipLevel: int
:param symbol: optional
:type symbol: str
:returns: API response
.. code-block:: python
\[
\{
"vipLevel": 0,
"symbol": "BTCUSDT",
"leverage": "10",
"data": \[
\{
"coin": "BTC",
"dailyInterest": "0.00026125",
"borrowLimit": "270"
},
\{
"coin": "USDT",
"dailyInterest": "0.000475",
"borrowLimit": "2100000"
}
]
}
]
```python
def get_isolated_margin_fee_data(self, **params):
"""Get isolated margin fee data collection with any vip level or user's current specific data as https://www.binance.com/en/margin-fee
https://developers.binance.com/docs/margin_trading/account/Query-Isolated-Margin-Fee-Data
:param vipLevel: User's current specific margin data will be returned if vipLevel is omitted
:type vipLevel: int
:param symbol: optional
:type symbol: str
:returns: API response
.. code-block:: python
[
{
"vipLevel": 0,
"symbol": "BTCUSDT",
"leverage": "10",
"data": [
{
"coin": "BTC",
"dailyInterest": "0.00026125",
"borrowLimit": "270"
},
{
"coin": "USDT",
"dailyInterest": "0.000475",
"borrowLimit": "2100000"
}
]
}
]
"""
return self._request_margin_api(
"get", "margin/isolatedMarginData", True, data=params
)
```
Get isolated margin tier data collection with any tier as [https://www.binance.com/en/margin-data](https://www.binance.com/en/margin-data)
[https://developers.binance.com/docs/margin\_trading/market-data/Query-Isolated-Margin-Tier-Data](https://developers.binance.com/docs/margin_trading/market-data/Query-Isolated-Margin-Tier-Data)
:param symbol: required
:type symbol: str
:param tier: All margin tier data will be returned if tier is omitted
:type tier: int
:param recvWindow: optional: No more than 60000
:type recvWindow:
:returns: API response
.. code-block:: python
\[
\{
"symbol": "BTCUSDT",
"tier": 1,
"effectiveMultiple": "10",
"initialRiskRatio": "1.111",
"liquidationRiskRatio": "1.05",
"baseAssetMaxBorrowable": "9",
"quoteAssetMaxBorrowable": "70000"
}
]
```python
def get_isolated_margin_tier_data(self, **params):
"""Get isolated margin tier data collection with any tier as https://www.binance.com/en/margin-data
https://developers.binance.com/docs/margin_trading/market-data/Query-Isolated-Margin-Tier-Data
:param symbol: required
:type symbol: str
:param tier: All margin tier data will be returned if tier is omitted
:type tier: int
:param recvWindow: optional: No more than 60000
:type recvWindow:
:returns: API response
.. code-block:: python
[
{
"symbol": "BTCUSDT",
"tier": 1,
"effectiveMultiple": "10",
"initialRiskRatio": "1.111",
"liquidationRiskRatio": "1.05",
"baseAssetMaxBorrowable": "9",
"quoteAssetMaxBorrowable": "70000"
}
]
"""
return self._request_margin_api(
"get", "margin/isolatedMarginTier", True, data=params
)
```
[https://developers.binance.com/docs/margin\_trading/trade/Margin-Manual-Liquidation](https://developers.binance.com/docs/margin_trading/trade/Margin-Manual-Liquidation)
:param type: required
:type symbol: str: When type selected is "ISOLATED", symbol must be filled in
:returns: API response
\[
\{
"asset": "ETH",
"interest": "0.00083334",
"principal": "0.001",
"liabilityAsset": "USDT",
"liabilityQty": 0.3552
}
]
```python
def margin_manual_liquidation(self, **params):
"""
https://developers.binance.com/docs/margin_trading/trade/Margin-Manual-Liquidation
:param type: required
:type symbol: str: When type selected is "ISOLATED", symbol must be filled in
:returns: API response
[
{
"asset": "ETH",
"interest": "0.00083334",
"principal": "0.001",
"liabilityAsset": "USDT",
"liabilityQty": 0.3552
}
]
"""
return self._request_margin_api(
"post", "margin/manual-liquidation", True, data=params
)
```
Toggle BNB Burn On Spot Trade And Margin Interest
[https://developers.binance.com/docs/wallet/asset/Toggle-BNB-Burn-On-Spot-Trade-And-Margin-Interest](https://developers.binance.com/docs/wallet/asset/Toggle-BNB-Burn-On-Spot-Trade-And-Margin-Interest)
:param spotBNBBurn: Determines whether to use BNB to pay for trading fees on SPOT
:type spotBNBBurn: bool
:param interestBNBBurn: Determines whether to use BNB to pay for margin loan's interest
:type interestBNBBurn: bool
.. code:: python
response = client.toggle\_bnb\_burn\_spot\_margin()
:returns: API response
.. code-block:: python
\{
"spotBNBBurn":true,
"interestBNBBurn": false
}
:raises: BinanceRequestException, BinanceAPIException
```python
def toggle_bnb_burn_spot_margin(self, **params):
"""Toggle BNB Burn On Spot Trade And Margin Interest
https://developers.binance.com/docs/wallet/asset/Toggle-BNB-Burn-On-Spot-Trade-And-Margin-Interest
:param spotBNBBurn: Determines whether to use BNB to pay for trading fees on SPOT
:type spotBNBBurn: bool
:param interestBNBBurn: Determines whether to use BNB to pay for margin loan's interest
:type interestBNBBurn: bool
.. code:: python
response = client.toggle_bnb_burn_spot_margin()
:returns: API response
.. code-block:: python
{
"spotBNBBurn":true,
"interestBNBBurn": false
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("post", "bnbBurn", signed=True, data=params)
```
Get BNB Burn Status
[https://developers.binance.com/docs/margin\_trading/account/Get-BNB-Burn-Status](https://developers.binance.com/docs/margin_trading/account/Get-BNB-Burn-Status)
.. code:: python
status = client.get\_bnb\_burn\_spot\_margin()
:returns: API response
.. code-block:: python
\{
"spotBNBBurn":true,
"interestBNBBurn": false
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_bnb_burn_spot_margin(self, **params):
"""Get BNB Burn Status
https://developers.binance.com/docs/margin_trading/account/Get-BNB-Burn-Status
.. code:: python
status = client.get_bnb_burn_spot_margin()
:returns: API response
.. code-block:: python
{
"spotBNBBurn":true,
"interestBNBBurn": false
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "bnbBurn", signed=True, data=params)
```
Query margin priceIndex
[https://developers.binance.com/docs/margin\_trading/market-data/Query-Margin-PriceIndex](https://developers.binance.com/docs/margin_trading/market-data/Query-Margin-PriceIndex)
:param symbol: name of the symbol pair
:type symbol: str
.. code:: python
price\_index\_details = client.get\_margin\_price\_index(symbol='BTCUSDT')
:returns: API response
.. code-block:: python
\{
"calcTime": 1562046418000,
"price": "0.00333930",
"symbol": "BNBBTC"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_price_index(self, **params):
"""Query margin priceIndex
https://developers.binance.com/docs/margin_trading/market-data/Query-Margin-PriceIndex
:param symbol: name of the symbol pair
:type symbol: str
.. code:: python
price_index_details = client.get_margin_price_index(symbol='BTCUSDT')
:returns: API response
.. code-block:: python
{
"calcTime": 1562046418000,
"price": "0.00333930",
"symbol": "BNBBTC"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "margin/priceIndex", data=params)
```
Execute transfer between cross-margin account and spot account.
[https://binance-docs.github.io/apidocs/spot/en/#cross-margin-account-transfer-margin](https://binance-docs.github.io/apidocs/spot/en/#cross-margin-account-transfer-margin)
:param asset: name of the asset
:type asset: str
:param amount: amount to transfer
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer\_margin\_to\_spot(asset='BTC', amount='1.1')
:returns: API response
.. code-block:: python
\{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
```python
def transfer_margin_to_spot(self, **params):
"""Execute transfer between cross-margin account and spot account.
https://binance-docs.github.io/apidocs/spot/en/#cross-margin-account-transfer-margin
:param asset: name of the asset
:type asset: str
:param amount: amount to transfer
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer_margin_to_spot(asset='BTC', amount='1.1')
:returns: API response
.. code-block:: python
{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
"""
params["type"] = 2
return self._request_margin_api(
"post", "margin/transfer", signed=True, data=params
)
```
Execute transfer between spot account and cross-margin account.
[https://binance-docs.github.io/apidocs/spot/en/#cross-margin-account-transfer-margin](https://binance-docs.github.io/apidocs/spot/en/#cross-margin-account-transfer-margin)
:param asset: name of the asset
:type asset: str
:param amount: amount to transfer
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer\_spot\_to\_margin(asset='BTC', amount='1.1')
:returns: API response
.. code-block:: python
\{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
```python
def transfer_spot_to_margin(self, **params):
"""Execute transfer between spot account and cross-margin account.
https://binance-docs.github.io/apidocs/spot/en/#cross-margin-account-transfer-margin
:param asset: name of the asset
:type asset: str
:param amount: amount to transfer
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer_spot_to_margin(asset='BTC', amount='1.1')
:returns: API response
.. code-block:: python
{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
"""
params["type"] = 1
return self._request_margin_api(
"post", "margin/transfer", signed=True, data=params
)
```
Execute transfer between isolated margin account and spot account.
[https://binance-docs.github.io/apidocs/spot/en/#isolated-margin-account-transfer-margin](https://binance-docs.github.io/apidocs/spot/en/#isolated-margin-account-transfer-margin)
:param asset: name of the asset
:type asset: str
:param symbol: pair symbol
:type symbol: str
:param amount: amount to transfer
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer\_isolated\_margin\_to\_spot(asset='BTC',
symbol='ETHBTC', amount='1.1')
:returns: API response
.. code-block:: python
\{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
```python
def transfer_isolated_margin_to_spot(self, **params):
"""Execute transfer between isolated margin account and spot account.
https://binance-docs.github.io/apidocs/spot/en/#isolated-margin-account-transfer-margin
:param asset: name of the asset
:type asset: str
:param symbol: pair symbol
:type symbol: str
:param amount: amount to transfer
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer_isolated_margin_to_spot(asset='BTC',
symbol='ETHBTC', amount='1.1')
:returns: API response
.. code-block:: python
{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
"""
params["transFrom"] = "ISOLATED_MARGIN"
params["transTo"] = "SPOT"
return self._request_margin_api(
"post", "margin/isolated/transfer", signed=True, data=params
)
```
Execute transfer between spot account and isolated margin account.
[https://binance-docs.github.io/apidocs/spot/en/#isolated-margin-account-transfer-margin](https://binance-docs.github.io/apidocs/spot/en/#isolated-margin-account-transfer-margin)
:param asset: name of the asset
:type asset: str
:param symbol: pair symbol
:type symbol: str
:param amount: amount to transfer
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer\_spot\_to\_isolated\_margin(asset='BTC',
symbol='ETHBTC', amount='1.1')
:returns: API response
.. code-block:: python
\{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
```python
def transfer_spot_to_isolated_margin(self, **params):
"""Execute transfer between spot account and isolated margin account.
https://binance-docs.github.io/apidocs/spot/en/#isolated-margin-account-transfer-margin
:param asset: name of the asset
:type asset: str
:param symbol: pair symbol
:type symbol: str
:param amount: amount to transfer
:type amount: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer_spot_to_isolated_margin(asset='BTC',
symbol='ETHBTC', amount='1.1')
:returns: API response
.. code-block:: python
{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
"""
params["transFrom"] = "SPOT"
params["transTo"] = "ISOLATED_MARGIN"
return self._request_margin_api(
"post", "margin/isolated/transfer", signed=True, data=params
)
```
Get transfers to isolated margin account.
[https://binance-docs.github.io/apidocs/spot/en/#get-isolated-margin-transfer-history-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-isolated-margin-transfer-history-user_data)
:param asset: name of the asset
:type asset: str
:param symbol: pair required
:type symbol: str
:param transFrom: optional SPOT, ISOLATED\_MARGIN
:param transFrom: str SPOT, ISOLATED\_MARGIN
:param transTo: optional
:param transTo: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer\_spot\_to\_isolated\_margin(symbol='ETHBTC')
:returns: API response
.. code-block:: python
\{
"rows": \[
\{
"amount": "0.10000000",
"asset": "BNB",
"status": "CONFIRMED",
"timestamp": 1566898617000,
"txId": 5240372201,
"transFrom": "SPOT",
"transTo": "ISOLATED\_MARGIN"
},
\{
"amount": "5.00000000",
"asset": "USDT",
"status": "CONFIRMED",
"timestamp": 1566888436123,
"txId": 5239810406,
"transFrom": "ISOLATED\_MARGIN",
"transTo": "SPOT"
}
],
"total": 2
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_isolated_margin_tranfer_history(self, **params):
"""Get transfers to isolated margin account.
https://binance-docs.github.io/apidocs/spot/en/#get-isolated-margin-transfer-history-user_data
:param asset: name of the asset
:type asset: str
:param symbol: pair required
:type symbol: str
:param transFrom: optional SPOT, ISOLATED_MARGIN
:param transFrom: str SPOT, ISOLATED_MARGIN
:param transTo: optional
:param transTo: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transfer = client.transfer_spot_to_isolated_margin(symbol='ETHBTC')
:returns: API response
.. code-block:: python
{
"rows": [
{
"amount": "0.10000000",
"asset": "BNB",
"status": "CONFIRMED",
"timestamp": 1566898617000,
"txId": 5240372201,
"transFrom": "SPOT",
"transTo": "ISOLATED_MARGIN"
},
{
"amount": "5.00000000",
"asset": "USDT",
"status": "CONFIRMED",
"timestamp": 1566888436123,
"txId": 5239810406,
"transFrom": "ISOLATED_MARGIN",
"transTo": "SPOT"
}
],
"total": 2
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "margin/isolated/transfer", signed=True, data=params
)
```
Apply for a loan in cross-margin or isolated-margin account.
[https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-margin](https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-margin)
:param asset: name of the asset
:type asset: str
:param amount: amount to transfer
:type amount: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param symbol: Isolated margin symbol (default blank for cross-margin)
:type symbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transaction = client.margin\_create\_loan(asset='BTC', amount='1.1')
transaction = client.margin\_create\_loan(asset='BTC', amount='1.1',
isIsolated='TRUE', symbol='ETHBTC')
:returns: API response
.. code-block:: python
\{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
```python
def create_margin_loan(self, **params):
"""Apply for a loan in cross-margin or isolated-margin account.
https://binance-docs.github.io/apidocs/spot/en/#margin-account-borrow-margin
:param asset: name of the asset
:type asset: str
:param amount: amount to transfer
:type amount: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param symbol: Isolated margin symbol (default blank for cross-margin)
:type symbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transaction = client.margin_create_loan(asset='BTC', amount='1.1')
transaction = client.margin_create_loan(asset='BTC', amount='1.1',
isIsolated='TRUE', symbol='ETHBTC')
:returns: API response
.. code-block:: python
{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("post", "margin/loan", signed=True, data=params)
```
Repay loan in cross-margin or isolated-margin account.
If amount is more than the amount borrowed, the full loan will be repaid.
[https://binance-docs.github.io/apidocs/spot/en/#margin-account-repay-margin](https://binance-docs.github.io/apidocs/spot/en/#margin-account-repay-margin)
:param asset: name of the asset
:type asset: str
:param amount: amount to transfer
:type amount: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param symbol: Isolated margin symbol (default blank for cross-margin)
:type symbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transaction = client.margin\_repay\_loan(asset='BTC', amount='1.1')
transaction = client.margin\_repay\_loan(asset='BTC', amount='1.1',
isIsolated='TRUE', symbol='ETHBTC')
:returns: API response
.. code-block:: python
\{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
```python
def repay_margin_loan(self, **params):
"""Repay loan in cross-margin or isolated-margin account.
If amount is more than the amount borrowed, the full loan will be repaid.
https://binance-docs.github.io/apidocs/spot/en/#margin-account-repay-margin
:param asset: name of the asset
:type asset: str
:param amount: amount to transfer
:type amount: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param symbol: Isolated margin symbol (default blank for cross-margin)
:type symbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code-block:: python
transaction = client.margin_repay_loan(asset='BTC', amount='1.1')
transaction = client.margin_repay_loan(asset='BTC', amount='1.1',
isIsolated='TRUE', symbol='ETHBTC')
:returns: API response
.. code-block:: python
{
"tranId": 100000001
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "margin/repay", signed=True, data=params
)
```
Post a new order for margin account.
[https://developers.binance.com/docs/margin\_trading/trade/Margin-Account-New-Order](https://developers.binance.com/docs/margin_trading/trade/Margin-Account-New-Order)
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param side: required
:type side: str
:param type: required
:type type: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param stopPrice: Used with STOP\_LOSS, STOP\_LOSS\_LIMIT, TAKE\_PROFIT, and TAKE\_PROFIT\_LIMIT orders.
:type stopPrice: str
:param timeInForce: required if limit order GTC,IOC,FOK
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP\_LOSS\_LIMIT, and TAKE\_PROFIT\_LIMIT to create an iceberg order.
:type icebergQty: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; MARKET and LIMIT order types default to
FULL, all other orders default to ACK.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
Response ACK:
.. code-block:: python
\{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595
}
Response RESULT:
.. code-block:: python
\{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "1.00000000",
"origQty": "10.00000000",
"executedQty": "10.00000000",
"cummulativeQuoteQty": "10.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "MARKET",
"side": "SELL"
}
Response FULL:
.. code-block:: python
\{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "1.00000000",
"origQty": "10.00000000",
"executedQty": "10.00000000",
"cummulativeQuoteQty": "10.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "MARKET",
"side": "SELL",
"fills": \[
\{
"price": "4000.00000000",
"qty": "1.00000000",
"commission": "4.00000000",
"commissionAsset": "USDT"
},
\{
"price": "3999.00000000",
"qty": "5.00000000",
"commission": "19.99500000",
"commissionAsset": "USDT"
},
\{
"price": "3998.00000000",
"qty": "2.00000000",
"commission": "7.99600000",
"commissionAsset": "USDT"
},
\{
"price": "3997.00000000",
"qty": "1.00000000",
"commission": "3.99700000",
"commissionAsset": "USDT"
},
\{
"price": "3995.00000000",
"qty": "1.00000000",
"commission": "3.99500000",
"commissionAsset": "USDT"
}
]
}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException,
BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException,
BinanceOrderInactiveSymbolException
```python
def create_margin_order(self, **params):
"""Post a new order for margin account.
https://developers.binance.com/docs/margin_trading/trade/Margin-Account-New-Order
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param side: required
:type side: str
:param type: required
:type type: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param stopPrice: Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
:type stopPrice: str
:param timeInForce: required if limit order GTC,IOC,FOK
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
:type icebergQty: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; MARKET and LIMIT order types default to
FULL, all other orders default to ACK.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
Response ACK:
.. code-block:: python
{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595
}
Response RESULT:
.. code-block:: python
{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "1.00000000",
"origQty": "10.00000000",
"executedQty": "10.00000000",
"cummulativeQuoteQty": "10.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "MARKET",
"side": "SELL"
}
Response FULL:
.. code-block:: python
{
"symbol": "BTCUSDT",
"orderId": 28,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "1.00000000",
"origQty": "10.00000000",
"executedQty": "10.00000000",
"cummulativeQuoteQty": "10.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "MARKET",
"side": "SELL",
"fills": [
{
"price": "4000.00000000",
"qty": "1.00000000",
"commission": "4.00000000",
"commissionAsset": "USDT"
},
{
"price": "3999.00000000",
"qty": "5.00000000",
"commission": "19.99500000",
"commissionAsset": "USDT"
},
{
"price": "3998.00000000",
"qty": "2.00000000",
"commission": "7.99600000",
"commissionAsset": "USDT"
},
{
"price": "3997.00000000",
"qty": "1.00000000",
"commission": "3.99700000",
"commissionAsset": "USDT"
},
{
"price": "3995.00000000",
"qty": "1.00000000",
"commission": "3.99500000",
"commissionAsset": "USDT"
}
]
}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException,
BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException,
BinanceOrderInactiveSymbolException
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return self._request_margin_api(
"post", "margin/order", signed=True, data=params
)
```
Cancel an active order for margin account.
Either orderId or origClientOrderId must be sent.
[https://developers.binance.com/docs/margin\_trading/trade/Margin-Account-Cancel-Order](https://developers.binance.com/docs/margin_trading/trade/Margin-Account-Cancel-Order)
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param orderId:
:type orderId: str
:param origClientOrderId:
:type origClientOrderId: str
:param newClientOrderId: Used to uniquely identify this cancel. Automatically generated by default.
:type newClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"symbol": "LTCBTC",
"orderId": 28,
"origClientOrderId": "myOrder1",
"clientOrderId": "cancelMyOrder1",
"transactTime": 1507725176595,
"price": "1.00000000",
"origQty": "10.00000000",
"executedQty": "8.00000000",
"cummulativeQuoteQty": "8.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def cancel_margin_order(self, **params):
"""Cancel an active order for margin account.
Either orderId or origClientOrderId must be sent.
https://developers.binance.com/docs/margin_trading/trade/Margin-Account-Cancel-Order
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param orderId:
:type orderId: str
:param origClientOrderId:
:type origClientOrderId: str
:param newClientOrderId: Used to uniquely identify this cancel. Automatically generated by default.
:type newClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"symbol": "LTCBTC",
"orderId": 28,
"origClientOrderId": "myOrder1",
"clientOrderId": "cancelMyOrder1",
"transactTime": 1507725176595,
"price": "1.00000000",
"origQty": "10.00000000",
"executedQty": "8.00000000",
"cummulativeQuoteQty": "8.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"delete", "margin/order", signed=True, data=params
)
```
Cancels all active orders on a symbol for margin account.
[https://developers.binance.com/docs/margin\_trading/trade/Margin-Account-Cancel-All-Open-Orders](https://developers.binance.com/docs/margin_trading/trade/Margin-Account-Cancel-All-Open-Orders)
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
:raises: BinanceRequestException, BinanceAPIException
```python
def cancel_all_open_margin_orders(self, **params):
"""
Cancels all active orders on a symbol for margin account.
https://developers.binance.com/docs/margin_trading/trade/Margin-Account-Cancel-All-Open-Orders
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"delete", "margin/openOrders", signed=True, data=params
)
```
Adjust cross margin max leverage
[https://developers.binance.com/docs/margin\_trading/account](https://developers.binance.com/docs/margin_trading/account)
:param maxLeverage: required Can only adjust 3 or 5,Example: maxLeverage=3
:type maxLeverage: int
:returns: API response
\{
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
```python
def set_margin_max_leverage(self, **params):
"""Adjust cross margin max leverage
https://developers.binance.com/docs/margin_trading/account
:param maxLeverage: required Can only adjust 3 or 5,Example: maxLeverage=3
:type maxLeverage: int
:returns: API response
{
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "margin/max-leverage", signed=True, data=params
)
```
Query margin transfer history
[https://developers.binance.com/docs/margin\_trading/transfer](https://developers.binance.com/docs/margin_trading/transfer)
:param asset: optional
:type asset: str
:param type: optional Transfer Type: ROLL\_IN, ROLL\_OUT
:type type: str
:param archived: optional Default: false. Set to true for archived data from 6 months ago
:type archived: str
:param startTime: earliest timestamp to filter transactions
:type startTime: str
:param endTime: Used to uniquely identify this cancel. Automatically generated by default.
:type endTime: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"rows": \[
\{
"amount": "0.10000000",
"asset": "BNB",
"status": "CONFIRMED",
"timestamp": 1566898617,
"txId": 5240372201,
"type": "ROLL\_IN"
},
\{
"amount": "5.00000000",
"asset": "USDT",
"status": "CONFIRMED",
"timestamp": 1566888436,
"txId": 5239810406,
"type": "ROLL\_OUT"
},
\{
"amount": "1.00000000",
"asset": "EOS",
"status": "CONFIRMED",
"timestamp": 1566888403,
"txId": 5239808703,
"type": "ROLL\_IN"
}
],
"total": 3
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_transfer_history(self, **params):
"""Query margin transfer history
https://developers.binance.com/docs/margin_trading/transfer
:param asset: optional
:type asset: str
:param type: optional Transfer Type: ROLL_IN, ROLL_OUT
:type type: str
:param archived: optional Default: false. Set to true for archived data from 6 months ago
:type archived: str
:param startTime: earliest timestamp to filter transactions
:type startTime: str
:param endTime: Used to uniquely identify this cancel. Automatically generated by default.
:type endTime: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"rows": [
{
"amount": "0.10000000",
"asset": "BNB",
"status": "CONFIRMED",
"timestamp": 1566898617,
"txId": 5240372201,
"type": "ROLL_IN"
},
{
"amount": "5.00000000",
"asset": "USDT",
"status": "CONFIRMED",
"timestamp": 1566888436,
"txId": 5239810406,
"type": "ROLL_OUT"
},
{
"amount": "1.00000000",
"asset": "EOS",
"status": "CONFIRMED",
"timestamp": 1566888403,
"txId": 5239808703,
"type": "ROLL_IN"
}
],
"total": 3
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "margin/transfer", signed=True, data=params
)
```
Query loan record
txId or startTime must be sent. txId takes precedence.
[https://binance-docs.github.io/apidocs/spot/en/#query-loan-record-user\_data](https://binance-docs.github.io/apidocs/spot/en/#query-loan-record-user_data)
:param asset: required
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param txId: the tranId in of the created loan
:type txId: str
:param startTime: earliest timestamp to filter transactions
:type startTime: str
:param endTime: Used to uniquely identify this cancel. Automatically generated by default.
:type endTime: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"rows": \[
\{
"asset": "BNB",
"principal": "0.84624403",
"timestamp": 1555056425000,
//one of PENDING (pending to execution), CONFIRMED (successfully loaned), FAILED (execution failed, nothing happened to your account);
"status": "CONFIRMED"
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_loan_details(self, **params):
"""Query loan record
txId or startTime must be sent. txId takes precedence.
https://binance-docs.github.io/apidocs/spot/en/#query-loan-record-user_data
:param asset: required
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param txId: the tranId in of the created loan
:type txId: str
:param startTime: earliest timestamp to filter transactions
:type startTime: str
:param endTime: Used to uniquely identify this cancel. Automatically generated by default.
:type endTime: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"rows": [
{
"asset": "BNB",
"principal": "0.84624403",
"timestamp": 1555056425000,
//one of PENDING (pending to execution), CONFIRMED (successfully loaned), FAILED (execution failed, nothing happened to your account);
"status": "CONFIRMED"
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "margin/loan", signed=True, data=params)
```
Query repay record
txId or startTime must be sent. txId takes precedence.
[https://binance-docs.github.io/apidocs/spot/en/#query-repay-record-user\_data](https://binance-docs.github.io/apidocs/spot/en/#query-repay-record-user_data)
:param asset: required
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param txId: the tranId in of the created loan
:type txId: str
:param startTime:
:type startTime: str
:param endTime: Used to uniquely identify this cancel. Automatically generated by default.
:type endTime: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"rows": \[
\{
//Total amount repaid
"amount": "14.00000000",
"asset": "BNB",
//Interest repaid
"interest": "0.01866667",
//Principal repaid
"principal": "13.98133333",
//one of PENDING (pending to execution), CONFIRMED (successfully loaned), FAILED (execution failed, nothing happened to your account);
"status": "CONFIRMED",
"timestamp": 1563438204000,
"txId": 2970933056
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_repay_details(self, **params):
"""Query repay record
txId or startTime must be sent. txId takes precedence.
https://binance-docs.github.io/apidocs/spot/en/#query-repay-record-user_data
:param asset: required
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param txId: the tranId in of the created loan
:type txId: str
:param startTime:
:type startTime: str
:param endTime: Used to uniquely identify this cancel. Automatically generated by default.
:type endTime: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"rows": [
{
//Total amount repaid
"amount": "14.00000000",
"asset": "BNB",
//Interest repaid
"interest": "0.01866667",
//Principal repaid
"principal": "13.98133333",
//one of PENDING (pending to execution), CONFIRMED (successfully loaned), FAILED (execution failed, nothing happened to your account);
"status": "CONFIRMED",
"timestamp": 1563438204000,
"txId": 2970933056
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "margin/repay", signed=True, data=params)
```
Query Cross Margin Fee Data (USER\_DATA)
[https://developers.binance.com/docs/margin\_trading/account/Query-Cross-Margin-Fee-Data](https://developers.binance.com/docs/margin_trading/account/Query-Cross-Margin-Fee-Data)
:param vipLevel: User's current specific margin data will be returned if vipLevel is omitted
:type vipLevel: int
:param coin
:type coin: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response (example):
\[
\{
"vipLevel": 0,
"coin": "BTC",
"transferIn": true,
"borrowable": true,
"dailyInterest": "0.00026125",
"yearlyInterest": "0.0953",
"borrowLimit": "180",
"marginablePairs": \[
"BNBBTC",
"TRXBTC",
"ETHBTC",
"BTCUSDT"
]
}
]
```python
def get_cross_margin_data(self, **params):
"""Query Cross Margin Fee Data (USER_DATA)
https://developers.binance.com/docs/margin_trading/account/Query-Cross-Margin-Fee-Data
:param vipLevel: User's current specific margin data will be returned if vipLevel is omitted
:type vipLevel: int
:param coin
:type coin: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response (example):
[
{
"vipLevel": 0,
"coin": "BTC",
"transferIn": true,
"borrowable": true,
"dailyInterest": "0.00026125",
"yearlyInterest": "0.0953",
"borrowLimit": "180",
"marginablePairs": [
"BNBBTC",
"TRXBTC",
"ETHBTC",
"BTCUSDT"
]
}
]
"""
return self._request_margin_api(
"get", "margin/crossMarginData", signed=True, data=params
)
```
Get Interest History (USER\_DATA)
[https://developers.binance.com/docs/margin\_trading/borrow-and-repay/Get-Interest-History](https://developers.binance.com/docs/margin_trading/borrow-and-repay/Get-Interest-History)
:param asset:
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param startTime:
:type startTime: str
:param endTime:
:type endTime: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param archived: Default: false. Set to true for archived data from 6 months ago
:type archived: bool
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"rows":\[
\{
"isolatedSymbol": "BNBUSDT", // isolated symbol, will not be returned for crossed margin
"asset": "BNB",
"interest": "0.02414667",
"interestAccuredTime": 1566813600000,
"interestRate": "0.01600000",
"principal": "36.22000000",
"type": "ON\_BORROW"
}
],
"total": 1
}
```python
def get_margin_interest_history(self, **params):
"""Get Interest History (USER_DATA)
https://developers.binance.com/docs/margin_trading/borrow-and-repay/Get-Interest-History
:param asset:
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param startTime:
:type startTime: str
:param endTime:
:type endTime: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param archived: Default: false. Set to true for archived data from 6 months ago
:type archived: bool
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"rows":[
{
"isolatedSymbol": "BNBUSDT", // isolated symbol, will not be returned for crossed margin
"asset": "BNB",
"interest": "0.02414667",
"interestAccuredTime": 1566813600000,
"interestRate": "0.01600000",
"principal": "36.22000000",
"type": "ON_BORROW"
}
],
"total": 1
}
"""
return self._request_margin_api(
"get", "margin/interestHistory", signed=True, data=params
)
```
Get Force Liquidation Record (USER\_DATA)
[https://developers.binance.com/docs/margin\_trading/trade](https://developers.binance.com/docs/margin_trading/trade)
:param startTime:
:type startTime: str
:param endTime:
:type endTime: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"rows": \[
\{
"avgPrice": "0.00388359",
"executedQty": "31.39000000",
"orderId": 180015097,
"price": "0.00388110",
"qty": "31.39000000",
"side": "SELL",
"symbol": "BNBBTC",
"timeInForce": "GTC",
"isIsolated": true,
"updatedTime": 1558941374745
}
],
"total": 1
}
```python
def get_margin_force_liquidation_rec(self, **params):
"""Get Force Liquidation Record (USER_DATA)
https://developers.binance.com/docs/margin_trading/trade
:param startTime:
:type startTime: str
:param endTime:
:type endTime: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param current: Currently querying page. Start from 1. Default:1
:type current: str
:param size: Default:10 Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"rows": [
{
"avgPrice": "0.00388359",
"executedQty": "31.39000000",
"orderId": 180015097,
"price": "0.00388110",
"qty": "31.39000000",
"side": "SELL",
"symbol": "BNBBTC",
"timeInForce": "GTC",
"isIsolated": true,
"updatedTime": 1558941374745
}
],
"total": 1
}
"""
return self._request_margin_api(
"get", "margin/forceLiquidationRec", signed=True, data=params
)
```
Query margin accounts order
Either orderId or origClientOrderId must be sent.
For some historical orders cummulativeQuoteQty will be \< 0, meaning the data is not available at this time.
[https://developers.binance.com/docs/margin\_trading/trade/Query-Margin-Account-Order](https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Order)
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param orderId:
:type orderId: str
:param origClientOrderId:
:type origClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"clientOrderId": "ZwfQzuDIGpceVhKW5DvCmO",
"cummulativeQuoteQty": "0.00000000",
"executedQty": "0.00000000",
"icebergQty": "0.00000000",
"isWorking": true,
"orderId": 213205622,
"origQty": "0.30000000",
"price": "0.00493630",
"side": "SELL",
"status": "NEW",
"stopPrice": "0.00000000",
"symbol": "BNBBTC",
"time": 1562133008725,
"timeInForce": "GTC",
"type": "LIMIT",
"updateTime": 1562133008725
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_order(self, **params):
"""Query margin accounts order
Either orderId or origClientOrderId must be sent.
For some historical orders cummulativeQuoteQty will be < 0, meaning the data is not available at this time.
https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Order
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param orderId:
:type orderId: str
:param origClientOrderId:
:type origClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"clientOrderId": "ZwfQzuDIGpceVhKW5DvCmO",
"cummulativeQuoteQty": "0.00000000",
"executedQty": "0.00000000",
"icebergQty": "0.00000000",
"isWorking": true,
"orderId": 213205622,
"origQty": "0.30000000",
"price": "0.00493630",
"side": "SELL",
"status": "NEW",
"stopPrice": "0.00000000",
"symbol": "BNBBTC",
"time": 1562133008725,
"timeInForce": "GTC",
"type": "LIMIT",
"updateTime": 1562133008725
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "margin/order", signed=True, data=params)
```
Query margin accounts open orders
If the symbol is not sent, orders for all symbols will be returned in an array (cross-margin only).
If querying isolated margin orders, both the isIsolated='TRUE' and symbol=symbol\_name must be set.
When all symbols are returned, the number of requests counted against the rate limiter is equal to the number
of symbols currently trading on the exchange.
[https://developers.binance.com/docs/margin\_trading/trade/Query-Margin-Account-Open-Orders](https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Open-Orders)
:param symbol: optional
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\[
\{
"clientOrderId": "qhcZw71gAkCCTv0t0k8LUK",
"cummulativeQuoteQty": "0.00000000",
"executedQty": "0.00000000",
"icebergQty": "0.00000000",
"isWorking": true,
"orderId": 211842552,
"origQty": "0.30000000",
"price": "0.00475010",
"side": "SELL",
"status": "NEW",
"stopPrice": "0.00000000",
"symbol": "BNBBTC",
"time": 1562040170089,
"timeInForce": "GTC",
"type": "LIMIT",
"updateTime": 1562040170089
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_open_margin_orders(self, **params):
"""Query margin accounts open orders
If the symbol is not sent, orders for all symbols will be returned in an array (cross-margin only).
If querying isolated margin orders, both the isIsolated='TRUE' and symbol=symbol_name must be set.
When all symbols are returned, the number of requests counted against the rate limiter is equal to the number
of symbols currently trading on the exchange.
https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Open-Orders
:param symbol: optional
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
[
{
"clientOrderId": "qhcZw71gAkCCTv0t0k8LUK",
"cummulativeQuoteQty": "0.00000000",
"executedQty": "0.00000000",
"icebergQty": "0.00000000",
"isWorking": true,
"orderId": 211842552,
"origQty": "0.30000000",
"price": "0.00475010",
"side": "SELL",
"status": "NEW",
"stopPrice": "0.00000000",
"symbol": "BNBBTC",
"time": 1562040170089,
"timeInForce": "GTC",
"type": "LIMIT",
"updateTime": 1562040170089
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "margin/openOrders", signed=True, data=params
)
```
Query all margin accounts orders
If orderId is set, it will get orders >= that orderId. Otherwise most recent orders are returned.
For some historical orders cummulativeQuoteQty will be \< 0, meaning the data is not available at this time.
[https://developers.binance.com/docs/margin\_trading/trade/Query-Margin-Account-All-Orders](https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-All-Orders)
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param orderId: optional
:type orderId: str
:param startTime: optional
:type startTime: str
:param endTime: optional
:type endTime: str
:param limit: Default 500; max 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\[
\{
"id": 43123876,
"price": "0.00395740",
"qty": "4.06000000",
"quoteQty": "0.01606704",
"symbol": "BNBBTC",
"time": 1556089977693
},
\{
"id": 43123877,
"price": "0.00395740",
"qty": "0.77000000",
"quoteQty": "0.00304719",
"symbol": "BNBBTC",
"time": 1556089977693
},
\{
"id": 43253549,
"price": "0.00428930",
"qty": "23.30000000",
"quoteQty": "0.09994069",
"symbol": "BNBBTC",
"time": 1556163963504
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_all_margin_orders(self, **params):
"""Query all margin accounts orders
If orderId is set, it will get orders >= that orderId. Otherwise most recent orders are returned.
For some historical orders cummulativeQuoteQty will be < 0, meaning the data is not available at this time.
https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-All-Orders
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param orderId: optional
:type orderId: str
:param startTime: optional
:type startTime: str
:param endTime: optional
:type endTime: str
:param limit: Default 500; max 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
[
{
"id": 43123876,
"price": "0.00395740",
"qty": "4.06000000",
"quoteQty": "0.01606704",
"symbol": "BNBBTC",
"time": 1556089977693
},
{
"id": 43123877,
"price": "0.00395740",
"qty": "0.77000000",
"quoteQty": "0.00304719",
"symbol": "BNBBTC",
"time": 1556089977693
},
{
"id": 43253549,
"price": "0.00428930",
"qty": "23.30000000",
"quoteQty": "0.09994069",
"symbol": "BNBBTC",
"time": 1556163963504
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "margin/allOrders", signed=True, data=params
)
```
Query margin accounts trades
If fromId is set, it will get orders >= that fromId. Otherwise most recent orders are returned.
[https://developers.binance.com/docs/margin\_trading/trade/Query-Margin-Account-Trade-List](https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Trade-List)
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param fromId: optional
:type fromId: str
:param startTime: optional
:type startTime: str
:param endTime: optional
:type endTime: str
:param limit: Default 500; max 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\[
\{
"commission": "0.00006000",
"commissionAsset": "BTC",
"id": 34,
"isBestMatch": true,
"isBuyer": false,
"isMaker": false,
"orderId": 39324,
"price": "0.02000000",
"qty": "3.00000000",
"symbol": "BNBBTC",
"time": 1561973357171
}, \{
"commission": "0.00002950",
"commissionAsset": "BTC",
"id": 32,
"isBestMatch": true,
"isBuyer": false,
"isMaker": true,
"orderId": 39319,
"price": "0.00590000",
"qty": "5.00000000",
"symbol": "BNBBTC",
"time": 1561964645345
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_margin_trades(self, **params):
"""Query margin accounts trades
If fromId is set, it will get orders >= that fromId. Otherwise most recent orders are returned.
https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Trade-List
:param symbol: required
:type symbol: str
:param isIsolated: set to 'TRUE' for isolated margin (default 'FALSE')
:type isIsolated: str
:param fromId: optional
:type fromId: str
:param startTime: optional
:type startTime: str
:param endTime: optional
:type endTime: str
:param limit: Default 500; max 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
[
{
"commission": "0.00006000",
"commissionAsset": "BTC",
"id": 34,
"isBestMatch": true,
"isBuyer": false,
"isMaker": false,
"orderId": 39324,
"price": "0.02000000",
"qty": "3.00000000",
"symbol": "BNBBTC",
"time": 1561973357171
}, {
"commission": "0.00002950",
"commissionAsset": "BTC",
"id": 32,
"isBestMatch": true,
"isBuyer": false,
"isMaker": true,
"orderId": 39319,
"price": "0.00590000",
"qty": "5.00000000",
"symbol": "BNBBTC",
"time": 1561964645345
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "margin/myTrades", signed=True, data=params
)
```
Query max borrow amount for an asset
[https://binance-docs.github.io/apidocs/spot/en/#query-max-borrow-user\_data](https://binance-docs.github.io/apidocs/spot/en/#query-max-borrow-user_data)
:param asset: required
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"amount": "1.69248805"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_max_margin_loan(self, **params):
"""Query max borrow amount for an asset
https://binance-docs.github.io/apidocs/spot/en/#query-max-borrow-user_data
:param asset: required
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"amount": "1.69248805"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "margin/maxBorrowable", signed=True, data=params
)
```
Query max transfer-out amount
[https://developers.binance.com/docs/margin\_trading/transfer/Query-Max-Transfer-Out-Amount](https://developers.binance.com/docs/margin_trading/transfer/Query-Max-Transfer-Out-Amount)
:param asset: required
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"amount": "3.59498107"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_max_margin_transfer(self, **params):
"""Query max transfer-out amount
https://developers.binance.com/docs/margin_trading/transfer/Query-Max-Transfer-Out-Amount
:param asset: required
:type asset: str
:param isolatedSymbol: isolated symbol (if querying isolated margin)
:type isolatedSymbol: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"amount": "3.59498107"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "margin/maxTransferable", signed=True, data=params
)
```
Get tokens or symbols delist schedule for cross margin and isolated margin
[https://developers.binance.com/docs/margin\_trading/market-data/Get-Delist-Schedule](https://developers.binance.com/docs/margin_trading/market-data/Get-Delist-Schedule)
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"delistTime": 1686161202000,
"crossMarginAssets": \[
"BTC",
"USDT"
],
"isolatedMarginSymbols": \[
"ADAUSDT",
"BNBUSDT"
]
},
\{
"delistTime": 1686222232000,
"crossMarginAssets": \[
"ADA"
],
"isolatedMarginSymbols": \[]
}
]
```python
def get_margin_delist_schedule(self, **params):
"""Get tokens or symbols delist schedule for cross margin and isolated margin
https://developers.binance.com/docs/margin_trading/market-data/Get-Delist-Schedule
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"delistTime": 1686161202000,
"crossMarginAssets": [
"BTC",
"USDT"
],
"isolatedMarginSymbols": [
"ADAUSDT",
"BNBUSDT"
]
},
{
"delistTime": 1686222232000,
"crossMarginAssets": [
"ADA"
],
"isolatedMarginSymbols": []
}
]
"""
return self._request_margin_api(
"get", "/margin/delist-schedule", signed=True, data=params
)
```
Post a new OCO trade for margin account.
[https://developers.binance.com/docs/margin\_trading/trade/Margin-Account-New-OCO](https://developers.binance.com/docs/margin_trading/trade/Margin-Account-New-OCO)
:param symbol: required
:type symbol: str
:param isIsolated: for isolated margin or not, "TRUE", "FALSE",default "FALSE"
:type symbol: str
:param listClientOrderId: A unique id for the list order. Automatically generated if not sent.
:type listClientOrderId: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param limitClientOrderId: A unique id for the limit order. Automatically generated if not sent.
:type limitClientOrderId: str
:param price: required
:type price: str
:param limitIcebergQty: Used to make the LIMIT\_MAKER leg an iceberg order.
:type limitIcebergQty: decimal
:param stopClientOrderId: A unique Id for the stop loss/stop loss limit leg. Automatically generated if not sent.
:type stopClientOrderId: str
:param stopPrice: required
:type stopPrice: str
:param stopLimitPrice: If provided, stopLimitTimeInForce is required.
:type stopLimitPrice: str
:param stopIcebergQty: Used with STOP\_LOSS\_LIMIT leg to make an iceberg order.
:type stopIcebergQty: decimal
:param stopLimitTimeInForce: Valid values are GTC/FOK/IOC.
:type stopLimitTimeInForce: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param sideEffectType: NO\_SIDE\_EFFECT, MARGIN\_BUY, AUTO\_REPAY; default NO\_SIDE\_EFFECT.
:type sideEffectType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"orderListId": 0,
"contingencyType": "OCO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "JYVpp3F0f5CAG15DhtrqLp",
"transactionTime": 1563417480525,
"symbol": "LTCBTC",
"marginBuyBorrowAmount": "5", // will not return if no margin trade happens
"marginBuyBorrowAsset": "BTC", // will not return if no margin trade happens
"isIsolated": false, // if isolated margin
"orders": \[
\{
"symbol": "LTCBTC",
"orderId": 2,
"clientOrderId": "Kk7sqHb9J6mJWTMDVW7Vos"
},
\{
"symbol": "LTCBTC",
"orderId": 3,
"clientOrderId": "xTXKaGYd4bluPVp78IVRvl"
}
],
"orderReports": \[
\{
"symbol": "LTCBTC",
"orderId": 2,
"orderListId": 0,
"clientOrderId": "Kk7sqHb9J6mJWTMDVW7Vos",
"transactTime": 1563417480525,
"price": "0.000000",
"origQty": "0.624363",
"executedQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "STOP\_LOSS",
"side": "BUY",
"stopPrice": "0.960664"
},
\{
"symbol": "LTCBTC",
"orderId": 3,
"orderListId": 0,
"clientOrderId": "xTXKaGYd4bluPVp78IVRvl",
"transactTime": 1563417480525,
"price": "0.036435",
"origQty": "0.624363",
"executedQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT\_MAKER",
"side": "BUY"
}
]
}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException,
BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException,
BinanceOrderInactiveSymbolException
```python
def create_margin_oco_order(self, **params):
"""Post a new OCO trade for margin account.
https://developers.binance.com/docs/margin_trading/trade/Margin-Account-New-OCO
:param symbol: required
:type symbol: str
:param isIsolated: for isolated margin or not, "TRUE", "FALSE",default "FALSE"
:type symbol: str
:param listClientOrderId: A unique id for the list order. Automatically generated if not sent.
:type listClientOrderId: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param limitClientOrderId: A unique id for the limit order. Automatically generated if not sent.
:type limitClientOrderId: str
:param price: required
:type price: str
:param limitIcebergQty: Used to make the LIMIT_MAKER leg an iceberg order.
:type limitIcebergQty: decimal
:param stopClientOrderId: A unique Id for the stop loss/stop loss limit leg. Automatically generated if not sent.
:type stopClientOrderId: str
:param stopPrice: required
:type stopPrice: str
:param stopLimitPrice: If provided, stopLimitTimeInForce is required.
:type stopLimitPrice: str
:param stopIcebergQty: Used with STOP_LOSS_LIMIT leg to make an iceberg order.
:type stopIcebergQty: decimal
:param stopLimitTimeInForce: Valid values are GTC/FOK/IOC.
:type stopLimitTimeInForce: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param sideEffectType: NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY; default NO_SIDE_EFFECT.
:type sideEffectType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"orderListId": 0,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "JYVpp3F0f5CAG15DhtrqLp",
"transactionTime": 1563417480525,
"symbol": "LTCBTC",
"marginBuyBorrowAmount": "5", // will not return if no margin trade happens
"marginBuyBorrowAsset": "BTC", // will not return if no margin trade happens
"isIsolated": false, // if isolated margin
"orders": [
{
"symbol": "LTCBTC",
"orderId": 2,
"clientOrderId": "Kk7sqHb9J6mJWTMDVW7Vos"
},
{
"symbol": "LTCBTC",
"orderId": 3,
"clientOrderId": "xTXKaGYd4bluPVp78IVRvl"
}
],
"orderReports": [
{
"symbol": "LTCBTC",
"orderId": 2,
"orderListId": 0,
"clientOrderId": "Kk7sqHb9J6mJWTMDVW7Vos",
"transactTime": 1563417480525,
"price": "0.000000",
"origQty": "0.624363",
"executedQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "STOP_LOSS",
"side": "BUY",
"stopPrice": "0.960664"
},
{
"symbol": "LTCBTC",
"orderId": 3,
"orderListId": 0,
"clientOrderId": "xTXKaGYd4bluPVp78IVRvl",
"transactTime": 1563417480525,
"price": "0.036435",
"origQty": "0.624363",
"executedQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT_MAKER",
"side": "BUY"
}
]
}
:raises: BinanceRequestException, BinanceAPIException, BinanceOrderException, BinanceOrderMinAmountException,
BinanceOrderMinPriceException, BinanceOrderMinTotalException, BinanceOrderUnknownSymbolException,
BinanceOrderInactiveSymbolException
"""
return self._request_margin_api(
"post", "margin/order/oco", signed=True, data=params
)
```
Cancel an entire Order List for a margin account.
[https://developers.binance.com/docs/margin\_trading/trade/Margin-Account-Cancel-OCO](https://developers.binance.com/docs/margin_trading/trade/Margin-Account-Cancel-OCO)
:param symbol: required
:type symbol: str
:param isIsolated: for isolated margin or not, "TRUE", "FALSE",default "FALSE"
:type symbol: str
:param orderListId: Either orderListId or listClientOrderId must be provided
:type orderListId: int
:param listClientOrderId: Either orderListId or listClientOrderId must be provided
:type listClientOrderId: str
:param newClientOrderId: Used to uniquely identify this cancel. Automatically generated by default.
:type newClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"orderListId": 0,
"contingencyType": "OCO",
"listStatusType": "ALL\_DONE",
"listOrderStatus": "ALL\_DONE",
"listClientOrderId": "C3wyj4WVEktd7u9aVBRXcN",
"transactionTime": 1574040868128,
"symbol": "LTCBTC",
"isIsolated": false, // if isolated margin
"orders": \[
\{
"symbol": "LTCBTC",
"orderId": 2,
"clientOrderId": "pO9ufTiFGg3nw2fOdgeOXa"
},
\{
"symbol": "LTCBTC",
"orderId": 3,
"clientOrderId": "TXOvglzXuaubXAaENpaRCB"
}
],
"orderReports": \[
\{
"symbol": "LTCBTC",
"origClientOrderId": "pO9ufTiFGg3nw2fOdgeOXa",
"orderId": 2,
"orderListId": 0,
"clientOrderId": "unfWT8ig8i0uj6lPuYLez6",
"price": "1.00000000",
"origQty": "10.00000000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "STOP\_LOSS\_LIMIT",
"side": "SELL",
"stopPrice": "1.00000000"
},
\{
"symbol": "LTCBTC",
"origClientOrderId": "TXOvglzXuaubXAaENpaRCB",
"orderId": 3,
"orderListId": 0,
"clientOrderId": "unfWT8ig8i0uj6lPuYLez6",
"price": "3.00000000",
"origQty": "10.00000000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT\_MAKER",
"side": "SELL"
}
]
}
```python
def cancel_margin_oco_order(self, **params):
"""Cancel an entire Order List for a margin account.
https://developers.binance.com/docs/margin_trading/trade/Margin-Account-Cancel-OCO
:param symbol: required
:type symbol: str
:param isIsolated: for isolated margin or not, "TRUE", "FALSE",default "FALSE"
:type symbol: str
:param orderListId: Either orderListId or listClientOrderId must be provided
:type orderListId: int
:param listClientOrderId: Either orderListId or listClientOrderId must be provided
:type listClientOrderId: str
:param newClientOrderId: Used to uniquely identify this cancel. Automatically generated by default.
:type newClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"orderListId": 0,
"contingencyType": "OCO",
"listStatusType": "ALL_DONE",
"listOrderStatus": "ALL_DONE",
"listClientOrderId": "C3wyj4WVEktd7u9aVBRXcN",
"transactionTime": 1574040868128,
"symbol": "LTCBTC",
"isIsolated": false, // if isolated margin
"orders": [
{
"symbol": "LTCBTC",
"orderId": 2,
"clientOrderId": "pO9ufTiFGg3nw2fOdgeOXa"
},
{
"symbol": "LTCBTC",
"orderId": 3,
"clientOrderId": "TXOvglzXuaubXAaENpaRCB"
}
],
"orderReports": [
{
"symbol": "LTCBTC",
"origClientOrderId": "pO9ufTiFGg3nw2fOdgeOXa",
"orderId": 2,
"orderListId": 0,
"clientOrderId": "unfWT8ig8i0uj6lPuYLez6",
"price": "1.00000000",
"origQty": "10.00000000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "STOP_LOSS_LIMIT",
"side": "SELL",
"stopPrice": "1.00000000"
},
{
"symbol": "LTCBTC",
"origClientOrderId": "TXOvglzXuaubXAaENpaRCB",
"orderId": 3,
"orderListId": 0,
"clientOrderId": "unfWT8ig8i0uj6lPuYLez6",
"price": "3.00000000",
"origQty": "10.00000000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT_MAKER",
"side": "SELL"
}
]
}
"""
return self._request_margin_api(
"delete", "margin/orderList", signed=True, data=params
)
```
Retrieves a specific OCO based on provided optional parameters
[https://developers.binance.com/docs/margin\_trading/trade/Query-Margin-Account-OCO](https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-OCO)
:param isIsolated: for isolated margin or not, "TRUE", "FALSE",default "FALSE"
:type symbol: str
:param symbol: mandatory for isolated margin, not supported for cross margin
:type symbol: str
:param orderListId: Either orderListId or listClientOrderId must be provided
:type orderListId: int
:param listClientOrderId: Either orderListId or listClientOrderId must be provided
:type listClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\{
"orderListId": 27,
"contingencyType": "OCO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "h2USkA5YQpaXHPIrkd96xE",
"transactionTime": 1565245656253,
"symbol": "LTCBTC",
"isIsolated": false, // if isolated margin
"orders": \[
\{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "qD1gy3kc3Gx0rihm9Y3xwS"
},
\{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "ARzZ9I00CPM8i3NhmU9Ega"
}
]
}
```python
def get_margin_oco_order(self, **params):
"""Retrieves a specific OCO based on provided optional parameters
https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-OCO
:param isIsolated: for isolated margin or not, "TRUE", "FALSE",default "FALSE"
:type symbol: str
:param symbol: mandatory for isolated margin, not supported for cross margin
:type symbol: str
:param orderListId: Either orderListId or listClientOrderId must be provided
:type orderListId: int
:param listClientOrderId: Either orderListId or listClientOrderId must be provided
:type listClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
{
"orderListId": 27,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "h2USkA5YQpaXHPIrkd96xE",
"transactionTime": 1565245656253,
"symbol": "LTCBTC",
"isIsolated": false, // if isolated margin
"orders": [
{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "qD1gy3kc3Gx0rihm9Y3xwS"
},
{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "ARzZ9I00CPM8i3NhmU9Ega"
}
]
}
"""
return self._request_margin_api(
"get", "margin/orderList", signed=True, data=params
)
```
Retrieves open OCO trades
[https://developers.binance.com/docs/margin\_trading/trade/Query-Margin-Account-Open-OCO](https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Open-OCO)
:param isIsolated: for isolated margin or not, "TRUE", "FALSE",default "FALSE"
:type symbol: str
:param symbol: mandatory for isolated margin, not supported for cross margin
:type symbol: str
:param fromId: If supplied, neither startTime or endTime can be provided
:type fromId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional Default Value: 500; Max Value: 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
\[
\{
"orderListId": 29,
"contingencyType": "OCO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "amEEAXryFzFwYF1FeRpUoZ",
"transactionTime": 1565245913483,
"symbol": "LTCBTC",
"isIsolated": true, // if isolated margin
"orders": \[
\{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "oD7aesZqjEGlZrbtRpy5zB"
},
\{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "Jr1h6xirOxgeJOUuYQS7V3"
}
]
},
\{
"orderListId": 28,
"contingencyType": "OCO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "hG7hFNxJV6cZy3Ze4AUT4d",
"transactionTime": 1565245913407,
"symbol": "LTCBTC",
"orders": \[
\{
"symbol": "LTCBTC",
"orderId": 2,
"clientOrderId": "j6lFOfbmFMRjTYA7rRJ0LP"
},
\{
"symbol": "LTCBTC",
"orderId": 3,
"clientOrderId": "z0KCjOdditiLS5ekAFtK81"
}
]
}
]
```python
def get_open_margin_oco_orders(self, **params):
"""Retrieves open OCO trades
https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-Open-OCO
:param isIsolated: for isolated margin or not, "TRUE", "FALSE",default "FALSE"
:type symbol: str
:param symbol: mandatory for isolated margin, not supported for cross margin
:type symbol: str
:param fromId: If supplied, neither startTime or endTime can be provided
:type fromId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional Default Value: 500; Max Value: 1000
:type limit: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
[
{
"orderListId": 29,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "amEEAXryFzFwYF1FeRpUoZ",
"transactionTime": 1565245913483,
"symbol": "LTCBTC",
"isIsolated": true, // if isolated margin
"orders": [
{
"symbol": "LTCBTC",
"orderId": 4,
"clientOrderId": "oD7aesZqjEGlZrbtRpy5zB"
},
{
"symbol": "LTCBTC",
"orderId": 5,
"clientOrderId": "Jr1h6xirOxgeJOUuYQS7V3"
}
]
},
{
"orderListId": 28,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "hG7hFNxJV6cZy3Ze4AUT4d",
"transactionTime": 1565245913407,
"symbol": "LTCBTC",
"orders": [
{
"symbol": "LTCBTC",
"orderId": 2,
"clientOrderId": "j6lFOfbmFMRjTYA7rRJ0LP"
},
{
"symbol": "LTCBTC",
"orderId": 3,
"clientOrderId": "z0KCjOdditiLS5ekAFtK81"
}
]
}
]
"""
return self._request_margin_api(
"get", "margin/openOrderList", signed=True, data=params
)
```
Start a new cross-margin data stream and return the listen key
If a stream already exists it should return the same key.
If the stream becomes invalid a new key is returned.
Can be used to keep the stream alive.
[https://developers.binance.com/docs/margin\_trading/trade-data-stream/Start-Margin-User-Data-Stream](https://developers.binance.com/docs/margin_trading/trade-data-stream/Start-Margin-User-Data-Stream)
:returns: API response
.. code-block:: python
\{
"listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def margin_stream_get_listen_key(self):
"""Start a new cross-margin data stream and return the listen key
If a stream already exists it should return the same key.
If the stream becomes invalid a new key is returned.
Can be used to keep the stream alive.
https://developers.binance.com/docs/margin_trading/trade-data-stream/Start-Margin-User-Data-Stream
:returns: API response
.. code-block:: python
{
"listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
}
:raises: BinanceRequestException, BinanceAPIException
"""
warnings.warn(
"POST /sapi/v1/userDataStream is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken, "
"then subscribe with userDataStream.subscribe.listenToken). "
"The margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
res = self._request_margin_api("post", "userDataStream", signed=False, data={})
return res["listenKey"]
```
PING a cross-margin data stream to prevent a time out.
[https://developers.binance.com/docs/margin\_trading/trade-data-stream/Keepalive-Margin-User-Data-Stream](https://developers.binance.com/docs/margin_trading/trade-data-stream/Keepalive-Margin-User-Data-Stream)
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
\{}
:raises: BinanceRequestException, BinanceAPIException
```python
def margin_stream_keepalive(self, listenKey):
"""PING a cross-margin data stream to prevent a time out.
https://developers.binance.com/docs/margin_trading/trade-data-stream/Keepalive-Margin-User-Data-Stream
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
{}
:raises: BinanceRequestException, BinanceAPIException
"""
warnings.warn(
"PUT /sapi/v1/userDataStream is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken, "
"then subscribe with userDataStream.subscribe.listenToken). "
"The margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"listenKey": listenKey}
return self._request_margin_api(
"put", "userDataStream", signed=False, data=params
)
```
Close out a cross-margin data stream.
[https://developers.binance.com/docs/margin\_trading/trade-data-stream/Close-Margin-User-Data-Stream](https://developers.binance.com/docs/margin_trading/trade-data-stream/Close-Margin-User-Data-Stream)
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
\{}
:raises: BinanceRequestException, BinanceAPIException
```python
def margin_stream_close(self, listenKey):
"""Close out a cross-margin data stream.
https://developers.binance.com/docs/margin_trading/trade-data-stream/Close-Margin-User-Data-Stream
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
{}
:raises: BinanceRequestException, BinanceAPIException
"""
warnings.warn(
"DELETE /sapi/v1/userDataStream is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken, "
"then subscribe with userDataStream.subscribe.listenToken). "
"The margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"listenKey": listenKey}
return self._request_margin_api(
"delete", "userDataStream", signed=False, data=params
)
```
Create a listenToken for margin account user data stream
[https://developers.binance.com/docs/margin\_trading/trade-data-stream/Create-Margin-Account-listenToken](https://developers.binance.com/docs/margin_trading/trade-data-stream/Create-Margin-Account-listenToken)
:param symbol: Trading pair symbol (required when is\_isolated=True)
:type symbol: str
:param is\_isolated: Whether it is isolated margin (default: False for cross-margin)
:type is\_isolated: bool
:param validity: Validity in milliseconds (default: 24 hours, max: 24 hours)
:type validity: int
:returns: API response with token and expirationTime
.. code-block:: python
\{
"token": "6xXxePXwZRjVSHKhzUCCGnmN3fkvMTXru+pYJS8RwijXk9Vcyr3rkwfVOTcP2OkONqciYA",
"expirationTime": 1758792204196
}
:raises: BinanceRequestException, BinanceAPIException
```python
def margin_create_listen_token(self, symbol: Optional[str] = None, is_isolated: bool = False, validity: Optional[int] = None):
"""Create a listenToken for margin account user data stream
https://developers.binance.com/docs/margin_trading/trade-data-stream/Create-Margin-Account-listenToken
:param symbol: Trading pair symbol (required when is_isolated=True)
:type symbol: str
:param is_isolated: Whether it is isolated margin (default: False for cross-margin)
:type is_isolated: bool
:param validity: Validity in milliseconds (default: 24 hours, max: 24 hours)
:type validity: int
:returns: API response with token and expirationTime
.. code-block:: python
{
"token": "6xXxePXwZRjVSHKhzUCCGnmN3fkvMTXru+pYJS8RwijXk9Vcyr3rkwfVOTcP2OkONqciYA",
"expirationTime": 1758792204196
}
:raises: BinanceRequestException, BinanceAPIException
"""
params = {}
if is_isolated:
if not symbol:
raise ValueError("symbol is required when is_isolated=True")
params["symbol"] = symbol
params["isIsolated"] = "true"
if validity is not None:
params["validity"] = validity
return self._request_margin_api(
"post", "userListenToken", signed=True, data=params
)
```
Start a new isolated margin data stream and return the listen key
If a stream already exists it should return the same key.
If the stream becomes invalid a new key is returned.
Can be used to keep the stream alive.
[https://developers.binance.com/docs/margin\_trading/trade-data-stream/Start-Isolated-Margin-User-Data-Stream](https://developers.binance.com/docs/margin_trading/trade-data-stream/Start-Isolated-Margin-User-Data-Stream)
:param symbol: required - symbol for the isolated margin account
:type symbol: str
:returns: API response
.. code-block:: python
\{
"listenKey": "T3ee22BIYuWqmvne0HNq2A2WsFlEtLhvWCtItw6ffhhdmjifQ2tRbuKkTHhr"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def isolated_margin_stream_get_listen_key(self, symbol):
"""Start a new isolated margin data stream and return the listen key
If a stream already exists it should return the same key.
If the stream becomes invalid a new key is returned.
Can be used to keep the stream alive.
https://developers.binance.com/docs/margin_trading/trade-data-stream/Start-Isolated-Margin-User-Data-Stream
:param symbol: required - symbol for the isolated margin account
:type symbol: str
:returns: API response
.. code-block:: python
{
"listenKey": "T3ee22BIYuWqmvne0HNq2A2WsFlEtLhvWCtItw6ffhhdmjifQ2tRbuKkTHhr"
}
:raises: BinanceRequestException, BinanceAPIException
"""
warnings.warn(
"POST /sapi/v1/userDataStream/isolated is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken "
"with isIsolated=true, then subscribe with userDataStream.subscribe.listenToken). "
"The isolated_margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"symbol": symbol}
res = self._request_margin_api(
"post", "userDataStream/isolated", signed=False, data=params
)
return res["listenKey"]
```
PING an isolated margin data stream to prevent a time out.
[https://developers.binance.com/docs/margin\_trading/trade-data-stream/Keepalive-Isolated-Margin-User-Data-Stream](https://developers.binance.com/docs/margin_trading/trade-data-stream/Keepalive-Isolated-Margin-User-Data-Stream)
:param symbol: required - symbol for the isolated margin account
:type symbol: str
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
\{}
:raises: BinanceRequestException, BinanceAPIException
```python
def isolated_margin_stream_keepalive(self, symbol, listenKey):
"""PING an isolated margin data stream to prevent a time out.
https://developers.binance.com/docs/margin_trading/trade-data-stream/Keepalive-Isolated-Margin-User-Data-Stream
:param symbol: required - symbol for the isolated margin account
:type symbol: str
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
{}
:raises: BinanceRequestException, BinanceAPIException
"""
warnings.warn(
"PUT /sapi/v1/userDataStream/isolated is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken "
"with isIsolated=true, then subscribe with userDataStream.subscribe.listenToken). "
"The isolated_margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"symbol": symbol, "listenKey": listenKey}
return self._request_margin_api(
"put", "userDataStream/isolated", signed=False, data=params
)
```
Close out an isolated margin data stream.
[https://developers.binance.com/docs/margin\_trading/trade-data-stream/Close-Isolated-Margin-User-Data-Stream](https://developers.binance.com/docs/margin_trading/trade-data-stream/Close-Isolated-Margin-User-Data-Stream)
:param symbol: required - symbol for the isolated margin account
:type symbol: str
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
\{}
:raises: BinanceRequestException, BinanceAPIException
```python
def isolated_margin_stream_close(self, symbol, listenKey):
"""Close out an isolated margin data stream.
https://developers.binance.com/docs/margin_trading/trade-data-stream/Close-Isolated-Margin-User-Data-Stream
:param symbol: required - symbol for the isolated margin account
:type symbol: str
:param listenKey: required
:type listenKey: str
:returns: API response
.. code-block:: python
{}
:raises: BinanceRequestException, BinanceAPIException
"""
warnings.warn(
"DELETE /sapi/v1/userDataStream/isolated is deprecated and will be removed on 2026-02-20. "
"Use the WebSocket API subscription method instead (create listenToken via POST /sapi/v1/userListenToken "
"with isIsolated=true, then subscribe with userDataStream.subscribe.listenToken). "
"The isolated_margin_socket() method now uses WebSocket API by default.",
DeprecationWarning,
stacklevel=2
)
params = {"symbol": symbol, "listenKey": listenKey}
return self._request_margin_api(
"delete", "userDataStream/isolated", signed=False, data=params
)
```
Get available Simple Earn flexible product list
[https://binance-docs.github.io/apidocs/spot/en/#get-simple-earn-flexible-product-list-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-simple-earn-flexible-product-list-user_data)
:param asset: optional
:type asset: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"rows":\[
\{
"asset": "BTC",
"latestAnnualPercentageRate": "0.05000000",
"tierAnnualPercentageRate": \{
"0-5BTC": 0.05,
"5-10BTC": 0.03
},
"airDropPercentageRate": "0.05000000",
"canPurchase": true,
"canRedeem": true,
"isSoldOut": true,
"hot": true,
"minPurchaseAmount": "0.01000000",
"productId": "BTC001",
"subscriptionStartTime": "1646182276000",
"status": "PURCHASING"
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_simple_earn_flexible_product_list(self, **params):
"""Get available Simple Earn flexible product list
https://binance-docs.github.io/apidocs/spot/en/#get-simple-earn-flexible-product-list-user_data
:param asset: optional
:type asset: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"rows":[
{
"asset": "BTC",
"latestAnnualPercentageRate": "0.05000000",
"tierAnnualPercentageRate": {
"0-5BTC": 0.05,
"5-10BTC": 0.03
},
"airDropPercentageRate": "0.05000000",
"canPurchase": true,
"canRedeem": true,
"isSoldOut": true,
"hot": true,
"minPurchaseAmount": "0.01000000",
"productId": "BTC001",
"subscriptionStartTime": "1646182276000",
"status": "PURCHASING"
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "simple-earn/flexible/list", signed=True, data=params
)
```
Get available Simple Earn flexible product list
[https://binance-docs.github.io/apidocs/spot/en/#get-simple-earn-locked-product-list-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-simple-earn-locked-product-list-user_data)
:param asset: optional
:type asset: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"rows": \[
\{
"projectId": "Axs\*90",
"detail": \{
"asset": "AXS",
"rewardAsset": "AXS",
"duration": 90,
"renewable": true,
"isSoldOut": true,
"apr": "1.2069",
"status": "CREATED",
"subscriptionStartTime": "1646182276000",
"extraRewardAsset": "BNB",
"extraRewardAPR": "0.23"
},
"quota": \{
"totalPersonalQuota": "2",
"minimum": "0.001"
}
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_simple_earn_locked_product_list(self, **params):
"""Get available Simple Earn flexible product list
https://binance-docs.github.io/apidocs/spot/en/#get-simple-earn-locked-product-list-user_data
:param asset: optional
:type asset: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"rows": [
{
"projectId": "Axs*90",
"detail": {
"asset": "AXS",
"rewardAsset": "AXS",
"duration": 90,
"renewable": true,
"isSoldOut": true,
"apr": "1.2069",
"status": "CREATED",
"subscriptionStartTime": "1646182276000",
"extraRewardAsset": "BNB",
"extraRewardAPR": "0.23"
},
"quota": {
"totalPersonalQuota": "2",
"minimum": "0.001"
}
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "simple-earn/locked/list", signed=True, data=params
)
```
Subscribe to a simple earn flexible product
[https://binance-docs.github.io/apidocs/spot/en/#subscribe-locked-product-trade](https://binance-docs.github.io/apidocs/spot/en/#subscribe-locked-product-trade)
:param productId: required
:type productId: str
:param amount: required
:type amount: str
:param autoSubscribe: optional - Default True
:type autoSubscribe: bool
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"purchaseId": 40607,
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
```python
def subscribe_simple_earn_flexible_product(self, **params):
"""Subscribe to a simple earn flexible product
https://binance-docs.github.io/apidocs/spot/en/#subscribe-locked-product-trade
:param productId: required
:type productId: str
:param amount: required
:type amount: str
:param autoSubscribe: optional - Default True
:type autoSubscribe: bool
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"purchaseId": 40607,
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "simple-earn/flexible/subscribe", signed=True, data=params
)
```
Subscribe to a simple earn locked product
[https://binance-docs.github.io/apidocs/spot/en/#subscribe-locked-product-trade](https://binance-docs.github.io/apidocs/spot/en/#subscribe-locked-product-trade)
:param productId: required
:type productId: str
:param amount: required
:type amount: str
:param autoSubscribe: optional - Default True
:type autoSubscribe: bool
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"purchaseId": 40607,
"positionId": "12345",
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
```python
def subscribe_simple_earn_locked_product(self, **params):
"""Subscribe to a simple earn locked product
https://binance-docs.github.io/apidocs/spot/en/#subscribe-locked-product-trade
:param productId: required
:type productId: str
:param amount: required
:type amount: str
:param autoSubscribe: optional - Default True
:type autoSubscribe: bool
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"purchaseId": 40607,
"positionId": "12345",
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "simple-earn/locked/subscribe", signed=True, data=params
)
```
Redeem a simple earn flexible product
[https://binance-docs.github.io/apidocs/spot/en/#redeem-flexible-product-trade](https://binance-docs.github.io/apidocs/spot/en/#redeem-flexible-product-trade)
:param productId: required
:type productId: str
:param amount: optional
:type amount: str
:param redeemAll: optional - Default False
:type redeemAll: bool
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"redeemId": 40607,
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
```python
def redeem_simple_earn_flexible_product(self, **params):
"""Redeem a simple earn flexible product
https://binance-docs.github.io/apidocs/spot/en/#redeem-flexible-product-trade
:param productId: required
:type productId: str
:param amount: optional
:type amount: str
:param redeemAll: optional - Default False
:type redeemAll: bool
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"redeemId": 40607,
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "simple-earn/flexible/redeem", signed=True, data=params
)
```
Redeem a simple earn locked product
[https://binance-docs.github.io/apidocs/spot/en/#redeem-locked-product-trade](https://binance-docs.github.io/apidocs/spot/en/#redeem-locked-product-trade)
:param productId: required
:type productId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"redeemId": 40607,
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
```python
def redeem_simple_earn_locked_product(self, **params):
"""Redeem a simple earn locked product
https://binance-docs.github.io/apidocs/spot/en/#redeem-locked-product-trade
:param productId: required
:type productId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"redeemId": 40607,
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "simple-earn/locked/redeem", signed=True, data=params
)
```
[https://binance-docs.github.io/apidocs/spot/en/#get-flexible-product-position-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-flexible-product-position-user_data)
:param asset: optional
:type asset: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"rows":\[
\{
"totalAmount": "75.46000000",
"tierAnnualPercentageRate": \{
"0-5BTC": 0.05,
"5-10BTC": 0.03
},
"latestAnnualPercentageRate": "0.02599895",
"yesterdayAirdropPercentageRate": "0.02599895",
"asset": "USDT",
"airDropAsset": "BETH",
"canRedeem": true,
"collateralAmount": "232.23123213",
"productId": "USDT001",
"yesterdayRealTimeRewards": "0.10293829",
"cumulativeBonusRewards": "0.22759183",
"cumulativeRealTimeRewards": "0.22759183",
"cumulativeTotalRewards": "0.45459183",
"autoSubscribe": true
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_simple_earn_flexible_product_position(self, **params):
"""
https://binance-docs.github.io/apidocs/spot/en/#get-flexible-product-position-user_data
:param asset: optional
:type asset: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"rows":[
{
"totalAmount": "75.46000000",
"tierAnnualPercentageRate": {
"0-5BTC": 0.05,
"5-10BTC": 0.03
},
"latestAnnualPercentageRate": "0.02599895",
"yesterdayAirdropPercentageRate": "0.02599895",
"asset": "USDT",
"airDropAsset": "BETH",
"canRedeem": true,
"collateralAmount": "232.23123213",
"productId": "USDT001",
"yesterdayRealTimeRewards": "0.10293829",
"cumulativeBonusRewards": "0.22759183",
"cumulativeRealTimeRewards": "0.22759183",
"cumulativeTotalRewards": "0.45459183",
"autoSubscribe": true
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "simple-earn/flexible/position", signed=True, data=params
)
```
[https://binance-docs.github.io/apidocs/spot/en/#get-locked-product-position-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-locked-product-position-user_data)
:param asset: optional
:type asset: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"rows":\[
\{
"positionId": "123123",
"projectId": "Axs\*90",
"asset": "AXS",
"amount": "122.09202928",
"purchaseTime": "1646182276000",
"duration": "60",
"accrualDays": "4",
"rewardAsset": "AXS",
"APY": "0.23",
"isRenewable": true,
"isAutoRenew": true,
"redeemDate": "1732182276000"
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_simple_earn_locked_product_position(self, **params):
"""
https://binance-docs.github.io/apidocs/spot/en/#get-locked-product-position-user_data
:param asset: optional
:type asset: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"rows":[
{
"positionId": "123123",
"projectId": "Axs*90",
"asset": "AXS",
"amount": "122.09202928",
"purchaseTime": "1646182276000",
"duration": "60",
"accrualDays": "4",
"rewardAsset": "AXS",
"APY": "0.23",
"isRenewable": true,
"isAutoRenew": true,
"redeemDate": "1732182276000"
}
],
"total": 1
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "simple-earn/locked/position", signed=True, data=params
)
```
[https://binance-docs.github.io/apidocs/spot/en/#simple-account-user\_data](https://binance-docs.github.io/apidocs/spot/en/#simple-account-user_data)
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"totalAmountInBTC": "0.01067982",
"totalAmountInUSDT": "77.13289230",
"totalFlexibleAmountInBTC": "0.00000000",
"totalFlexibleAmountInUSDT": "0.00000000",
"totalLockedInBTC": "0.01067982",
"totalLockedInUSDT": "77.13289230"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_simple_earn_account(self, **params):
"""
https://binance-docs.github.io/apidocs/spot/en/#simple-account-user_data
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"totalAmountInBTC": "0.01067982",
"totalAmountInUSDT": "77.13289230",
"totalFlexibleAmountInBTC": "0.00000000",
"totalFlexibleAmountInUSDT": "0.00000000",
"totalLockedInBTC": "0.01067982",
"totalLockedInUSDT": "77.13289230"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "simple-earn/account", signed=True, data=params
)
```
Get Fixed and Activity Project List
[https://binance-docs.github.io/apidocs/spot/en/#get-fixed-and-activity-project-list-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-fixed-and-activity-project-list-user_data)
:param asset: optional
:type asset: str
:param type: required - "ACTIVITY", "CUSTOMIZED\_FIXED"
:type type: str
:param status: optional - "ALL", "SUBSCRIBABLE", "UNSUBSCRIBABLE"; default "ALL"
:type status: str
:param sortBy: optional - "START\_TIME", "LOT\_SIZE", "INTEREST\_RATE", "DURATION"; default "START\_TIME"
:type sortBy: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"asset": "USDT",
"displayPriority": 1,
"duration": 90,
"interestPerLot": "1.35810000",
"interestRate": "0.05510000",
"lotSize": "100.00000000",
"lotsLowLimit": 1,
"lotsPurchased": 74155,
"lotsUpLimit": 80000,
"maxLotsPerUser": 2000,
"needKyc": False,
"projectId": "CUSDT90DAYSS001",
"projectName": "USDT",
"status": "PURCHASING",
"type": "CUSTOMIZED\_FIXED",
"withAreaLimitation": False
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_fixed_activity_project_list(self, **params):
"""Get Fixed and Activity Project List
https://binance-docs.github.io/apidocs/spot/en/#get-fixed-and-activity-project-list-user_data
:param asset: optional
:type asset: str
:param type: required - "ACTIVITY", "CUSTOMIZED_FIXED"
:type type: str
:param status: optional - "ALL", "SUBSCRIBABLE", "UNSUBSCRIBABLE"; default "ALL"
:type status: str
:param sortBy: optional - "START_TIME", "LOT_SIZE", "INTEREST_RATE", "DURATION"; default "START_TIME"
:type sortBy: str
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10, Max:100
:type size: int
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"asset": "USDT",
"displayPriority": 1,
"duration": 90,
"interestPerLot": "1.35810000",
"interestRate": "0.05510000",
"lotSize": "100.00000000",
"lotsLowLimit": 1,
"lotsPurchased": 74155,
"lotsUpLimit": 80000,
"maxLotsPerUser": 2000,
"needKyc": False,
"projectId": "CUSDT90DAYSS001",
"projectName": "USDT",
"status": "PURCHASING",
"type": "CUSTOMIZED_FIXED",
"withAreaLimitation": False
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "lending/project/list", signed=True, data=params
)
```
Change Fixed/Activity Position to Daily Position
[https://binance-docs.github.io/apidocs/spot/en/#change-fixed-activity-position-to-daily-position-user\_data](https://binance-docs.github.io/apidocs/spot/en/#change-fixed-activity-position-to-daily-position-user_data)
```python
def change_fixed_activity_to_daily_position(self, **params):
"""Change Fixed/Activity Position to Daily Position
https://binance-docs.github.io/apidocs/spot/en/#change-fixed-activity-position-to-daily-position-user_data
"""
return self._request_margin_api(
"post", "lending/positionChanged", signed=True, data=params
)
```
Get Staking Product List
[https://binance-docs.github.io/apidocs/spot/en/#get-staking-product-list-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-staking-product-list-user_data)
```python
def get_staking_product_list(self, **params):
"""Get Staking Product List
https://binance-docs.github.io/apidocs/spot/en/#get-staking-product-list-user_data
"""
return self._request_margin_api(
"get", "staking/productList", signed=True, data=params
)
```
Purchase Staking Product
[https://binance-docs.github.io/apidocs/spot/en/#purchase-staking-product-user\_data](https://binance-docs.github.io/apidocs/spot/en/#purchase-staking-product-user_data)
```python
def purchase_staking_product(self, **params):
"""Purchase Staking Product
https://binance-docs.github.io/apidocs/spot/en/#purchase-staking-product-user_data
"""
return self._request_margin_api(
"post", "staking/purchase", signed=True, data=params
)
```
Redeem Staking Product
[https://binance-docs.github.io/apidocs/spot/en/#redeem-staking-product-user\_data](https://binance-docs.github.io/apidocs/spot/en/#redeem-staking-product-user_data)
```python
def redeem_staking_product(self, **params):
"""Redeem Staking Product
https://binance-docs.github.io/apidocs/spot/en/#redeem-staking-product-user_data
"""
return self._request_margin_api(
"post", "staking/redeem", signed=True, data=params
)
```
Get Staking Product Position
[https://binance-docs.github.io/apidocs/spot/en/#get-staking-product-position-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-staking-product-position-user_data)
```python
def get_staking_position(self, **params):
"""Get Staking Product Position
https://binance-docs.github.io/apidocs/spot/en/#get-staking-product-position-user_data
"""
return self._request_margin_api(
"get", "staking/position", signed=True, data=params
)
```
Get Staking Purchase History
[https://binance-docs.github.io/apidocs/spot/en/#get-staking-history-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-staking-history-user_data)
```python
def get_staking_purchase_history(self, **params):
"""Get Staking Purchase History
https://binance-docs.github.io/apidocs/spot/en/#get-staking-history-user_data
"""
return self._request_margin_api(
"get", "staking/purchaseRecord", signed=True, data=params
)
```
Set Auto Staking on Locked Staking or Locked DeFi Staking
[https://binance-docs.github.io/apidocs/spot/en/#set-auto-staking-user\_data](https://binance-docs.github.io/apidocs/spot/en/#set-auto-staking-user_data)
```python
def set_auto_staking(self, **params):
"""Set Auto Staking on Locked Staking or Locked DeFi Staking
https://binance-docs.github.io/apidocs/spot/en/#set-auto-staking-user_data
"""
return self._request_margin_api(
"post", "staking/setAutoStaking", signed=True, data=params
)
```
Get Personal Left Quota of Staking Product
[https://binance-docs.github.io/apidocs/spot/en/#get-personal-left-quota-of-staking-product-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-personal-left-quota-of-staking-product-user_data)
```python
def get_personal_left_quota(self, **params):
"""Get Personal Left Quota of Staking Product
https://binance-docs.github.io/apidocs/spot/en/#get-personal-left-quota-of-staking-product-user_data
"""
return self._request_margin_api(
"get", "staking/personalLeftQuota", signed=True, data=params
)
```
Get staking information for a supported asset (or assets)
[https://docs.binance.us/#get-staking-asset-information](https://docs.binance.us/#get-staking-asset-information)
:raises BinanceRegionException: If client is not configured for binance.us
```python
def get_staking_asset_us(self, **params):
"""Get staking information for a supported asset (or assets)
https://docs.binance.us/#get-staking-asset-information
:raises BinanceRegionException: If client is not configured for binance.us
"""
self._require_tld("us", "get_staking_asset_us")
return self._request_margin_api("get", "staking/asset", True, data=params)
```
Stake a supported asset.
[https://docs.binance.us/#stake-asset](https://docs.binance.us/#stake-asset)
:raises BinanceRegionException: If client is not configured for binance.us
```python
def stake_asset_us(self, **params):
"""Stake a supported asset.
https://docs.binance.us/#stake-asset
:raises BinanceRegionException: If client is not configured for binance.us
"""
self._require_tld("us", "stake_asset_us")
return self._request_margin_api("post", "staking/stake", True, data=params)
```
Unstake a staked asset
[https://docs.binance.us/#unstake-asset](https://docs.binance.us/#unstake-asset)
:raises BinanceRegionException: If client is not configured for binance.us
```python
def unstake_asset_us(self, **params):
"""Unstake a staked asset
https://docs.binance.us/#unstake-asset
:raises BinanceRegionException: If client is not configured for binance.us
"""
self._require_tld("us", "unstake_asset_us")
return self._request_margin_api("post", "staking/unstake", True, data=params)
```
Get staking balance
[https://docs.binance.us/#get-staking-balance](https://docs.binance.us/#get-staking-balance)
:raises BinanceRegionException: If client is not configured for binance.us
```python
def get_staking_balance_us(self, **params):
"""Get staking balance
https://docs.binance.us/#get-staking-balance
:raises BinanceRegionException: If client is not configured for binance.us
"""
self._require_tld("us", "get_staking_balance_us")
return self._request_margin_api(
"get", "staking/stakingBalance", True, data=params
)
```
Get staking history
[https://docs.binance.us/#get-staking-history](https://docs.binance.us/#get-staking-history)
:raises BinanceRegionException: If client is not configured for binance.us
```python
def get_staking_history_us(self, **params):
"""Get staking history
https://docs.binance.us/#get-staking-history
:raises BinanceRegionException: If client is not configured for binance.us
"""
self._require_tld("us", "get_staking_history_us")
return self._request_margin_api("get", "staking/history", True, data=params)
```
Get staking rewards history for an asset(or assets) within a given time range.
[https://docs.binance.us/#get-staking-rewards-history](https://docs.binance.us/#get-staking-rewards-history)
:raises BinanceRegionException: If client is not configured for binance.us
```python
def get_staking_rewards_history_us(self, **params):
"""Get staking rewards history for an asset(or assets) within a given time range.
https://docs.binance.us/#get-staking-rewards-history
:raises BinanceRegionException: If client is not configured for binance.us
"""
self._require_tld("us", "get_staking_rewards_history_us")
return self._request_margin_api(
"get", "staking/stakingRewardsHistory", True, data=params
)
```
Query Sub-account List.
[https://developers.binance.com/docs/sub\_account/account-management/Query-Sub-account-List](https://developers.binance.com/docs/sub_account/account-management/Query-Sub-account-List)
:param email: optional - Sub-account email
:type email: str
:param isFreeze: optional
:type isFreeze: str
:param page: optional - Default value: 1
:type page: int
:param limit: optional - Default value: 1, Max value: 200
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"subAccounts":\[
\{
"email":"[testsub@gmail.com](mailto:testsub@gmail.com)",
"isFreeze":false,
"createTime":1544433328000
},
\{
"email":"[virtual@oxebmvfonoemail.com](mailto:virtual@oxebmvfonoemail.com)",
"isFreeze":false,
"createTime":1544433328000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_sub_account_list(self, **params):
"""Query Sub-account List.
https://developers.binance.com/docs/sub_account/account-management/Query-Sub-account-List
:param email: optional - Sub-account email
:type email: str
:param isFreeze: optional
:type isFreeze: str
:param page: optional - Default value: 1
:type page: int
:param limit: optional - Default value: 1, Max value: 200
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"subAccounts":[
{
"email":"testsub@gmail.com",
"isFreeze":false,
"createTime":1544433328000
},
{
"email":"virtual@oxebmvfonoemail.com",
"isFreeze":false,
"createTime":1544433328000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "sub-account/list", True, data=params)
```
Query Sub-account Transfer History.
[https://developers.binance.com/docs/sub\_account/asset-management/Query-Sub-account-Spot-Asset-Transfer-History](https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Spot-Asset-Transfer-History)
:param fromEmail: optional
:type fromEmail: str
:param toEmail: optional
:type toEmail: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param page: optional - Default value: 1
:type page: int
:param limit: optional - Default value: 500
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"from":"[aaa@test.com](mailto:aaa@test.com)",
"to":"[bbb@test.com](mailto:bbb@test.com)",
"asset":"BTC",
"qty":"10",
"status": "SUCCESS",
"tranId": 6489943656,
"time":1544433328000
},
\{
"from":"[bbb@test.com](mailto:bbb@test.com)",
"to":"[ccc@test.com](mailto:ccc@test.com)",
"asset":"ETH",
"qty":"2",
"status": "SUCCESS",
"tranId": 6489938713,
"time":1544433328000
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_sub_account_transfer_history(self, **params):
"""Query Sub-account Transfer History.
https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Spot-Asset-Transfer-History
:param fromEmail: optional
:type fromEmail: str
:param toEmail: optional
:type toEmail: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param page: optional - Default value: 1
:type page: int
:param limit: optional - Default value: 500
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"from":"aaa@test.com",
"to":"bbb@test.com",
"asset":"BTC",
"qty":"10",
"status": "SUCCESS",
"tranId": 6489943656,
"time":1544433328000
},
{
"from":"bbb@test.com",
"to":"ccc@test.com",
"asset":"ETH",
"qty":"2",
"status": "SUCCESS",
"tranId": 6489938713,
"time":1544433328000
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/sub/transfer/history", True, data=params
)
```
Query Sub-account Futures Transfer History.
[https://developers.binance.com/docs/sub\_account/asset-management/Query-Sub-account-Futures-Asset-Transfer-History](https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Futures-Asset-Transfer-History)
:param email: required
:type email: str
:param futuresType: required
:type futuresType: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param page: optional
:type page: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"success":true,
"futuresType": 2,
"transfers":\[
\{
"from":"[aaa@test.com](mailto:aaa@test.com)",
"to":"[bbb@test.com](mailto:bbb@test.com)",
"asset":"BTC",
"qty":"1",
"time":1544433328000
},
\{
"from":"[bbb@test.com](mailto:bbb@test.com)",
"to":"[ccc@test.com](mailto:ccc@test.com)",
"asset":"ETH",
"qty":"2",
"time":1544433328000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_sub_account_futures_transfer_history(self, **params):
"""Query Sub-account Futures Transfer History.
https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Futures-Asset-Transfer-History
:param email: required
:type email: str
:param futuresType: required
:type futuresType: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param page: optional
:type page: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"success":true,
"futuresType": 2,
"transfers":[
{
"from":"aaa@test.com",
"to":"bbb@test.com",
"asset":"BTC",
"qty":"1",
"time":1544433328000
},
{
"from":"bbb@test.com",
"to":"ccc@test.com",
"asset":"ETH",
"qty":"2",
"time":1544433328000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/futures/internalTransfer", True, data=params
)
```
Execute sub-account Futures transfer
[https://developers.binance.com/docs/sub\_account/asset-management/Sub-account-Futures-Asset-Transfer](https://developers.binance.com/docs/sub_account/asset-management/Sub-account-Futures-Asset-Transfer)
:param fromEmail: required - Sender email
:type fromEmail: str
:param toEmail: required - Recipient email
:type toEmail: str
:param futuresType: required
:type futuresType: int
:param asset: required
:type asset: str
:param amount: required
:type amount: decimal
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"success":true,
"txnId":"2934662589"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def create_sub_account_futures_transfer(self, **params):
"""Execute sub-account Futures transfer
https://developers.binance.com/docs/sub_account/asset-management/Sub-account-Futures-Asset-Transfer
:param fromEmail: required - Sender email
:type fromEmail: str
:param toEmail: required - Recipient email
:type toEmail: str
:param futuresType: required
:type futuresType: int
:param asset: required
:type asset: str
:param amount: required
:type amount: decimal
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"success":true,
"txnId":"2934662589"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "sub-account/futures/internalTransfer", True, data=params
)
```
Fetch sub-account assets
[https://developers.binance.com/docs/sub\_account/asset-management/Query-Sub-account-Assets-V4](https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Assets-V4)
:param email: required
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"balances":\[
\{
"asset":"ADA",
"free":10000,
"locked":0
},
\{
"asset":"BNB",
"free":10003,
"locked":0
},
\{
"asset":"BTC",
"free":11467.6399,
"locked":0
},
\{
"asset":"ETH",
"free":10004.995,
"locked":0
},
\{
"asset":"USDT",
"free":11652.14213,
"locked":0
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_sub_account_assets(self, **params):
"""Fetch sub-account assets
https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Assets-V4
:param email: required
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"balances":[
{
"asset":"ADA",
"free":10000,
"locked":0
},
{
"asset":"BNB",
"free":10003,
"locked":0
},
{
"asset":"BTC",
"free":11467.6399,
"locked":0
},
{
"asset":"ETH",
"free":10004.995,
"locked":0
},
{
"asset":"USDT",
"free":11652.14213,
"locked":0
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/assets", True, data=params, version=4
)
```
Query Sub-account Spot Assets Summary (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Query-Sub-account-Spot-Assets-Summary](https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Spot-Assets-Summary)
:param email: optional - Sub account email
:type email: str
:param page: optional - default 1
:type page: int
:param size: optional - default 10, max 20
:type size: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"totalCount":2,
"masterAccountTotalAsset": "0.23231201",
"spotSubUserAssetBtcVoList":\[
\{
"email":"[sub123@test.com](mailto:sub123@test.com)",
"totalAsset":"9999.00000000"
},
\{
"email":"[test456@test.com](mailto:test456@test.com)",
"totalAsset":"0.00000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def query_subaccount_spot_summary(self, **params):
"""Query Sub-account Spot Assets Summary (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Query-Sub-account-Spot-Assets-Summary
:param email: optional - Sub account email
:type email: str
:param page: optional - default 1
:type page: int
:param size: optional - default 10, max 20
:type size: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"totalCount":2,
"masterAccountTotalAsset": "0.23231201",
"spotSubUserAssetBtcVoList":[
{
"email":"sub123@test.com",
"totalAsset":"9999.00000000"
},
{
"email":"test456@test.com",
"totalAsset":"0.00000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/spotSummary", True, data=params
)
```
Get Sub-account Deposit Address (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Get-Sub-account-Deposit-Address](https://developers.binance.com/docs/sub_account/asset-management/Get-Sub-account-Deposit-Address)
:param email: required - Sub account email
:type email: str
:param coin: required
:type coin: str
:param network: optional
:type network: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"address":"TDunhSa7jkTNuKrusUTU1MUHtqXoBPKETV",
"coin":"USDT",
"tag":"",
"url":"[https://tronscan.org/#/address/TDunhSa7jkTNuKrusUTU1MUHtqXoBPKETV](https://tronscan.org/#/address/TDunhSa7jkTNuKrusUTU1MUHtqXoBPKETV)"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_subaccount_deposit_address(self, **params):
"""Get Sub-account Deposit Address (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Get-Sub-account-Deposit-Address
:param email: required - Sub account email
:type email: str
:param coin: required
:type coin: str
:param network: optional
:type network: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"address":"TDunhSa7jkTNuKrusUTU1MUHtqXoBPKETV",
"coin":"USDT",
"tag":"",
"url":"https://tronscan.org/#/address/TDunhSa7jkTNuKrusUTU1MUHtqXoBPKETV"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "capital/deposit/subAddress", True, data=params
)
```
Get Sub-account Deposit History (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Get-Sub-account-Deposit-History](https://developers.binance.com/docs/sub_account/asset-management/Get-Sub-account-Deposit-History)
:param email: required - Sub account email
:type email: str
:param coin: optional
:type coin: str
:param status: optional - (0:pending,6: credited but cannot withdraw, 1:success)
:type status: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional
:type limit: int
:param offset: optional - default:0
:type offset: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"amount":"0.00999800",
"coin":"PAXG",
"network":"ETH",
"status":1,
"address":"0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
"addressTag":"",
"txId":"0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
"insertTime":1599621997000,
"transferType":0,
"confirmTimes":"12/12"
},
\{
"amount":"0.50000000",
"coin":"IOTA",
"network":"IOTA",
"status":1,
"address":"SIZ9VLMHWATXKV99LH99CIGFJFUMLEHGWVZVNNZXRJJVWBPHYWPPBOSDORZ9EQSHCZAMPVAPGFYQAUUV9DROOXJLNW",
"addressTag":"",
"txId":"ESBFVQUTPIWQNJSPXFNHNYHSQNTGKRVKPRABQWTAXCDWOAKDKYWPTVG9BGXNVNKTLEJGESAVXIKIZ9999",
"insertTime":1599620082000,
"transferType":0,
"confirmTimes":"1/1"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_subaccount_deposit_history(self, **params):
"""Get Sub-account Deposit History (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Get-Sub-account-Deposit-History
:param email: required - Sub account email
:type email: str
:param coin: optional
:type coin: str
:param status: optional - (0:pending,6: credited but cannot withdraw, 1:success)
:type status: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional
:type limit: int
:param offset: optional - default:0
:type offset: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"amount":"0.00999800",
"coin":"PAXG",
"network":"ETH",
"status":1,
"address":"0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
"addressTag":"",
"txId":"0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
"insertTime":1599621997000,
"transferType":0,
"confirmTimes":"12/12"
},
{
"amount":"0.50000000",
"coin":"IOTA",
"network":"IOTA",
"status":1,
"address":"SIZ9VLMHWATXKV99LH99CIGFJFUMLEHGWVZVNNZXRJJVWBPHYWPPBOSDORZ9EQSHCZAMPVAPGFYQAUUV9DROOXJLNW",
"addressTag":"",
"txId":"ESBFVQUTPIWQNJSPXFNHNYHSQNTGKRVKPRABQWTAXCDWOAKDKYWPTVG9BGXNVNKTLEJGESAVXIKIZ9999",
"insertTime":1599620082000,
"transferType":0,
"confirmTimes":"1/1"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "capital/deposit/subHisrec", True, data=params
)
```
Get Sub-account's Status on Margin/Futures (For Master Account)
[https://developers.binance.com/docs/sub\_account/account-management/Get-Sub-accounts-Status-on-Margin-Or-Futures](https://developers.binance.com/docs/sub_account/account-management/Get-Sub-accounts-Status-on-Margin-Or-Futures)
:param email: optional - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"email":"[123@test.com](mailto:123@test.com)", // user email
"isSubUserEnabled": true, // true or false
"isUserActive": true, // true or false
"insertTime": 1570791523523 // sub account create time
"isMarginEnabled": true, // true or false for margin
"isFutureEnabled": true // true or false for futures.
"mobile": 1570791523523 // user mobile number
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_subaccount_futures_margin_status(self, **params):
"""Get Sub-account's Status on Margin/Futures (For Master Account)
https://developers.binance.com/docs/sub_account/account-management/Get-Sub-accounts-Status-on-Margin-Or-Futures
:param email: optional - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"email":"123@test.com", // user email
"isSubUserEnabled": true, // true or false
"isUserActive": true, // true or false
"insertTime": 1570791523523 // sub account create time
"isMarginEnabled": true, // true or false for margin
"isFutureEnabled": true // true or false for futures.
"mobile": 1570791523523 // user mobile number
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "sub-account/status", True, data=params)
```
Enable Margin for Sub-account (For Master Account)
[https://binance-docs.github.io/apidocs/spot/en/#enable-margin-for-sub-account-for-master-account](https://binance-docs.github.io/apidocs/spot/en/#enable-margin-for-sub-account-for-master-account)
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"email":"[123@test.com](mailto:123@test.com)",
"isMarginEnabled": true
}
:raises: BinanceRequestException, BinanceAPIException
```python
def enable_subaccount_margin(self, **params):
"""Enable Margin for Sub-account (For Master Account)
https://binance-docs.github.io/apidocs/spot/en/#enable-margin-for-sub-account-for-master-account
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"email":"123@test.com",
"isMarginEnabled": true
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "sub-account/margin/enable", True, data=params
)
```
Get Detail on Sub-account's Margin Account (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Get-Detail-on-Sub-accounts-Margin-Account](https://developers.binance.com/docs/sub_account/asset-management/Get-Detail-on-Sub-accounts-Margin-Account)
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"email":"[123@test.com](mailto:123@test.com)",
"marginLevel": "11.64405625",
"totalAssetOfBtc": "6.82728457",
"totalLiabilityOfBtc": "0.58633215",
"totalNetAssetOfBtc": "6.24095242",
"marginTradeCoeffVo":
\{
"forceLiquidationBar": "1.10000000", // Liquidation margin ratio
"marginCallBar": "1.50000000", // Margin call margin ratio
"normalBar": "2.00000000" // Initial margin ratio
},
"marginUserAssetVoList": \[
\{
"asset": "BTC",
"borrowed": "0.00000000",
"free": "0.00499500",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00499500"
},
\{
"asset": "BNB",
"borrowed": "201.66666672",
"free": "2346.50000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "2144.83333328"
},
\{
"asset": "ETH",
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000"
},
\{
"asset": "USDT",
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_subaccount_margin_details(self, **params):
"""Get Detail on Sub-account's Margin Account (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Get-Detail-on-Sub-accounts-Margin-Account
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"email":"123@test.com",
"marginLevel": "11.64405625",
"totalAssetOfBtc": "6.82728457",
"totalLiabilityOfBtc": "0.58633215",
"totalNetAssetOfBtc": "6.24095242",
"marginTradeCoeffVo":
{
"forceLiquidationBar": "1.10000000", // Liquidation margin ratio
"marginCallBar": "1.50000000", // Margin call margin ratio
"normalBar": "2.00000000" // Initial margin ratio
},
"marginUserAssetVoList": [
{
"asset": "BTC",
"borrowed": "0.00000000",
"free": "0.00499500",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00499500"
},
{
"asset": "BNB",
"borrowed": "201.66666672",
"free": "2346.50000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "2144.83333328"
},
{
"asset": "ETH",
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000"
},
{
"asset": "USDT",
"borrowed": "0.00000000",
"free": "0.00000000",
"interest": "0.00000000",
"locked": "0.00000000",
"netAsset": "0.00000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/margin/account", True, data=params
)
```
Get Summary of Sub-account's Margin Account (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Get-Summary-of-Sub-accounts-Margin-Account](https://developers.binance.com/docs/sub_account/asset-management/Get-Summary-of-Sub-accounts-Margin-Account)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"totalAssetOfBtc": "4.33333333",
"totalLiabilityOfBtc": "2.11111112",
"totalNetAssetOfBtc": "2.22222221",
"subAccountList":\[
\{
"email":"[123@test.com](mailto:123@test.com)",
"totalAssetOfBtc": "2.11111111",
"totalLiabilityOfBtc": "1.11111111",
"totalNetAssetOfBtc": "1.00000000"
},
\{
"email":"[345@test.com](mailto:345@test.com)",
"totalAssetOfBtc": "2.22222222",
"totalLiabilityOfBtc": "1.00000001",
"totalNetAssetOfBtc": "1.22222221"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_subaccount_margin_summary(self, **params):
"""Get Summary of Sub-account's Margin Account (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Get-Summary-of-Sub-accounts-Margin-Account
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"totalAssetOfBtc": "4.33333333",
"totalLiabilityOfBtc": "2.11111112",
"totalNetAssetOfBtc": "2.22222221",
"subAccountList":[
{
"email":"123@test.com",
"totalAssetOfBtc": "2.11111111",
"totalLiabilityOfBtc": "1.11111111",
"totalNetAssetOfBtc": "1.00000000"
},
{
"email":"345@test.com",
"totalAssetOfBtc": "2.22222222",
"totalLiabilityOfBtc": "1.00000001",
"totalNetAssetOfBtc": "1.22222221"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/margin/accountSummary", True, data=params
)
```
Enable Futures for Sub-account (For Master Account)
[https://developers.binance.com/docs/sub\_account/account-management/Enable-Futures-for-Sub-account](https://developers.binance.com/docs/sub_account/account-management/Enable-Futures-for-Sub-account)
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"email":"[123@test.com](mailto:123@test.com)",
"isFuturesEnabled": true // true or false
}
:raises: BinanceRequestException, BinanceAPIException
```python
def enable_subaccount_futures(self, **params):
"""Enable Futures for Sub-account (For Master Account)
https://developers.binance.com/docs/sub_account/account-management/Enable-Futures-for-Sub-account
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"email":"123@test.com",
"isFuturesEnabled": true // true or false
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "sub-account/futures/enable", True, data=params
)
```
Get Detail on Sub-account's Futures Account (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Get-Detail-on-Sub-accounts-Futures-Account](https://developers.binance.com/docs/sub_account/asset-management/Get-Detail-on-Sub-accounts-Futures-Account)
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"email": "[abc@test.com](mailto:abc@test.com)",
"asset": "USDT",
"assets":\[
\{
"asset": "USDT",
"initialMargin": "0.00000000",
"maintenanceMargin": "0.00000000",
"marginBalance": "0.88308000",
"maxWithdrawAmount": "0.88308000",
"openOrderInitialMargin": "0.00000000",
"positionInitialMargin": "0.00000000",
"unrealizedProfit": "0.00000000",
"walletBalance": "0.88308000"
}
],
"canDeposit": true,
"canTrade": true,
"canWithdraw": true,
"feeTier": 2,
"maxWithdrawAmount": "0.88308000",
"totalInitialMargin": "0.00000000",
"totalMaintenanceMargin": "0.00000000",
"totalMarginBalance": "0.88308000",
"totalOpenOrderInitialMargin": "0.00000000",
"totalPositionInitialMargin": "0.00000000",
"totalUnrealizedProfit": "0.00000000",
"totalWalletBalance": "0.88308000",
"updateTime": 1576756674610
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_subaccount_futures_details(self, **params):
"""Get Detail on Sub-account's Futures Account (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Get-Detail-on-Sub-accounts-Futures-Account
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"email": "abc@test.com",
"asset": "USDT",
"assets":[
{
"asset": "USDT",
"initialMargin": "0.00000000",
"maintenanceMargin": "0.00000000",
"marginBalance": "0.88308000",
"maxWithdrawAmount": "0.88308000",
"openOrderInitialMargin": "0.00000000",
"positionInitialMargin": "0.00000000",
"unrealizedProfit": "0.00000000",
"walletBalance": "0.88308000"
}
],
"canDeposit": true,
"canTrade": true,
"canWithdraw": true,
"feeTier": 2,
"maxWithdrawAmount": "0.88308000",
"totalInitialMargin": "0.00000000",
"totalMaintenanceMargin": "0.00000000",
"totalMarginBalance": "0.88308000",
"totalOpenOrderInitialMargin": "0.00000000",
"totalPositionInitialMargin": "0.00000000",
"totalUnrealizedProfit": "0.00000000",
"totalWalletBalance": "0.88308000",
"updateTime": 1576756674610
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/futures/account", True, data=params, version=2
)
```
Get Summary of Sub-account's Futures Account (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Get-Summary-of-Sub-accounts-Futures-Account-V2](https://developers.binance.com/docs/sub_account/asset-management/Get-Summary-of-Sub-accounts-Futures-Account-V2)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"totalInitialMargin": "9.83137400",
"totalMaintenanceMargin": "0.41568700",
"totalMarginBalance": "23.03235621",
"totalOpenOrderInitialMargin": "9.00000000",
"totalPositionInitialMargin": "0.83137400",
"totalUnrealizedProfit": "0.03219710",
"totalWalletBalance": "22.15879444",
"asset": "USDT",
"subAccountList":\[
\{
"email": "[123@test.com](mailto:123@test.com)",
"totalInitialMargin": "9.00000000",
"totalMaintenanceMargin": "0.00000000",
"totalMarginBalance": "22.12659734",
"totalOpenOrderInitialMargin": "9.00000000",
"totalPositionInitialMargin": "0.00000000",
"totalUnrealizedProfit": "0.00000000",
"totalWalletBalance": "22.12659734",
"asset": "USDT"
},
\{
"email": "[345@test.com](mailto:345@test.com)",
"totalInitialMargin": "0.83137400",
"totalMaintenanceMargin": "0.41568700",
"totalMarginBalance": "0.90575887",
"totalOpenOrderInitialMargin": "0.00000000",
"totalPositionInitialMargin": "0.83137400",
"totalUnrealizedProfit": "0.03219710",
"totalWalletBalance": "0.87356177",
"asset": "USDT"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_subaccount_futures_summary(self, **params):
"""Get Summary of Sub-account's Futures Account (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Get-Summary-of-Sub-accounts-Futures-Account-V2
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"totalInitialMargin": "9.83137400",
"totalMaintenanceMargin": "0.41568700",
"totalMarginBalance": "23.03235621",
"totalOpenOrderInitialMargin": "9.00000000",
"totalPositionInitialMargin": "0.83137400",
"totalUnrealizedProfit": "0.03219710",
"totalWalletBalance": "22.15879444",
"asset": "USDT",
"subAccountList":[
{
"email": "123@test.com",
"totalInitialMargin": "9.00000000",
"totalMaintenanceMargin": "0.00000000",
"totalMarginBalance": "22.12659734",
"totalOpenOrderInitialMargin": "9.00000000",
"totalPositionInitialMargin": "0.00000000",
"totalUnrealizedProfit": "0.00000000",
"totalWalletBalance": "22.12659734",
"asset": "USDT"
},
{
"email": "345@test.com",
"totalInitialMargin": "0.83137400",
"totalMaintenanceMargin": "0.41568700",
"totalMarginBalance": "0.90575887",
"totalOpenOrderInitialMargin": "0.00000000",
"totalPositionInitialMargin": "0.83137400",
"totalUnrealizedProfit": "0.03219710",
"totalWalletBalance": "0.87356177",
"asset": "USDT"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/futures/accountSummary", True, data=params, version=2
)
```
Get Futures Position-Risk of Sub-account (For Master Account)
[https://developers.binance.com/docs/sub\_account/account-management/Get-Futures-Position-Risk-of-Sub-account-V2](https://developers.binance.com/docs/sub_account/account-management/Get-Futures-Position-Risk-of-Sub-account-V2)
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"entryPrice": "9975.12000",
"leverage": "50", // current initial leverage
"maxNotional": "1000000", // notional value limit of current initial leverage
"liquidationPrice": "7963.54",
"markPrice": "9973.50770517",
"positionAmount": "0.010",
"symbol": "BTCUSDT",
"unrealizedProfit": "-0.01612295"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_subaccount_futures_positionrisk(self, **params):
"""Get Futures Position-Risk of Sub-account (For Master Account)
https://developers.binance.com/docs/sub_account/account-management/Get-Futures-Position-Risk-of-Sub-account-V2
:param email: required - Sub account email
:type email: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"entryPrice": "9975.12000",
"leverage": "50", // current initial leverage
"maxNotional": "1000000", // notional value limit of current initial leverage
"liquidationPrice": "7963.54",
"markPrice": "9973.50770517",
"positionAmount": "0.010",
"symbol": "BTCUSDT",
"unrealizedProfit": "-0.01612295"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/futures/positionRisk", True, data=params, version=2
)
```
Futures Transfer for Sub-account (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management](https://developers.binance.com/docs/sub_account/asset-management)
:param email: required - Sub account email
:type email: str
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required - The amount to be transferred
:type amount: float
:param type: required - 1: transfer from subaccount's spot account to its USDT-margined futures account
2: transfer from subaccount's USDT-margined futures account to its spot account
3: transfer from subaccount's spot account to its COIN-margined futures account
4: transfer from subaccount's COIN-margined futures account to its spot account
:type type: int
:returns: API response
.. code-block:: python
\{
"txnId":"2966662589"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def make_subaccount_futures_transfer(self, **params):
"""Futures Transfer for Sub-account (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management
:param email: required - Sub account email
:type email: str
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required - The amount to be transferred
:type amount: float
:param type: required - 1: transfer from subaccount's spot account to its USDT-margined futures account
2: transfer from subaccount's USDT-margined futures account to its spot account
3: transfer from subaccount's spot account to its COIN-margined futures account
4: transfer from subaccount's COIN-margined futures account to its spot account
:type type: int
:returns: API response
.. code-block:: python
{
"txnId":"2966662589"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "sub-account/futures/transfer", True, data=params
)
```
Margin Transfer for Sub-account (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Margin-Transfer-for-Sub-account](https://developers.binance.com/docs/sub_account/asset-management/Margin-Transfer-for-Sub-account)
:param email: required - Sub account email
:type email: str
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required - The amount to be transferred
:type amount: float
:param type: required - 1: transfer from subaccount's spot account to margin account
2: transfer from subaccount's margin account to its spot account
:type type: int
:returns: API response
.. code-block:: python
\{
"txnId":"2966662589"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def make_subaccount_margin_transfer(self, **params):
"""Margin Transfer for Sub-account (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Margin-Transfer-for-Sub-account
:param email: required - Sub account email
:type email: str
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required - The amount to be transferred
:type amount: float
:param type: required - 1: transfer from subaccount's spot account to margin account
2: transfer from subaccount's margin account to its spot account
:type type: int
:returns: API response
.. code-block:: python
{
"txnId":"2966662589"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "sub-account/margin/transfer", True, data=params
)
```
Transfer to Sub-account of Same Master (For Sub-account)
[https://developers.binance.com/docs/sub\_account/asset-management/Transfer-to-Sub-account-of-Same-Master](https://developers.binance.com/docs/sub_account/asset-management/Transfer-to-Sub-account-of-Same-Master)
:param toEmail: required - Sub account email
:type toEmail: str
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required - The amount to be transferred
:type amount: float
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"txnId":"2966662589"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def make_subaccount_to_subaccount_transfer(self, **params):
"""Transfer to Sub-account of Same Master (For Sub-account)
https://developers.binance.com/docs/sub_account/asset-management/Transfer-to-Sub-account-of-Same-Master
:param toEmail: required - Sub account email
:type toEmail: str
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required - The amount to be transferred
:type amount: float
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"txnId":"2966662589"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "sub-account/transfer/subToSub", True, data=params
)
```
Transfer to Master (For Sub-account)
[https://developers.binance.com/docs/sub\_account/asset-management/Transfer-to-Master](https://developers.binance.com/docs/sub_account/asset-management/Transfer-to-Master)
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required - The amount to be transferred
:type amount: float
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"txnId":"2966662589"
}
:raises: BinanceRequestException, BinanceAPIException
```python
def make_subaccount_to_master_transfer(self, **params):
"""Transfer to Master (For Sub-account)
https://developers.binance.com/docs/sub_account/asset-management/Transfer-to-Master
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required - The amount to be transferred
:type amount: float
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"txnId":"2966662589"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "sub-account/transfer/subToMaster", True, data=params
)
```
Sub-account Transfer History (For Sub-account)
[https://developers.binance.com/docs/sub\_account/asset-management/Sub-account-Transfer-History](https://developers.binance.com/docs/sub_account/asset-management/Sub-account-Transfer-History)
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param type: optional - 1: transfer in, 2: transfer out
:type type: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional - Default 500
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"counterParty":"master",
"email":"[master@test.com](mailto:master@test.com)",
"type":1, // 1 for transfer in, 2 for transfer out
"asset":"BTC",
"qty":"1",
"status":"SUCCESS",
"tranId":11798835829,
"time":1544433325000
},
\{
"counterParty":"subAccount",
"email":"[sub2@test.com](mailto:sub2@test.com)",
"type":2,
"asset":"ETH",
"qty":"2",
"status":"SUCCESS",
"tranId":11798829519,
"time":1544433326000
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_subaccount_transfer_history(self, **params):
"""Sub-account Transfer History (For Sub-account)
https://developers.binance.com/docs/sub_account/asset-management/Sub-account-Transfer-History
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param type: optional - 1: transfer in, 2: transfer out
:type type: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional - Default 500
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"counterParty":"master",
"email":"master@test.com",
"type":1, // 1 for transfer in, 2 for transfer out
"asset":"BTC",
"qty":"1",
"status":"SUCCESS",
"tranId":11798835829,
"time":1544433325000
},
{
"counterParty":"subAccount",
"email":"sub2@test.com",
"type":2,
"asset":"ETH",
"qty":"2",
"status":"SUCCESS",
"tranId":11798829519,
"time":1544433326000
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/transfer/subUserHistory", True, data=params
)
```
Universal Transfer (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Universal-Transfer](https://developers.binance.com/docs/sub_account/asset-management/Universal-Transfer)
:param fromEmail: optional
:type fromEmail: str
:param toEmail: optional
:type toEmail: str
:param fromAccountType: required - "SPOT","USDT\_FUTURE","COIN\_FUTURE"
:type fromAccountType: str
:param toAccountType: required - "SPOT","USDT\_FUTURE","COIN\_FUTURE"
:type toAccountType: str
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required
:type amount: float
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"tranId":11945860693
}
:raises: BinanceRequestException, BinanceAPIException
```python
def make_subaccount_universal_transfer(self, **params):
"""Universal Transfer (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Universal-Transfer
:param fromEmail: optional
:type fromEmail: str
:param toEmail: optional
:type toEmail: str
:param fromAccountType: required - "SPOT","USDT_FUTURE","COIN_FUTURE"
:type fromAccountType: str
:param toAccountType: required - "SPOT","USDT_FUTURE","COIN_FUTURE"
:type toAccountType: str
:param asset: required - The asset being transferred, e.g., USDT
:type asset: str
:param amount: required
:type amount: float
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"tranId":11945860693
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "sub-account/universalTransfer", True, data=params
)
```
Universal Transfer (For Master Account)
[https://developers.binance.com/docs/sub\_account/asset-management/Query-Universal-Transfer-History](https://developers.binance.com/docs/sub_account/asset-management/Query-Universal-Transfer-History)
:param fromEmail: optional
:type fromEmail: str
:param toEmail: optional
:type toEmail: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param page: optional
:type page: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"tranId":11945860693,
"fromEmail":"[master@test.com](mailto:master@test.com)",
"toEmail":"[subaccount1@test.com](mailto:subaccount1@test.com)",
"asset":"BTC",
"amount":"0.1",
"fromAccountType":"SPOT",
"toAccountType":"COIN\_FUTURE",
"status":"SUCCESS",
"createTimeStamp":1544433325000
},
\{
"tranId":11945857955,
"fromEmail":"[master@test.com](mailto:master@test.com)",
"toEmail":"[subaccount2@test.com](mailto:subaccount2@test.com)",
"asset":"ETH",
"amount":"0.2",
"fromAccountType":"SPOT",
"toAccountType":"USDT\_FUTURE",
"status":"SUCCESS",
"createTimeStamp":1544433326000
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def get_universal_transfer_history(self, **params):
"""Universal Transfer (For Master Account)
https://developers.binance.com/docs/sub_account/asset-management/Query-Universal-Transfer-History
:param fromEmail: optional
:type fromEmail: str
:param toEmail: optional
:type toEmail: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param page: optional
:type page: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"tranId":11945860693,
"fromEmail":"master@test.com",
"toEmail":"subaccount1@test.com",
"asset":"BTC",
"amount":"0.1",
"fromAccountType":"SPOT",
"toAccountType":"COIN_FUTURE",
"status":"SUCCESS",
"createTimeStamp":1544433325000
},
{
"tranId":11945857955,
"fromEmail":"master@test.com",
"toEmail":"subaccount2@test.com",
"asset":"ETH",
"amount":"0.2",
"fromAccountType":"SPOT",
"toAccountType":"USDT_FUTURE",
"status":"SUCCESS",
"createTimeStamp":1544433326000
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "sub-account/universalTransfer", True, data=params
)
```
Test connectivity to the Rest API
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api)
```python
def futures_ping(self):
"""Test connectivity to the Rest API
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api
"""
return self._request_futures_api("get", "ping")
```
Test connectivity to the Rest API and get the current server time.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Check-Server-Time](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Check-Server-Time)
```python
def futures_time(self):
"""Test connectivity to the Rest API and get the current server time.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Check-Server-Time
"""
return self._request_futures_api("get", "time")
```
Current exchange trading rules and symbol information
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Exchange-Information](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Exchange-Information)
```python
def futures_exchange_info(self):
"""Current exchange trading rules and symbol information
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Exchange-Information
"""
return self._request_futures_api("get", "exchangeInfo")
```
Get the Order Book for the market
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Order-Book](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Order-Book)
```python
def futures_order_book(self, **params):
"""Get the Order Book for the market
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Order-Book
"""
return self._request_futures_api("get", "depth", data=params)
```
Get RPI Order Book with Retail Price Improvement orders
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/RPI-Order-Book](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/RPI-Order-Book)
:param symbol: required
:type symbol: str
:param limit: Default 1000; Valid limits:\[1000]
:type limit: int
:returns: API response
.. code-block:: python
\{
"lastUpdateId": 1027024,
"E": 1589436922972, // Message output time
"T": 1589436922959, // Transaction time
"bids": \[
\[
"4.00000000", // PRICE
"431.00000000" // QTY
]
],
"asks": \[
\[
"4.00000200",
"12.00000000"
]
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def futures_rpi_depth(self, **params):
"""Get RPI Order Book with Retail Price Improvement orders
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/RPI-Order-Book
:param symbol: required
:type symbol: str
:param limit: Default 1000; Valid limits:[1000]
:type limit: int
:returns: API response
.. code-block:: python
{
"lastUpdateId": 1027024,
"E": 1589436922972, // Message output time
"T": 1589436922959, // Transaction time
"bids": [
[
"4.00000000", // PRICE
"431.00000000" // QTY
]
],
"asks": [
[
"4.00000200",
"12.00000000"
]
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_futures_api("get", "rpiDepth", data=params)
```
Get recent trades (up to last 500).
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Recent-Trades-List](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Recent-Trades-List)
```python
def futures_recent_trades(self, **params):
"""Get recent trades (up to last 500).
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Recent-Trades-List
"""
return self._request_futures_api("get", "trades", data=params)
```
Get older market historical trades.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Old-Trades-Lookup](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Old-Trades-Lookup)
```python
def futures_historical_trades(self, **params):
"""Get older market historical trades.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Old-Trades-Lookup
"""
return self._request_futures_api("get", "historicalTrades", data=params)
```
Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same
price will have the quantity aggregated.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Compressed-Aggregate-Trades-List](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Compressed-Aggregate-Trades-List)
```python
def futures_aggregate_trades(self, **params):
"""Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same
price will have the quantity aggregated.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Compressed-Aggregate-Trades-List
"""
return self._request_futures_api("get", "aggTrades", data=params)
```
Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
```python
def futures_klines(self, **params):
"""Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Kline-Candlestick-Data
"""
return self._request_futures_api("get", "klines", data=params)
```
Kline/candlestick bars for the mark price of a symbol. Klines are uniquely identified by their open time.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
```python
def futures_mark_price_klines(self, **params):
"""Kline/candlestick bars for the mark price of a symbol. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
"""
return self._request_futures_api("get", "markPriceKlines", data=params)
```
Kline/candlestick bars for the index price of a symbol. Klines are uniquely identified by their open time.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
```python
def futures_index_price_klines(self, **params):
"""Kline/candlestick bars for the index price of a symbol. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
"""
return self._request_futures_api("get", "indexPriceKlines", data=params)
```
Premium index kline bars of a symbol.l. Klines are uniquely identified by their open time.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
```python
def futures_premium_index_klines(self, **params):
"""Premium index kline bars of a symbol.l. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
"""
return self._request_futures_api("get", "premiumIndexKlines", data=params)
```
Kline/candlestick bars for a specific contract type. Klines are uniquely identified by their open time.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Continuous-Contract-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Continuous-Contract-Kline-Candlestick-Data)
```python
def futures_continuous_klines(self, **params):
"""Kline/candlestick bars for a specific contract type. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Continuous-Contract-Kline-Candlestick-Data
"""
return self._request_futures_api("get", "continuousKlines", data=params)
```
Get historical futures klines from Binance
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start\_str: Start date string in UTC format or timestamp in milliseconds
:type start\_str: str|int
:param end\_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end\_str: str|int
:param limit: Default None (fetches full range in batches of max 1000 per request). To limit the number of rows, pass an integer.
:type limit: int
:return: list of OHLCV values (Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore)
```python
def futures_historical_klines(
self, symbol: str, interval :str, start_str, end_str=None, limit=None
):
"""Get historical futures klines from Binance
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start_str: Start date string in UTC format or timestamp in milliseconds
:type start_str: str|int
:param end_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end_str: str|int
:param limit: Default None (fetches full range in batches of max 1000 per request). To limit the number of rows, pass an integer.
:type limit: int
:return: list of OHLCV values (Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore)
"""
return self._historical_klines(
symbol,
interval,
start_str,
end_str=end_str,
limit=limit,
klines_type=HistoricalKlinesType.FUTURES,
)
```
Get historical futures mark price klines from Binance
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start\_str: Start date string in UTC format or timestamp in milliseconds
:type start\_str: str|int
:param end\_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end\_str: str|int
:param limit: Default None (fetches full range in batches of max 1000 per request). To limit the number of rows, pass an integer.
:type limit: int
:return: list of OHLCV values (Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore)
```python
def futures_historical_mark_price_klines(
self, symbol: str, interval: str, start_str, end_str=None, limit=None
):
"""Get historical futures mark price klines from Binance
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start_str: Start date string in UTC format or timestamp in milliseconds
:type start_str: str|int
:param end_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end_str: str|int
:param limit: Default None (fetches full range in batches of max 1000 per request). To limit the number of rows, pass an integer.
:type limit: int
:return: list of OHLCV values (Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore)
"""
return self._historical_klines(
symbol,
interval,
start_str,
end_str=end_str,
limit=limit,
klines_type=HistoricalKlinesType.FUTURES_MARK_PRICE,
)
```
Get historical futures klines generator from Binance
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start\_str: Start date string in UTC format or timestamp in milliseconds
:type start\_str: str|int
:param end\_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end\_str: str|int
:return: generator of OHLCV values
```python
def futures_historical_klines_generator(
self, symbol, interval, start_str, end_str=None
):
"""Get historical futures klines generator from Binance
:param symbol: Name of symbol pair e.g. BNBBTC
:type symbol: str
:param interval: Binance Kline interval
:type interval: str
:param start_str: Start date string in UTC format or timestamp in milliseconds
:type start_str: str|int
:param end_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now)
:type end_str: str|int
:return: generator of OHLCV values
"""
return self._historical_klines_generator(
symbol,
interval,
start_str,
end_str=end_str,
klines_type=HistoricalKlinesType.FUTURES,
)
```
Get Mark Price and Funding Rate
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price)
```python
def futures_mark_price(self, **params):
"""Get Mark Price and Funding Rate
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Mark-Price
"""
return self._request_futures_api("get", "premiumIndex", data=params)
```
Get funding rate history
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-History](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-History)
```python
def futures_funding_rate(self, **params):
"""Get funding rate history
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-History
"""
return self._request_futures_api("get", "fundingRate", data=params)
```
Get present long to short ratio for top accounts of a specific symbol.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Top-Long-Short-Account-Ratio](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Top-Long-Short-Account-Ratio)
```python
def futures_top_longshort_account_ratio(self, **params):
"""Get present long to short ratio for top accounts of a specific symbol.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Top-Long-Short-Account-Ratio
"""
return self._request_futures_data_api(
"get", "topLongShortAccountRatio", data=params
)
```
Get present long to short ratio for top positions of a specific symbol.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Top-Trader-Long-Short-Ratio](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Top-Trader-Long-Short-Ratio)
```python
def futures_top_longshort_position_ratio(self, **params):
"""Get present long to short ratio for top positions of a specific symbol.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Top-Trader-Long-Short-Ratio
"""
return self._request_futures_data_api(
"get", "topLongShortPositionRatio", data=params
)
```
Get present global long to short ratio of a specific symbol.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Long-Short-Ratio](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Long-Short-Ratio)
```python
def futures_global_longshort_ratio(self, **params):
"""Get present global long to short ratio of a specific symbol.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Long-Short-Ratio
"""
return self._request_futures_data_api(
"get", "globalLongShortAccountRatio", data=params
)
```
Get taker buy to sell volume ratio of a specific symbol
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Taker-BuySell-Volume](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Taker-BuySell-Volume)
```python
def futures_taker_longshort_ratio(self, **params):
"""Get taker buy to sell volume ratio of a specific symbol
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Taker-BuySell-Volume
"""
return self._request_futures_data_api(
"get", "takerlongshortRatio", data=params
)
```
Get future basis of a specific symbol
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Basis](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Basis)
```python
def futures_basis(self, **params):
"""Get future basis of a specific symbol
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Basis
"""
return self._request_futures_data_api(
"get", "basis", data=params
)
```
24 hour rolling window price change statistics.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics)
```python
def futures_ticker(self, **params):
"""24 hour rolling window price change statistics.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics
"""
return self._request_futures_api("get", "ticker/24hr", data=params)
```
Latest price for a symbol or symbols.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Price-Ticker-v2](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Price-Ticker-v2)
```python
def futures_symbol_ticker(self, **params):
"""Latest price for a symbol or symbols.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Price-Ticker-v2
"""
return self._request_futures_api("get", "ticker/price", version=2, data=params)
```
Best price/qty on the order book for a symbol or symbols.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker)
```python
def futures_orderbook_ticker(self, **params):
"""Best price/qty on the order book for a symbol or symbols.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker
"""
return self._request_futures_api("get", "ticker/bookTicker", data=params)
```
Get latest price for a symbol or symbols
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Delivery-Price](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Delivery-Price)
```python
def futures_delivery_price(self, **params):
"""Get latest price for a symbol or symbols
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Delivery-Price
"""
return self._request_futures_data_api("get", "delivery-price", data=params)
```
Get index price constituents
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Constituents](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Constituents)
```python
def futures_index_price_constituents(self, **params):
"""Get index price constituents
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Index-Constituents
"""
return self._request_futures_api("get", "constituents", data=params)
```
Get Insurance Fund Balance Snapshot
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Insurance-Fund-Balance](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Insurance-Fund-Balance)
```python
def futures_insurance_fund_balance_snapshot(self, **params):
"""Get Insurance Fund Balance Snapshot
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Insurance-Fund-Balance
"""
return self._request_futures_api("get", "insuranceBalance", data=params)
```
Get all liquidation orders
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Users-Force-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Users-Force-Orders)
```python
def futures_liquidation_orders(self, **params):
"""Get all liquidation orders
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Users-Force-Orders
"""
return self._request_futures_api("get", "forceOrders", signed=True, data=params)
```
Get quantitative trading rules for order placement, such as Unfilled Ratio (UFR), Good-Til-Canceled Ratio (GCR),
Immediate-or-Cancel (IOC) & Fill-or-Kill (FOK) Expire Ratio (IFER), among others.
[https://www.binance.com/en/support/faq/binance-futures-trading-quantitative-rules-4f462ebe6ff445d4a170be7d9e897272](https://www.binance.com/en/support/faq/binance-futures-trading-quantitative-rules-4f462ebe6ff445d4a170be7d9e897272)
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Futures-Trading-Quantitative-Rules-Indicators](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Futures-Trading-Quantitative-Rules-Indicators)
:param symbol: optional
:type symbol: str
:returns: API response
.. code-block:: python
\{
"indicators": \{ // indicator: quantitative rules indicators, value: user's indicators value, triggerValue: trigger indicator value threshold of quantitative rules.
"BTCUSDT": \[
\{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "UFR", // Unfilled Ratio (UFR)
"value": 0.05, // Current value
"triggerValue": 0.995 // Trigger value
},
\{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "IFER", // IOC/FOK Expiration Ratio (IFER)
"value": 0.99, // Current value
"triggerValue": 0.99 // Trigger value
},
\{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "GCR", // GTC Cancellation Ratio (GCR)
"value": 0.99, // Current value
"triggerValue": 0.99 // Trigger value
},
\{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "DR", // Dust Ratio (DR)
"value": 0.99, // Current value
"triggerValue": 0.99 // Trigger value
}
],
"ETHUSDT": \[
\{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "UFR",
"value": 0.05,
"triggerValue": 0.995
},
\{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "IFER",
"value": 0.99,
"triggerValue": 0.99
},
\{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "GCR",
"value": 0.99,
"triggerValue": 0.99
}
\{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "DR",
"value": 0.99,
"triggerValue": 0.99
}
]
},
"updateTime": 1545741270000
}
:raises: BinanceRequestException, BinanceAPIException
```python
def futures_api_trading_status(self, **params):
"""Get quantitative trading rules for order placement, such as Unfilled Ratio (UFR), Good-Til-Canceled Ratio (GCR),
Immediate-or-Cancel (IOC) & Fill-or-Kill (FOK) Expire Ratio (IFER), among others.
https://www.binance.com/en/support/faq/binance-futures-trading-quantitative-rules-4f462ebe6ff445d4a170be7d9e897272
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Futures-Trading-Quantitative-Rules-Indicators
:param symbol: optional
:type symbol: str
:returns: API response
.. code-block:: python
{
"indicators": { // indicator: quantitative rules indicators, value: user's indicators value, triggerValue: trigger indicator value threshold of quantitative rules.
"BTCUSDT": [
{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "UFR", // Unfilled Ratio (UFR)
"value": 0.05, // Current value
"triggerValue": 0.995 // Trigger value
},
{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "IFER", // IOC/FOK Expiration Ratio (IFER)
"value": 0.99, // Current value
"triggerValue": 0.99 // Trigger value
},
{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "GCR", // GTC Cancellation Ratio (GCR)
"value": 0.99, // Current value
"triggerValue": 0.99 // Trigger value
},
{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "DR", // Dust Ratio (DR)
"value": 0.99, // Current value
"triggerValue": 0.99 // Trigger value
}
],
"ETHUSDT": [
{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "UFR",
"value": 0.05,
"triggerValue": 0.995
},
{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "IFER",
"value": 0.99,
"triggerValue": 0.99
},
{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "GCR",
"value": 0.99,
"triggerValue": 0.99
}
{
"isLocked": true,
"plannedRecoverTime": 1545741270000,
"indicator": "DR",
"value": 0.99,
"triggerValue": 0.99
}
]
},
"updateTime": 1545741270000
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_futures_api(
"get", "apiTradingStatus", signed=True, data=params
)
```
Get Futures commission rate
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/User-Commission-Rate](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/User-Commission-Rate)
:param symbol: required
:type symbol: str
:returns: API response
.. code-block:: python
\{
"symbol": "BTCUSDT",
"makerCommissionRate": "0.0002", // 0.02%
"takerCommissionRate": "0.0004" // 0.04%
}
:raises: BinanceRequestException, BinanceAPIException
```python
def futures_commission_rate(self, **params):
"""Get Futures commission rate
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/User-Commission-Rate
:param symbol: required
:type symbol: str
:returns: API response
.. code-block:: python
{
"symbol": "BTCUSDT",
"makerCommissionRate": "0.0002", // 0.02%
"takerCommissionRate": "0.0004" // 0.04%
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_futures_api(
"get", "commissionRate", signed=True, data=params
)
```
Get Position ADL Quantile Estimate
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-ADL-Quantile-Estimation](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-ADL-Quantile-Estimation)
```python
def futures_adl_quantile_estimate(self, **params):
"""Get Position ADL Quantile Estimate
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-ADL-Quantile-Estimation
"""
return self._request_futures_api("get", "adlQuantile", signed=True, data=params)
```
Get present open interest of a specific symbol.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest)
```python
def futures_open_interest(self, **params):
"""Get present open interest of a specific symbol.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest
"""
return self._request_futures_api("get", "openInterest", data=params)
```
Get index\_info
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Composite-Index-Symbol-Information](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Composite-Index-Symbol-Information)
```python
def futures_index_info(self, **params):
"""Get index_info
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Composite-Index-Symbol-Information
"""
return self._request_futures_api("get", "indexInfo", data=params)
```
Get open interest statistics of a specific symbol.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest-Statistics](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest-Statistics)
```python
def futures_open_interest_hist(self, **params):
"""Get open interest statistics of a specific symbol.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Open-Interest-Statistics
"""
return self._request_futures_data_api("get", "openInterestHist", data=params)
```
Notional and Leverage Brackets
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Notional-and-Leverage-Brackets](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Notional-and-Leverage-Brackets)
```python
def futures_leverage_bracket(self, **params):
"""Notional and Leverage Brackets
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Notional-and-Leverage-Brackets
"""
return self._request_futures_api("get", "leverageBracket", True, data=params)
```
Execute transfer between spot account and futures account.
[https://binance-docs.github.io/apidocs/futures/en/#new-future-account-transfer](https://binance-docs.github.io/apidocs/futures/en/#new-future-account-transfer)
```python
def futures_account_transfer(self, **params):
"""Execute transfer between spot account and futures account.
https://binance-docs.github.io/apidocs/futures/en/#new-future-account-transfer
"""
return self._request_margin_api("post", "futures/transfer", True, data=params)
```
Get future account transaction history list
[https://binance-docs.github.io/apidocs/futures/en/#get-future-account-transaction-history-list-user\_data](https://binance-docs.github.io/apidocs/futures/en/#get-future-account-transaction-history-list-user_data)
```python
def transfer_history(self, **params):
"""Get future account transaction history list
https://binance-docs.github.io/apidocs/futures/en/#get-future-account-transaction-history-list-user_data
"""
return self._request_margin_api("get", "futures/transfer", True, data=params)
```
```python
def futures_loan_borrow_history(self, **params):
return self._request_margin_api(
"get", "futures/loan/borrow/history", True, data=params
)
```
```python
def futures_loan_repay_history(self, **params):
return self._request_margin_api(
"get", "futures/loan/repay/history", True, data=params
)
```
```python
def futures_loan_wallet(self, **params):
return self._request_margin_api(
"get", "futures/loan/wallet", True, data=params, version=2
)
```
```python
def futures_cross_collateral_adjust_history(self, **params):
return self._request_margin_api(
"get", "futures/loan/adjustCollateral/history", True, data=params
)
```
```python
def futures_cross_collateral_liquidation_history(self, **params):
return self._request_margin_api(
"get", "futures/loan/liquidationHistory", True, data=params
)
```
```python
def futures_loan_interest_history(self, **params):
return self._request_margin_api(
"get", "futures/loan/interestHistory", True, data=params
)
```
Send in a new order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
Note: After 2025-12-09, conditional order types (STOP, STOP\_MARKET, TAKE\_PROFIT,
TAKE\_PROFIT\_MARKET, TRAILING\_STOP\_MARKET) are automatically routed to the algo
order endpoint.
```python
def futures_create_order(self, **params):
"""Send in a new order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
Note: After 2025-12-09, conditional order types (STOP, STOP_MARKET, TAKE_PROFIT,
TAKE_PROFIT_MARKET, TRAILING_STOP_MARKET) are automatically routed to the algo
order endpoint.
"""
# Check if this is a conditional order type that needs to use algo endpoint
order_type = params.get("type", "").upper()
conditional_types = [
"STOP",
"STOP_MARKET",
"TAKE_PROFIT",
"TAKE_PROFIT_MARKET",
"TRAILING_STOP_MARKET",
]
if order_type in conditional_types:
# Route to algo order endpoint
if "clientAlgoId" not in params:
params["clientAlgoId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
# Remove newClientOrderId if it was added by default
params.pop("newClientOrderId", None)
params["algoType"] = "CONDITIONAL"
# Convert stopPrice to triggerPrice for algo orders (camelCase per API docs)
if "stopPrice" in params and "triggerPrice" not in params:
params["triggerPrice"] = params.pop("stopPrice")
return self._request_futures_api("post", "algoOrder", True, data=params)
else:
# Use regular order endpoint
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures limit order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
def futures_limit_order(self, **params):
"""Send in a new futures limit order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["type"] = "LIMIT"
return self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures market order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
def futures_market_order(self, **params):
"""Send in a new futures market order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["type"] = "MARKET"
return self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures limit buy order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
def futures_limit_buy_order(self, **params):
"""Send in a new futures limit buy order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["side"] = "BUY"
params["type"] = "LIMIT"
return self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures limit sell order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
def futures_limit_sell_order(self, **params):
"""Send in a new futures limit sell order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["side"] = "SELL"
params["type"] = "LIMIT"
return self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures market buy order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
def futures_market_buy_order(self, **params):
"""Send in a new futures market buy order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["side"] = "BUY"
params["type"] = "MARKET"
return self._request_futures_api("post", "order", True, data=params)
```
Send in a new futures market sell order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api)
```python
def futures_market_sell_order(self, **params):
"""Send in a new futures market sell order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
params["side"] = "SELL"
params["type"] = "MARKET"
return self._request_futures_api("post", "order", True, data=params)
```
Modify an existing order. Currently only LIMIT order modification is supported.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Order)
```python
def futures_modify_order(self, **params):
"""Modify an existing order. Currently only LIMIT order modification is supported.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Order
"""
return self._request_futures_api("put", "order", True, data=params)
```
Testing order request, this order will not be submitted to matching engine
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Order-Test](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Order-Test)
```python
def futures_create_test_order(self, **params):
"""Testing order request, this order will not be submitted to matching engine
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Order-Test
"""
return self._request_futures_api("post", "order/test", True, data=params)
```
Send in new orders.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Place-Multiple-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Place-Multiple-Orders)
To avoid modifying the existing signature generation and parameter order logic,
the url encoding is done on the special query param, batchOrders, in the early stage.
```python
def futures_place_batch_order(self, **params):
"""Send in new orders.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Place-Multiple-Orders
To avoid modifying the existing signature generation and parameter order logic,
the url encoding is done on the special query param, batchOrders, in the early stage.
"""
for order in params["batchOrders"]:
if "newClientOrderId" not in order:
order["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
query_string = urlencode(params)
query_string = query_string.replace("%27", "%22")
params["batchOrders"] = query_string[12:]
return self._request_futures_api(
"post", "batchOrders", True, data=params, force_params=True
)
```
Check an order's status.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Order)
:param conditional: optional - Set to True to query algo/conditional order
:type conditional: bool
:param algoId: optional - Algo order ID (for conditional orders)
:type algoId: int
:param clientAlgoId: optional - Client algo order ID (for conditional orders)
:type clientAlgoId: str
```python
def futures_get_order(self, **params):
"""Check an order's status.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Order
:param conditional: optional - Set to True to query algo/conditional order
:type conditional: bool
:param algoId: optional - Algo order ID (for conditional orders)
:type algoId: int
:param clientAlgoId: optional - Client algo order ID (for conditional orders)
:type clientAlgoId: str
"""
# Check if this is a request for a conditional/algo order
is_conditional = params.pop("conditional", False)
# Also check if algoId or clientAlgoId is provided
if "algoId" in params or "clientAlgoId" in params:
is_conditional = True
if is_conditional:
return self._request_futures_api("get", "algoOrder", True, data=params)
else:
return self._request_futures_api("get", "order", True, data=params)
```
Get all open orders on a symbol.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Open-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Open-Orders)
:param conditional: optional - Set to True to query algo/conditional orders
:type conditional: bool
```python
def futures_get_open_orders(self, **params):
"""Get all open orders on a symbol.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Open-Orders
:param conditional: optional - Set to True to query algo/conditional orders
:type conditional: bool
"""
is_conditional = params.pop("conditional", False)
if is_conditional:
return self._request_futures_api("get", "openAlgoOrders", True, data=params)
else:
return self._request_futures_api("get", "openOrders", True, data=params)
```
Get all futures account orders; active, canceled, or filled.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/All-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/All-Orders)
:param conditional: optional - Set to True to query algo/conditional orders
:type conditional: bool
```python
def futures_get_all_orders(self, **params):
"""Get all futures account orders; active, canceled, or filled.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/All-Orders
:param conditional: optional - Set to True to query algo/conditional orders
:type conditional: bool
"""
is_conditional = params.pop("conditional", False)
if is_conditional:
return self._request_futures_api("get", "allAlgoOrders", True, data=params)
else:
return self._request_futures_api("get", "allOrders", True, data=params)
```
Cancel an active futures order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Order)
:param conditional: optional - Set to True to cancel algo/conditional order
:type conditional: bool
:param algoId: optional - Algo order ID (for conditional orders)
:type algoId: int
:param clientAlgoId: optional - Client algo order ID (for conditional orders)
:type clientAlgoId: str
```python
def futures_cancel_order(self, **params):
"""Cancel an active futures order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Order
:param conditional: optional - Set to True to cancel algo/conditional order
:type conditional: bool
:param algoId: optional - Algo order ID (for conditional orders)
:type algoId: int
:param clientAlgoId: optional - Client algo order ID (for conditional orders)
:type clientAlgoId: str
"""
# Check if this is a request for a conditional/algo order
is_conditional = params.pop("conditional", False)
# Also check if algoId or clientAlgoId is provided
if "algoId" in params or "clientAlgoId" in params:
is_conditional = True
if is_conditional:
return self._request_futures_api("delete", "algoOrder", True, data=params)
else:
return self._request_futures_api("delete", "order", True, data=params)
```
Cancel all open futures orders
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Open-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Open-Orders)
:param conditional: optional - Set to True to cancel algo/conditional orders
:type conditional: bool
```python
def futures_cancel_all_open_orders(self, **params):
"""Cancel all open futures orders
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Open-Orders
:param conditional: optional - Set to True to cancel algo/conditional orders
:type conditional: bool
"""
is_conditional = params.pop("conditional", False)
if is_conditional:
return self._request_futures_api(
"delete", "algoOpenOrders", True, data=params
)
else:
return self._request_futures_api("delete", "allOpenOrders", True, data=params)
```
Cancel multiple futures orders
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Multiple-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Multiple-Orders)
```python
def futures_cancel_orders(self, **params):
"""Cancel multiple futures orders
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Multiple-Orders
"""
if params.get("orderidlist"):
params["orderidlist"] = quote(
convert_list_to_json_array(params["orderidlist"])
)
if params.get("origclientorderidlist"):
params["origclientorderidlist"] = quote(
convert_list_to_json_array(params["origclientorderidlist"])
)
return self._request_futures_api(
"delete", "batchOrders", True, force_params=True, data=params
)
```
Cancel all open orders of the specified symbol at the end of the specified countdown.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Auto-Cancel-All-Open-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Auto-Cancel-All-Open-Orders)
:param symbol: required
:type symbol: str
:param countdownTime: required
:type countdownTime: int
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"symbol": "BTCUSDT",
"countdownTime": "100000"
}
```python
def futures_countdown_cancel_all(self, **params):
"""Cancel all open orders of the specified symbol at the end of the specified countdown.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Auto-Cancel-All-Open-Orders
:param symbol: required
:type symbol: str
:param countdownTime: required
:type countdownTime: int
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"symbol": "BTCUSDT",
"countdownTime": "100000"
}
"""
return self._request_futures_api(
"post", "countdownCancelAll", True, data=params
)
```
Send in a new algo order (conditional order).
[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/New-Algo-Order)
:param algoType: required - Only support CONDITIONAL
:type algoType: str
:param symbol: required
:type symbol: str
:param side: required - BUY or SELL
:type side: str
:param positionSide: optional - Default BOTH for One-way Mode; LONG or SHORT for Hedge Mode
:type positionSide: str
:param type: required - STOP\_MARKET/TAKE\_PROFIT\_MARKET/STOP/TAKE\_PROFIT/TRAILING\_STOP\_MARKET
:type type: str
:param timeInForce: optional - IOC or GTC or FOK or GTX, default GTC
:type timeInForce: str
:param quantity: optional - Cannot be sent with closePosition=true
:type quantity: decimal
:param price: optional
:type price: decimal
:param triggerPrice: optional - Used with STOP, STOP\_MARKET, TAKE\_PROFIT, TAKE\_PROFIT\_MARKET
:type triggerPrice: decimal
:param workingType: optional - triggerPrice triggered by: MARK\_PRICE, CONTRACT\_PRICE. Default CONTRACT\_PRICE
:type workingType: str
:param priceMatch: optional - only available for LIMIT/STOP/TAKE\_PROFIT order
:type priceMatch: str
:param closePosition: optional - true, false; Close-All, used with STOP\_MARKET or TAKE\_PROFIT\_MARKET
:type closePosition: str
:param priceProtect: optional - "TRUE" or "FALSE", default "FALSE"
:type priceProtect: str
:param reduceOnly: optional - "true" or "false", default "false"
:type reduceOnly: str
:param activatePrice: optional - Used with TRAILING\_STOP\_MARKET orders
:type activatePrice: decimal
:param callbackRate: optional - Used with TRAILING\_STOP\_MARKET orders, min 0.1, max 10
:type callbackRate: decimal
:param clientAlgoId: optional - A unique id among open orders
:type clientAlgoId: str
:param newOrderRespType: optional - "ACK", "RESULT", default "ACK"
:type newOrderRespType: str
:param selfTradePreventionMode: optional - EXPIRE\_TAKER, EXPIRE\_MAKER, EXPIRE\_BOTH, default NONE
:type selfTradePreventionMode: str
:param goodTillDate: optional - order cancel time for timeInForce GTD
:type goodTillDate: long
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
result = client.futures\_create\_algo\_order(
algoType='CONDITIONAL',
symbol='BNBUSDT',
side='SELL',
type='TAKE\_PROFIT',
quantity='0.01',
price='750.000',
triggerPrice='750.000',
timeInForce='GTC'
)
```python
def futures_create_algo_order(self, **params):
"""Send in a new algo order (conditional order).
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/New-Algo-Order
:param algoType: required - Only support CONDITIONAL
:type algoType: str
:param symbol: required
:type symbol: str
:param side: required - BUY or SELL
:type side: str
:param positionSide: optional - Default BOTH for One-way Mode; LONG or SHORT for Hedge Mode
:type positionSide: str
:param type: required - STOP_MARKET/TAKE_PROFIT_MARKET/STOP/TAKE_PROFIT/TRAILING_STOP_MARKET
:type type: str
:param timeInForce: optional - IOC or GTC or FOK or GTX, default GTC
:type timeInForce: str
:param quantity: optional - Cannot be sent with closePosition=true
:type quantity: decimal
:param price: optional
:type price: decimal
:param triggerPrice: optional - Used with STOP, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET
:type triggerPrice: decimal
:param workingType: optional - triggerPrice triggered by: MARK_PRICE, CONTRACT_PRICE. Default CONTRACT_PRICE
:type workingType: str
:param priceMatch: optional - only available for LIMIT/STOP/TAKE_PROFIT order
:type priceMatch: str
:param closePosition: optional - true, false; Close-All, used with STOP_MARKET or TAKE_PROFIT_MARKET
:type closePosition: str
:param priceProtect: optional - "TRUE" or "FALSE", default "FALSE"
:type priceProtect: str
:param reduceOnly: optional - "true" or "false", default "false"
:type reduceOnly: str
:param activatePrice: optional - Used with TRAILING_STOP_MARKET orders
:type activatePrice: decimal
:param callbackRate: optional - Used with TRAILING_STOP_MARKET orders, min 0.1, max 10
:type callbackRate: decimal
:param clientAlgoId: optional - A unique id among open orders
:type clientAlgoId: str
:param newOrderRespType: optional - "ACK", "RESULT", default "ACK"
:type newOrderRespType: str
:param selfTradePreventionMode: optional - EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH, default NONE
:type selfTradePreventionMode: str
:param goodTillDate: optional - order cancel time for timeInForce GTD
:type goodTillDate: long
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
result = client.futures_create_algo_order(
algoType='CONDITIONAL',
symbol='BNBUSDT',
side='SELL',
type='TAKE_PROFIT',
quantity='0.01',
price='750.000',
triggerPrice='750.000',
timeInForce='GTC'
)
"""
if "clientAlgoId" not in params:
params["clientAlgoId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
if "algoType" not in params:
params["algoType"] = "CONDITIONAL"
return self._request_futures_api("post", "algoOrder", True, data=params)
```
Cancel an active 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/Cancel-Algo-Order)
:param symbol: required
:type symbol: str
:param algoId: optional - Either algoId or clientAlgoId must be sent
:type algoId: int
:param clientAlgoId: optional - Either algoId or clientAlgoId must be sent
:type clientAlgoId: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
```python
def futures_cancel_algo_order(self, **params):
"""Cancel an active algo order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-Algo-Order
:param symbol: required
:type symbol: str
:param algoId: optional - Either algoId or clientAlgoId must be sent
:type algoId: int
:param clientAlgoId: optional - Either algoId or clientAlgoId must be sent
:type clientAlgoId: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
"""
return self._request_futures_api("delete", "algoOrder", True, data=params)
```
Cancel all open algo orders
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Algo-Open-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Algo-Open-Orders)
:param symbol: required
:type symbol: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
```python
def futures_cancel_all_algo_open_orders(self, **params):
"""Cancel all open algo orders
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Cancel-All-Algo-Open-Orders
:param symbol: required
:type symbol: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
"""
return self._request_futures_api(
"delete", "algoOpenOrders", True, data=params
)
```
Check an algo order's status.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Algo-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Algo-Order)
:param symbol: required
:type symbol: str
:param algoId: optional - Either algoId or clientAlgoId must be sent
:type algoId: int
:param clientAlgoId: optional - Either algoId or clientAlgoId must be sent
:type clientAlgoId: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
```python
def futures_get_algo_order(self, **params):
"""Check an algo order's status.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Algo-Order
:param symbol: required
:type symbol: str
:param algoId: optional - Either algoId or clientAlgoId must be sent
:type algoId: int
:param clientAlgoId: optional - Either algoId or clientAlgoId must be sent
:type clientAlgoId: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
"""
return self._request_futures_api("get", "algoOrder", True, data=params)
```
Get all open algo orders on a symbol.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Algo-Open-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Algo-Open-Orders)
:param symbol: optional
:type symbol: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
```python
def futures_get_open_algo_orders(self, **params):
"""Get all open algo orders on a symbol.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Current-All-Algo-Open-Orders
:param symbol: optional
:type symbol: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
"""
return self._request_futures_api("get", "openAlgoOrders", True, data=params)
```
Get all algo account orders; active, canceled, or filled.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-All-Algo-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-All-Algo-Orders)
:param symbol: required
:type symbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional - Default 100; max 100
:type limit: int
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
```python
def futures_get_all_algo_orders(self, **params):
"""Get all algo account orders; active, canceled, or filled.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-All-Algo-Orders
:param symbol: required
:type symbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional - Default 100; max 100
:type limit: int
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
"""
return self._request_futures_api("get", "allAlgoOrders", True, data=params)
```
Get futures account balance
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Futures-Account-Balance-V3](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Futures-Account-Balance-V3)
```python
def futures_account_balance(self, **params):
"""Get futures account balance
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Futures-Account-Balance-V3
"""
return self._request_futures_api("get", "balance", True, 3, data=params)
```
Get current account information.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V2](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V2)
```python
def futures_account(self, **params):
"""Get current account information.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Information-V2
"""
return self._request_futures_api("get", "account", True, 2, data=params)
```
Query the symbol-level ADL (Auto-Deleveraging) risk rating
The ADL risk rating measures the likelihood of ADL during liquidation.
Rating can be: high, medium, low. Updated every 30 minutes.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Query-ADL-Risk-Rating](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Query-ADL-Risk-Rating)
:param symbol: optional - if not provided, returns ADL risk for all symbols
:type symbol: str
:returns: API response
.. code-block:: python
Single symbol [#single-symbol]
\{
"symbol": "BTCUSDT",
"adlRisk": "low",
"updateTime": 1597370495002
}
All symbols (when symbol not provided) [#all-symbols-when-symbol-not-provided]
\[
\{
"symbol": "BTCUSDT",
"adlRisk": "low",
"updateTime": 1597370495002
},
\{
"symbol": "ETHUSDT",
"adlRisk": "high",
"updateTime": 1597370495004
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def futures_symbol_adl_risk(self, **params):
"""Query the symbol-level ADL (Auto-Deleveraging) risk rating
The ADL risk rating measures the likelihood of ADL during liquidation.
Rating can be: high, medium, low. Updated every 30 minutes.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Query-ADL-Risk-Rating
:param symbol: optional - if not provided, returns ADL risk for all symbols
:type symbol: str
:returns: API response
.. code-block:: python
# Single symbol
{
"symbol": "BTCUSDT",
"adlRisk": "low",
"updateTime": 1597370495002
}
# All symbols (when symbol not provided)
[
{
"symbol": "BTCUSDT",
"adlRisk": "low",
"updateTime": 1597370495002
},
{
"symbol": "ETHUSDT",
"adlRisk": "high",
"updateTime": 1597370495004
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_futures_api("get", "symbolAdlRisk", True, data=params)
```
Change user's initial leverage of specific symbol market
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Initial-Leverage](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Initial-Leverage)
```python
def futures_change_leverage(self, **params):
"""Change user's initial leverage of specific symbol market
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Initial-Leverage
"""
return self._request_futures_api("post", "leverage", True, data=params)
```
Change the margin type for a symbol
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Margin-Type](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Margin-Type)
```python
def futures_change_margin_type(self, **params):
"""Change the margin type for a symbol
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Margin-Type
"""
return self._request_futures_api("post", "marginType", True, data=params)
```
Change the position margin for a symbol
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin)
```python
def futures_change_position_margin(self, **params):
"""Change the position margin for a symbol
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin
"""
return self._request_futures_api("post", "positionMargin", True, data=params)
```
Get position margin change history
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Get-Position-Margin-Change-History](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Get-Position-Margin-Change-History)
```python
def futures_position_margin_history(self, **params):
"""Get position margin change history
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Get-Position-Margin-Change-History
"""
return self._request_futures_api(
"get", "positionMargin/history", True, data=params
)
```
Get position information
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-Information-V3](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-Information-V3)
```python
def futures_position_information(self, **params):
"""Get position information
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Position-Information-V3
"""
return self._request_futures_api("get", "positionRisk", True, 3, data=params)
```
Get trades for the authenticated account and symbol.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Account-Trade-List](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Account-Trade-List)
```python
def futures_account_trades(self, **params):
"""Get trades for the authenticated account and symbol.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Account-Trade-List
"""
return self._request_futures_api("get", "userTrades", True, data=params)
```
Get income history for authenticated account
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Income-History](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Income-History)
```python
def futures_income_history(self, **params):
"""Get income history for authenticated account
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Income-History
"""
return self._request_futures_api("get", "income", True, data=params)
```
Change position mode for authenticated account
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Position-Mode](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Position-Mode)
```python
def futures_change_position_mode(self, **params):
"""Change position mode for authenticated account
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Position-Mode
"""
return self._request_futures_api("post", "positionSide/dual", True, data=params)
```
Get position mode for authenticated account
[https://binance-docs.github.io/apidocs/futures/en/#get-current-position-mode-user\_data](https://binance-docs.github.io/apidocs/futures/en/#get-current-position-mode-user_data)
```python
def futures_get_position_mode(self, **params):
"""Get position mode for authenticated account
https://binance-docs.github.io/apidocs/futures/en/#get-current-position-mode-user_data
"""
return self._request_futures_api("get", "positionSide/dual", True, data=params)
```
Change user's Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on Every symbol
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Multi-Assets-Mode](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Multi-Assets-Mode)
```python
def futures_change_multi_assets_mode(self, multiAssetsMargin: bool):
"""Change user's Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on Every symbol
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Change-Multi-Assets-Mode
"""
params = {"multiAssetsMargin": "true" if multiAssetsMargin else "false"}
return self._request_futures_api("post", "multiAssetsMargin", True, data=params)
```
Get user's Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on Every symbol
[https://binance-docs.github.io/apidocs/futures/en/#get-current-multi-assets-mode-user\_data](https://binance-docs.github.io/apidocs/futures/en/#get-current-multi-assets-mode-user_data)
```python
def futures_get_multi_assets_mode(self):
"""Get user's Multi-Assets mode (Multi-Assets Mode or Single-Asset Mode) on Every symbol
https://binance-docs.github.io/apidocs/futures/en/#get-current-multi-assets-mode-user_data
"""
return self._request_futures_api("get", "multiAssetsMargin", True, data={})
```
```python
def futures_stream_get_listen_key(self):
res = self._request_futures_api("post", "listenKey", signed=False, data={})
return res["listenKey"]
```
```python
def futures_stream_keepalive(self, listenKey):
params = {"listenKey": listenKey}
return self._request_futures_api("put", "listenKey", signed=False, data=params)
```
```python
def futures_stream_close(self, listenKey):
params = {"listenKey": listenKey}
return self._request_futures_api(
"delete", "listenKey", signed=False, data=params
)
```
Get futures account configuration
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Config](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Config)
```python
def futures_account_config(self, **params):
"""Get futures account configuration
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Account-Config
"""
return self._request_futures_api(
"get", "accountConfig", signed=True, version=1, data=params
)
```
Get current account symbol configuration
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Symbol-Config](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Symbol-Config)
```python
def futures_symbol_config(self, **params):
"""Get current account symbol configuration
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Symbol-Config
"""
return self._request_futures_api(
"get", "symbolConfig", signed=True, version=1, data=params
)
```
Test connectivity to the Rest API
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api)
```python
def futures_coin_ping(self):
"""Test connectivity to the Rest API
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api
"""
return self._request_futures_coin_api("get", "ping")
```
Test connectivity to the Rest API and get the current server time.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Check-Server-time](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Check-Server-time)
```python
def futures_coin_time(self):
"""Test connectivity to the Rest API and get the current server time.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Check-Server-time
"""
return self._request_futures_coin_api("get", "time")
```
Current exchange trading rules and symbol information
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Exchange-Information](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Exchange-Information)
```python
def futures_coin_exchange_info(self):
"""Current exchange trading rules and symbol information
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Exchange-Information
"""
return self._request_futures_coin_api("get", "exchangeInfo")
```
Get the Order Book for the market
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Order-Book](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Order-Book)
```python
def futures_coin_order_book(self, **params):
"""Get the Order Book for the market
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Order-Book
"""
return self._request_futures_coin_api("get", "depth", data=params)
```
Get recent trades (up to last 500).
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Recent-Trades-List](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Recent-Trades-List)
```python
def futures_coin_recent_trades(self, **params):
"""Get recent trades (up to last 500).
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Recent-Trades-List
"""
return self._request_futures_coin_api("get", "trades", data=params)
```
Get older market historical trades.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Old-Trades-Lookup](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Old-Trades-Lookup)
```python
def futures_coin_historical_trades(self, **params):
"""Get older market historical trades.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Old-Trades-Lookup
"""
return self._request_futures_coin_api("get", "historicalTrades", data=params)
```
Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same
price will have the quantity aggregated.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Compressed-Aggregate-Trades-List](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Compressed-Aggregate-Trades-List)
```python
def futures_coin_aggregate_trades(self, **params):
"""Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same
price will have the quantity aggregated.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Compressed-Aggregate-Trades-List
"""
return self._request_futures_coin_api("get", "aggTrades", data=params)
```
Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data)
```python
def futures_coin_klines(self, **params):
"""Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Kline-Candlestick-Data
"""
return self._request_futures_coin_api("get", "klines", data=params)
```
Kline/candlestick bars for a specific contract type. Klines are uniquely identified by their open time.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Continuous-Contract-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Continuous-Contract-Kline-Candlestick-Data)
```python
def futures_coin_continous_klines(self, **params):
"""Kline/candlestick bars for a specific contract type. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Continuous-Contract-Kline-Candlestick-Data
"""
return self._request_futures_coin_api("get", "continuousKlines", data=params)
```
Kline/candlestick bars for the index price of a pair..
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data)
```python
def futures_coin_index_price_klines(self, **params):
"""Kline/candlestick bars for the index price of a pair..
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-Kline-Candlestick-Data
"""
return self._request_futures_coin_api("get", "indexPriceKlines", data=params)
```
Kline/candlestick bars for the index price of a pair..
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data)
```python
def futures_coin_premium_index_klines(self, **params):
"""Kline/candlestick bars for the index price of a pair..
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Premium-Index-Kline-Data
"""
return self._request_futures_coin_api("get", "premiumIndexKlines", data=params)
```
Kline/candlestick bars for the index price of a pair..
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data)
```python
def futures_coin_mark_price_klines(self, **params):
"""Kline/candlestick bars for the index price of a pair..
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Mark-Price-Kline-Candlestick-Data
"""
return self._request_futures_coin_api("get", "markPriceKlines", data=params)
```
Get Mark Price and Funding Rate
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-and-Mark-Price](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-and-Mark-Price)
```python
def futures_coin_mark_price(self, **params):
"""Get Mark Price and Funding Rate
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Price-and-Mark-Price
"""
return self._request_futures_coin_api("get", "premiumIndex", data=params)
```
Get funding rate history
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Rate-History-of-Perpetual-Futures](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Rate-History-of-Perpetual-Futures)
```python
def futures_coin_funding_rate(self, **params):
"""Get funding rate history
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Rate-History-of-Perpetual-Futures
"""
return self._request_futures_coin_api("get", "fundingRate", data=params)
```
24 hour rolling window price change statistics.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics)
```python
def futures_coin_ticker(self, **params):
"""24 hour rolling window price change statistics.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/24hr-Ticker-Price-Change-Statistics
"""
return self._request_futures_coin_api("get", "ticker/24hr", data=params)
```
Latest price for a symbol or symbols.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Symbol-Price-Ticker](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Symbol-Price-Ticker)
```python
def futures_coin_symbol_ticker(self, **params):
"""Latest price for a symbol or symbols.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Symbol-Price-Ticker
"""
return self._request_futures_coin_api("get", "ticker/price", data=params)
```
Best price/qty on the order book for a symbol or symbols.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker)
```python
def futures_coin_orderbook_ticker(self, **params):
"""Best price/qty on the order book for a symbol or symbols.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Symbol-Order-Book-Ticker
"""
return self._request_futures_coin_api("get", "ticker/bookTicker", data=params)
```
Get present long to short ratio for top positions of a specific symbol.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Top-Trader-Long-Short-Ratio](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Top-Trader-Long-Short-Ratio)
```python
def futures_coin_top_longshort_position_ratio(self, **params):
"""Get present long to short ratio for top positions of a specific symbol.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Top-Trader-Long-Short-Ratio
"""
return self._request_futures_coin_data_api("get", "topLongShortPositionRatio", data=params)
```
Get present long to short ratio for top positions of a specific symbol.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Top-Long-Short-Account-Ratio](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Top-Long-Short-Account-Ratio)
```python
def futures_coin_top_longshort_account_ratio(self, **params):
"""Get present long to short ratio for top positions of a specific symbol.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Top-Long-Short-Account-Ratio
"""
return self._request_futures_coin_data_api("get", "topLongShortAccountRatio", data=params)
```
Get present long to short ratio for top positions of a specific symbol.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Long-Short-Ratio](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Long-Short-Ratio)
```python
def futures_coin_global_longshort_ratio(self, **params):
"""Get present long to short ratio for top positions of a specific symbol.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Long-Short-Ratio
"""
return self._request_futures_coin_data_api("get", "globalLongShortAccountRatio", data=params)
```
Get present long to short ratio for top positions of a specific symbol.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Taker-Buy-Sell-Volume](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Taker-Buy-Sell-Volume)
```python
def futures_coin_taker_buy_sell_volume(self, **params):
"""Get present long to short ratio for top positions of a specific symbol.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Taker-Buy-Sell-Volume
"""
return self._request_futures_coin_data_api("get", "takerBuySellVol", data=params)
```
Get future basis of a specific symbol
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Basis](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Basis)
```python
def futures_coin_basis(self, **params):
"""Get future basis of a specific symbol
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Basis
"""
return self._request_futures_coin_data_api("get", "basis", data=params)
```
Get index price constituents
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Constituents](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Constituents)
```python
def futures_coin_index_price_constituents(self, **params):
"""Get index price constituents
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Index-Constituents
"""
return self._request_futures_coin_api("get", "constituents", data=params)
```
Get all liquidation orders
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Users-Force-Orders](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Users-Force-Orders)
```python
def futures_coin_liquidation_orders(self, **params):
"""Get all liquidation orders
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Users-Force-Orders
"""
return self._request_futures_coin_api(
"get", "forceOrders", signed=True, data=params
)
```
Get present open interest of a specific symbol.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest)
```python
def futures_coin_open_interest(self, **params):
"""Get present open interest of a specific symbol.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest
"""
return self._request_futures_coin_api("get", "openInterest", data=params)
```
Get open interest statistics of a specific symbol.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest-Statistics](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest-Statistics)
```python
def futures_coin_open_interest_hist(self, **params):
"""Get open interest statistics of a specific symbol.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Open-Interest-Statistics
"""
return self._request_futures_coin_data_api(
"get", "openInterestHist", data=params
)
```
Notional and Leverage Brackets
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Notional-Bracket-for-Symbol](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Notional-Bracket-for-Symbol)
```python
def futures_coin_leverage_bracket(self, **params):
"""Notional and Leverage Brackets
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Notional-Bracket-for-Symbol
"""
return self._request_futures_coin_api(
"get", "leverageBracket", version=2, signed=True, data=params
)
```
Get future account transaction history list
[https://developers.binance.com/docs/wallet/asset/query-user-universal-transfer](https://developers.binance.com/docs/wallet/asset/query-user-universal-transfer)
```python
def new_transfer_history(self, **params):
"""Get future account transaction history list
https://developers.binance.com/docs/wallet/asset/query-user-universal-transfer
"""
return self._request_margin_api("get", "asset/transfer", True, data=params)
```
Query Funding Wallet
[https://developers.binance.com/docs/wallet/asset/funding-wallet](https://developers.binance.com/docs/wallet/asset/funding-wallet)
```python
def funding_wallet(self, **params):
""" Query Funding Wallet
https://developers.binance.com/docs/wallet/asset/funding-wallet
"""
return self._request_margin_api(
"post", "asset/get-funding-asset", True, data=params
)
```
Get user assets, just for positive data
[https://developers.binance.com/docs/wallet/asset/user-assets](https://developers.binance.com/docs/wallet/asset/user-assets)
```python
def get_user_asset(self, **params):
""" Get user assets, just for positive data
https://developers.binance.com/docs/wallet/asset/user-assets
"""
return self._request_margin_api(
"post", "asset/getUserAsset", True, data=params, version=3
)
```
Unviversal transfer api accross different binance account types
[https://developers.binance.com/docs/wallet/asset/user-universal-transfer](https://developers.binance.com/docs/wallet/asset/user-universal-transfer)
```python
def universal_transfer(self, **params):
"""Unviversal transfer api accross different binance account types
https://developers.binance.com/docs/wallet/asset/user-universal-transfer
"""
return self._request_margin_api(
"post", "asset/transfer", signed=True, data=params
)
```
Send in a new order.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api)
```python
def futures_coin_create_order(self, **params):
"""Send in a new order.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._request_futures_coin_api("post", "order", True, data=params)
```
Send in new orders.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Place-Multiple-Orders](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Place-Multiple-Orders)
To avoid modifying the existing signature generation and parameter order logic,
the url encoding is done on the special query param, batchOrders, in the early stage.
```python
def futures_coin_place_batch_order(self, **params):
"""Send in new orders.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Place-Multiple-Orders
To avoid modifying the existing signature generation and parameter order logic,
the url encoding is done on the special query param, batchOrders, in the early stage.
"""
for order in params["batchOrders"]:
if "newClientOrderId" not in order:
order["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
query_string = urlencode(params)
query_string = query_string.replace("%27", "%22")
params["batchOrders"] = query_string[12:]
return self._request_futures_coin_api("post", "batchOrders", True, data=params)
```
Modify an existing order. Currently only LIMIT order modification is supported.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Order](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Order)
```python
def futures_coin_modify_order(self, **params):
"""Modify an existing order. Currently only LIMIT order modification is supported.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Order
"""
return self._request_futures_coin_api("put", "order", True, data=params)
```
Check an order's status.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Query-Order](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Query-Order)
```python
def futures_coin_get_order(self, **params):
"""Check an order's status.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Query-Order
"""
return self._request_futures_coin_api("get", "order", True, data=params)
```
Get all open orders on a symbol.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Current-All-Open-Orders](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Current-All-Open-Orders)
```python
def futures_coin_get_open_orders(self, **params):
"""Get all open orders on a symbol.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Current-All-Open-Orders
"""
return self._request_futures_coin_api("get", "openOrders", True, data=params)
```
Get all futures account orders; active, canceled, or filled.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/All-Orders](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/All-Orders)
```python
def futures_coin_get_all_orders(self, **params):
"""Get all futures account orders; active, canceled, or filled.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/All-Orders
"""
return self._request_futures_coin_api(
"get", "allOrders", signed=True, data=params
)
```
Cancel an active futures order.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-Order](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-Order)
```python
def futures_coin_cancel_order(self, **params):
"""Cancel an active futures order.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-Order
"""
return self._request_futures_coin_api(
"delete", "order", signed=True, data=params
)
```
Cancel all open futures orders
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-All-Open-Orders](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-All-Open-Orders)
```python
def futures_coin_cancel_all_open_orders(self, **params):
"""Cancel all open futures orders
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-All-Open-Orders
"""
return self._request_futures_coin_api(
"delete", "allOpenOrders", signed=True, force_params=True, data=params
)
```
Cancel multiple futures orders
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-Multiple-Orders](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-Multiple-Orders)
```python
def futures_coin_cancel_orders(self, **params):
"""Cancel multiple futures orders
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Cancel-Multiple-Orders
"""
if params.get("orderidlist"):
params["orderidlist"] = quote(
convert_list_to_json_array(params["orderidlist"])
)
if params.get("origclientOrderidlist"):
params["origclientorderidlist"] = quote(
convert_list_to_json_array(params["origclientorderidlist"])
)
return self._request_futures_coin_api(
"delete", "batchOrders", True, data=params
)
```
Cancel all open orders of the specified symbol at the end of the specified countdown.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Auto-Cancel-All-Open-Orders](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Auto-Cancel-All-Open-Orders)
:param symbol: required
:type symbol: str
:param countdownTime: required
:type countdownTime: int
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"symbol": "BTCUSDT",
"countdownTime": "100000"
}
```python
def futures_coin_countdown_cancel_all(self, **params):
"""Cancel all open orders of the specified symbol at the end of the specified countdown.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Auto-Cancel-All-Open-Orders
:param symbol: required
:type symbol: str
:param countdownTime: required
:type countdownTime: int
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"symbol": "BTCUSDT",
"countdownTime": "100000"
}
"""
return self._request_futures_coin_api(
"post", "countdownCancelAll", True, data=params
)
```
Get current open order.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Query-Current-Open-Order](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Query-Current-Open-Order)
```python
def futures_coin_get_open_order(self, **params):
"""Get current open order.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Query-Current-Open-Order
"""
return self._request_futures_coin_api(
"get", "openOrder", signed=True, data=params
)
```
Get futures account balance
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Futures-Account-Balance](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Futures-Account-Balance)
```python
def futures_coin_account_balance(self, **params):
"""Get futures account balance
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Futures-Account-Balance
"""
return self._request_futures_coin_api(
"get", "balance", signed=True, data=params
)
```
Get current account information.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information)
```python
def futures_coin_account(self, **params):
"""Get current account information.
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Account-Information
"""
return self._request_futures_coin_api(
"get", "account", signed=True, data=params
)
```
Change user's initial leverage of specific symbol market
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Initial-Leverage](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Initial-Leverage)
```python
def futures_coin_change_leverage(self, **params):
"""Change user's initial leverage of specific symbol market
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Initial-Leverage
"""
return self._request_futures_coin_api(
"post", "leverage", signed=True, data=params
)
```
Change the margin type for a symbol
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Margin-Type](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Margin-Type)
```python
def futures_coin_change_margin_type(self, **params):
"""Change the margin type for a symbol
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Margin-Type
"""
return self._request_futures_coin_api(
"post", "marginType", signed=True, data=params
)
```
Change the position margin for a symbol
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin)
```python
def futures_coin_change_position_margin(self, **params):
"""Change the position margin for a symbol
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Isolated-Position-Margin
"""
return self._request_futures_coin_api(
"post", "positionMargin", True, data=params
)
```
Get position margin change history
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Get-Position-Margin-Change-History](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Get-Position-Margin-Change-History)
```python
def futures_coin_position_margin_history(self, **params):
"""Get position margin change history
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Get-Position-Margin-Change-History
"""
return self._request_futures_coin_api(
"get", "positionMargin/history", True, data=params
)
```
Get position information
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-Information](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-Information)
```python
def futures_coin_position_information(self, **params):
"""Get position information
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-Information
"""
return self._request_futures_coin_api("get", "positionRisk", True, data=params)
```
Get trades for the authenticated account and symbol.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Account-Trade-List](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Account-Trade-List)
```python
def futures_coin_account_trades(self, **params):
"""Get trades for the authenticated account and symbol.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Account-Trade-List
"""
return self._request_futures_coin_api("get", "userTrades", True, data=params)
```
Get income history for authenticated account
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Income-History](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Income-History)
```python
def futures_coin_income_history(self, **params):
"""Get income history for authenticated account
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Income-History
"""
return self._request_futures_coin_api("get", "income", True, data=params)
```
Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Position-Mode](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Position-Mode)
```python
def futures_coin_change_position_mode(self, **params):
"""Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Change-Position-Mode
"""
return self._request_futures_coin_api(
"post", "positionSide/dual", True, data=params
)
```
Get user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Current-Position-Mode](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Current-Position-Mode)
```python
def futures_coin_get_position_mode(self, **params):
"""Get user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Current-Position-Mode
"""
return self._request_futures_coin_api(
"get", "positionSide/dual", True, data=params
)
```
```python
def futures_coin_stream_get_listen_key(self):
res = self._request_futures_coin_api("post", "listenKey", signed=False, data={})
return res["listenKey"]
```
```python
def futures_coin_stream_keepalive(self, listenKey):
params = {"listenKey": listenKey}
return self._request_futures_coin_api(
"put", "listenKey", signed=False, data=params
)
```
```python
def futures_coin_stream_close(self, listenKey):
params = {"listenKey": listenKey}
return self._request_futures_coin_api(
"delete", "listenKey", signed=False, data=params
)
```
Get Download Id For Futures Order History
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Order-History](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Order-History)
:param startTime: required - Start timestamp in ms
:type startTime: int
:param endTime: required - End timestamp in ms
:type endTime: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"avgCostTimestampOfLast30d": 7241837, # Average time taken for data download in the past 30 days
"downloadId": "546975389218332672"
}
Note:
* Request Limitation is 10 times per month, shared by front end download page and rest api
* The time between startTime and endTime can not be longer than 1 year
:raises: BinanceRequestException, BinanceAPIException
```python
def futures_coin_account_order_history_download(self, **params):
"""Get Download Id For Futures Order History
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Order-History
:param startTime: required - Start timestamp in ms
:type startTime: int
:param endTime: required - End timestamp in ms
:type endTime: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"avgCostTimestampOfLast30d": 7241837, # Average time taken for data download in the past 30 days
"downloadId": "546975389218332672"
}
Note:
- Request Limitation is 10 times per month, shared by front end download page and rest api
- The time between startTime and endTime can not be longer than 1 year
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_futures_coin_api(
"get", "order/asyn", signed=True, data=params
)
```
Get futures order history download link by Id
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Order-History-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Order-History-Download-Link-by-Id)
:param downloadId: required - Download ID obtained from futures\_coin\_download\_id
:type downloadId: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"downloadId": "545923594199212032",
"status": "completed", # Enum:completed,processing
"url": "[www.binance.com](http://www.binance.com)", # The link is mapped to download id
"notified": true, # ignore
"expirationTimestamp": 1645009771000, # The link would expire after this timestamp
"isExpired": null
}
OR (Response when server is processing) [#or-response-when-server-is-processing]
\{
"downloadId": "545923594199212032",
"status": "processing",
"url": "",
"notified": false,
"expirationTimestamp": -1,
"isExpired": null
}
Note:
* Download link expiration: 24h
:raises: BinanceRequestException, BinanceAPIException
```python
def futures_coin_accout_order_history_download_link(self, **params):
"""Get futures order history download link by Id
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Order-History-Download-Link-by-Id
:param downloadId: required - Download ID obtained from futures_coin_download_id
:type downloadId: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"downloadId": "545923594199212032",
"status": "completed", # Enum:completed,processing
"url": "www.binance.com", # The link is mapped to download id
"notified": true, # ignore
"expirationTimestamp": 1645009771000, # The link would expire after this timestamp
"isExpired": null
}
# OR (Response when server is processing)
{
"downloadId": "545923594199212032",
"status": "processing",
"url": "",
"notified": false,
"expirationTimestamp": -1,
"isExpired": null
}
Note:
- Download link expiration: 24h
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_futures_coin_api("get", "order/asyn/id", True, data=params)
```
Get Download Id For Futures Trade History (USER\_DATA)
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Trade-History](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Trade-History)
:param startTime: required - Start timestamp in ms
:type startTime: int
:param endTime: required - End timestamp in ms
:type endTime: int
:returns: API response
.. code-block:: python
\{
"avgCostTimestampOfLast30d": 7241837, # Average time taken for data download in the past 30 days
"downloadId": "546975389218332672"
}
Note:
* Request Limitation is 5 times per month, shared by front end download page and rest api
* The time between startTime and endTime can not be longer than 1 year
:raises: BinanceRequestException, BinanceAPIException
```python
def futures_coin_account_trade_history_download(self, **params):
"""Get Download Id For Futures Trade History (USER_DATA)
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Trade-History
:param startTime: required - Start timestamp in ms
:type startTime: int
:param endTime: required - End timestamp in ms
:type endTime: int
:returns: API response
.. code-block:: python
{
"avgCostTimestampOfLast30d": 7241837, # Average time taken for data download in the past 30 days
"downloadId": "546975389218332672"
}
Note:
- Request Limitation is 5 times per month, shared by front end download page and rest api
- The time between startTime and endTime can not be longer than 1 year
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_futures_coin_api("get", "trade/asyn", True, data=params)
```
Get futures trade download link by Id
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Trade-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Trade-Download-Link-by-Id)
:param downloadId: required - Download ID obtained from futures\_coin\_trade\_download\_id
:type downloadId: str
:returns: API response
.. code-block:: python
\{
"downloadId": "545923594199212032",
"status": "completed", # Enum:completed,processing
"url": "[www.binance.com](http://www.binance.com)", # The link is mapped to download id
"notified": true, # ignore
"expirationTimestamp": 1645009771000, # The link would expire after this timestamp
"isExpired": null
}
OR (Response when server is processing) [#or-response-when-server-is-processing-1]
\{
"downloadId": "545923594199212032",
"status": "processing",
"url": "",
"notified": false,
"expirationTimestamp": -1,
"isExpired": null
}
Note:
* Download link expiration: 24h
:raises: BinanceRequestException, BinanceAPIException
```python
def futures_coin_account_trade_history_download_link(self, **params):
"""Get futures trade download link by Id
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Trade-Download-Link-by-Id
:param downloadId: required - Download ID obtained from futures_coin_trade_download_id
:type downloadId: str
:returns: API response
.. code-block:: python
{
"downloadId": "545923594199212032",
"status": "completed", # Enum:completed,processing
"url": "www.binance.com", # The link is mapped to download id
"notified": true, # ignore
"expirationTimestamp": 1645009771000, # The link would expire after this timestamp
"isExpired": null
}
# OR (Response when server is processing)
{
"downloadId": "545923594199212032",
"status": "processing",
"url": "",
"notified": false,
"expirationTimestamp": -1,
"isExpired": null
}
Note:
- Download link expiration: 24h
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_futures_coin_api("get", "trade/asyn/id", True, data=params)
```
Get information of coins (available for deposit and withdraw) for user.
[https://developers.binance.com/docs/wallet/capital](https://developers.binance.com/docs/wallet/capital)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"coin": "BTC",
"depositAllEnable": true,
"withdrawAllEnable": true,
"name": "Bitcoin",
"free": "0",
"locked": "0",
"freeze": "0",
"withdrawing": "0",
"ipoing": "0",
"ipoable": "0",
"storage": "0",
"isLegalMoney": false,
"trading": true,
"networkList": \[
\{
"network": "BNB",
"coin": "BTC",
"withdrawIntegerMultiple": "0.00000001",
"isDefault": false,
"depositEnable": true,
"withdrawEnable": true,
"depositDesc": "",
"withdrawDesc": "",
"specialTips": "Both a MEMO and an Address are required to successfully deposit your BEP2-BTCB tokens to Binance.",
"name": "BEP2",
"resetAddressStatus": false,
"addressRegex": "^(bnb1)\[0-9a-z]\{38}$",
"memoRegex": "^\[0-9A-Za-z-\_]\{1,120}$",
"withdrawFee": "0.0000026",
"withdrawMin": "0.0000052",
"withdrawMax": "0",
"minConfirm": 1,
"unLockConfirm": 0
},
\{
"network": "BTC",
"coin": "BTC",
"withdrawIntegerMultiple": "0.00000001",
"isDefault": true,
"depositEnable": true,
"withdrawEnable": true,
"depositDesc": "",
"withdrawDesc": "",
"specialTips": "",
"name": "BTC",
"resetAddressStatus": false,
"addressRegex": "^\[13]\[a-km-zA-HJ-NP-Z1-9]\{25,34}$|^(bc1)\[0-9A-Za-z]\{39,59}$",
"memoRegex": "",
"withdrawFee": "0.0005",
"withdrawMin": "0.001",
"withdrawMax": "0",
"minConfirm": 1,
"unLockConfirm": 2
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_all_coins_info(self, **params):
"""Get information of coins (available for deposit and withdraw) for user.
https://developers.binance.com/docs/wallet/capital
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"coin": "BTC",
"depositAllEnable": true,
"withdrawAllEnable": true,
"name": "Bitcoin",
"free": "0",
"locked": "0",
"freeze": "0",
"withdrawing": "0",
"ipoing": "0",
"ipoable": "0",
"storage": "0",
"isLegalMoney": false,
"trading": true,
"networkList": [
{
"network": "BNB",
"coin": "BTC",
"withdrawIntegerMultiple": "0.00000001",
"isDefault": false,
"depositEnable": true,
"withdrawEnable": true,
"depositDesc": "",
"withdrawDesc": "",
"specialTips": "Both a MEMO and an Address are required to successfully deposit your BEP2-BTCB tokens to Binance.",
"name": "BEP2",
"resetAddressStatus": false,
"addressRegex": "^(bnb1)[0-9a-z]{38}$",
"memoRegex": "^[0-9A-Za-z-_]{1,120}$",
"withdrawFee": "0.0000026",
"withdrawMin": "0.0000052",
"withdrawMax": "0",
"minConfirm": 1,
"unLockConfirm": 0
},
{
"network": "BTC",
"coin": "BTC",
"withdrawIntegerMultiple": "0.00000001",
"isDefault": true,
"depositEnable": true,
"withdrawEnable": true,
"depositDesc": "",
"withdrawDesc": "",
"specialTips": "",
"name": "BTC",
"resetAddressStatus": false,
"addressRegex": "^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$|^(bc1)[0-9A-Za-z]{39,59}$",
"memoRegex": "",
"withdrawFee": "0.0005",
"withdrawMin": "0.001",
"withdrawMax": "0",
"minConfirm": 1,
"unLockConfirm": 2
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"get", "capital/config/getall", True, data=params
)
```
Get daily account snapshot of specific type.
[https://developers.binance.com/docs/wallet/account/daily-account-snapshoot](https://developers.binance.com/docs/wallet/account/daily-account-snapshoot)
:param type: required. Valid values are SPOT/MARGIN/FUTURES.
:type type: string
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"code":200, // 200 for success; others are error codes
"msg":"", // error message
"snapshotVos":\[
\{
"data":\{
"balances":\[
\{
"asset":"BTC",
"free":"0.09905021",
"locked":"0.00000000"
},
\{
"asset":"USDT",
"free":"1.89109409",
"locked":"0.00000000"
}
],
"totalAssetOfBtc":"0.09942700"
},
"type":"spot",
"updateTime":1576281599000
}
]
}
OR
.. code-block:: python
\{
"code":200, // 200 for success; others are error codes
"msg":"", // error message
"snapshotVos":\[
\{
"data":\{
"marginLevel":"2748.02909813",
"totalAssetOfBtc":"0.00274803",
"totalLiabilityOfBtc":"0.00000100",
"totalNetAssetOfBtc":"0.00274750",
"userAssets":\[
\{
"asset":"XRP",
"borrowed":"0.00000000",
"free":"1.00000000",
"interest":"0.00000000",
"locked":"0.00000000",
"netAsset":"1.00000000"
}
]
},
"type":"margin",
"updateTime":1576281599000
}
]
}
OR
.. code-block:: python
\{
"code":200, // 200 for success; others are error codes
"msg":"", // error message
"snapshotVos":\[
\{
"data":\{
"assets":\[
\{
"asset":"USDT",
"marginBalance":"118.99782335",
"walletBalance":"120.23811389"
}
],
"position":\[
\{
"entryPrice":"7130.41000000",
"markPrice":"7257.66239673",
"positionAmt":"0.01000000",
"symbol":"BTCUSDT",
"unRealizedProfit":"1.24029054"
}
]
},
"type":"futures",
"updateTime":1576281599000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def get_account_snapshot(self, **params):
"""Get daily account snapshot of specific type.
https://developers.binance.com/docs/wallet/account/daily-account-snapshoot
:param type: required. Valid values are SPOT/MARGIN/FUTURES.
:type type: string
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"code":200, // 200 for success; others are error codes
"msg":"", // error message
"snapshotVos":[
{
"data":{
"balances":[
{
"asset":"BTC",
"free":"0.09905021",
"locked":"0.00000000"
},
{
"asset":"USDT",
"free":"1.89109409",
"locked":"0.00000000"
}
],
"totalAssetOfBtc":"0.09942700"
},
"type":"spot",
"updateTime":1576281599000
}
]
}
OR
.. code-block:: python
{
"code":200, // 200 for success; others are error codes
"msg":"", // error message
"snapshotVos":[
{
"data":{
"marginLevel":"2748.02909813",
"totalAssetOfBtc":"0.00274803",
"totalLiabilityOfBtc":"0.00000100",
"totalNetAssetOfBtc":"0.00274750",
"userAssets":[
{
"asset":"XRP",
"borrowed":"0.00000000",
"free":"1.00000000",
"interest":"0.00000000",
"locked":"0.00000000",
"netAsset":"1.00000000"
}
]
},
"type":"margin",
"updateTime":1576281599000
}
]
}
OR
.. code-block:: python
{
"code":200, // 200 for success; others are error codes
"msg":"", // error message
"snapshotVos":[
{
"data":{
"assets":[
{
"asset":"USDT",
"marginBalance":"118.99782335",
"walletBalance":"120.23811389"
}
],
"position":[
{
"entryPrice":"7130.41000000",
"markPrice":"7257.66239673",
"positionAmt":"0.01000000",
"symbol":"BTCUSDT",
"unRealizedProfit":"1.24029054"
}
]
},
"type":"futures",
"updateTime":1576281599000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api("get", "accountSnapshot", True, data=params)
```
Disable Fast Withdraw Switch
[https://binance-docs.github.io/apidocs/spot/en/#disable-fast-withdraw-switch-user\_data](https://binance-docs.github.io/apidocs/spot/en/#disable-fast-withdraw-switch-user_data)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
:raises: BinanceRequestException, BinanceAPIException
```python
def disable_fast_withdraw_switch(self, **params):
"""Disable Fast Withdraw Switch
https://binance-docs.github.io/apidocs/spot/en/#disable-fast-withdraw-switch-user_data
:param recvWindow: optional
:type recvWindow: int
:returns: API response
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "disableFastWithdrawSwitch", True, data=params
)
```
Enable Fast Withdraw Switch
[https://binance-docs.github.io/apidocs/spot/en/#enable-fast-withdraw-switch-user\_data](https://binance-docs.github.io/apidocs/spot/en/#enable-fast-withdraw-switch-user_data)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
:raises: BinanceRequestException, BinanceAPIException
```python
def enable_fast_withdraw_switch(self, **params):
"""Enable Fast Withdraw Switch
https://binance-docs.github.io/apidocs/spot/en/#enable-fast-withdraw-switch-user_data
:param recvWindow: optional
:type recvWindow: int
:returns: API response
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api(
"post", "enableFastWithdrawSwitch", True, data=params
)
```
Test connectivity
[https://developers.binance.com/docs/derivatives/option/market-data/Test-Connectivity](https://developers.binance.com/docs/derivatives/option/market-data/Test-Connectivity)
```python
def options_ping(self):
"""Test connectivity
https://developers.binance.com/docs/derivatives/option/market-data/Test-Connectivity
"""
return self._request_options_api("get", "ping")
```
Get server time
[https://developers.binance.com/docs/derivatives/option/market-data](https://developers.binance.com/docs/derivatives/option/market-data)
```python
def options_time(self):
"""Get server time
https://developers.binance.com/docs/derivatives/option/market-data
"""
return self._request_options_api("get", "time")
```
Get current trading pair info
[https://binance-docs.github.io/apidocs/voptions/en/#get-current-trading-pair-info](https://binance-docs.github.io/apidocs/voptions/en/#get-current-trading-pair-info)
```python
def options_info(self):
"""Get current trading pair info
https://binance-docs.github.io/apidocs/voptions/en/#get-current-trading-pair-info
"""
return self._request_options_api("get", "optionInfo")
```
Get current limit info and trading pair info
[https://developers.binance.com/docs/derivatives/option/market-data/Exchange-Information](https://developers.binance.com/docs/derivatives/option/market-data/Exchange-Information)
```python
def options_exchange_info(self):
"""Get current limit info and trading pair info
https://developers.binance.com/docs/derivatives/option/market-data/Exchange-Information
"""
return self._request_options_api("get", "exchangeInfo")
```
Get the spot index price
[https://developers.binance.com/docs/derivatives/option/market-data/Symbol-Price-Ticker](https://developers.binance.com/docs/derivatives/option/market-data/Symbol-Price-Ticker)
:param underlying: required - Spot pair(Option contract underlying asset)- BTCUSDT
:type underlying: str
```python
def options_index_price(self, **params):
"""Get the spot index price
https://developers.binance.com/docs/derivatives/option/market-data/Symbol-Price-Ticker
:param underlying: required - Spot pair(Option contract underlying asset)- BTCUSDT
:type underlying: str
"""
return self._request_options_api("get", "index", data=params)
```
Get the latest price
[https://developers.binance.com/docs/derivatives/option/market-data/24hr-Ticker-Price-Change-Statistics](https://developers.binance.com/docs/derivatives/option/market-data/24hr-Ticker-Price-Change-Statistics)
:param symbol: optional - Option trading pair - BTC-200730-9000-C
:type symbol: str
```python
def options_price(self, **params):
"""Get the latest price
https://developers.binance.com/docs/derivatives/option/market-data/24hr-Ticker-Price-Change-Statistics
:param symbol: optional - Option trading pair - BTC-200730-9000-C
:type symbol: str
"""
return self._request_options_api("get", "ticker", data=params)
```
Get the latest mark price
[https://developers.binance.com/docs/derivatives/option/market-data/Option-Mark-Price](https://developers.binance.com/docs/derivatives/option/market-data/Option-Mark-Price)
:param symbol: optional - Option trading pair - BTC-200730-9000-C
:type symbol: str
```python
def options_mark_price(self, **params):
"""Get the latest mark price
https://developers.binance.com/docs/derivatives/option/market-data/Option-Mark-Price
:param symbol: optional - Option trading pair - BTC-200730-9000-C
:type symbol: str
"""
return self._request_options_api("get", "mark", data=params)
```
Depth information
[https://developers.binance.com/docs/derivatives/option/market-data/Order-Book](https://developers.binance.com/docs/derivatives/option/market-data/Order-Book)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param limit: optional - Default:100 Max:1000.Optional value:\[10, 20, 50, 100, 500, 1000] - 100
:type limit: int
```python
def options_order_book(self, **params):
"""Depth information
https://developers.binance.com/docs/derivatives/option/market-data/Order-Book
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param limit: optional - Default:100 Max:1000.Optional value:[10, 20, 50, 100, 500, 1000] - 100
:type limit: int
"""
return self._request_options_api("get", "depth", data=params)
```
Candle data
[https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data](https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param interval: required - Time interval - 5m
:type interval: str
:param startTime: optional - Start Time - 1592317127349
:type startTime: int
:param endTime: optional - End Time - 1592317127349
:type endTime: int
:param limit: optional - Number of records Default:500 Max:1500 - 500
:type limit: int
```python
def options_klines(self, **params):
"""Candle data
https://developers.binance.com/docs/derivatives/option/market-data/Kline-Candlestick-Data
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param interval: required - Time interval - 5m
:type interval: str
:param startTime: optional - Start Time - 1592317127349
:type startTime: int
:param endTime: optional - End Time - 1592317127349
:type endTime: int
:param limit: optional - Number of records Default:500 Max:1500 - 500
:type limit: int
"""
return self._request_options_api("get", "klines", data=params)
```
Recently completed Option trades
[https://developers.binance.com/docs/derivatives/option/market-data/Recent-Trades-List](https://developers.binance.com/docs/derivatives/option/market-data/Recent-Trades-List)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param limit: optional - Number of records Default:100 Max:500 - 100
:type limit: int
```python
def options_recent_trades(self, **params):
"""Recently completed Option trades
https://developers.binance.com/docs/derivatives/option/market-data/Recent-Trades-List
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param limit: optional - Number of records Default:100 Max:500 - 100
:type limit: int
"""
return self._request_options_api("get", "trades", data=params)
```
Query trade history
[https://developers.binance.com/docs/derivatives/option/market-data/Old-Trades-Lookup](https://developers.binance.com/docs/derivatives/option/market-data/Old-Trades-Lookup)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param fromId: optional - The deal ID from which to return. The latest deal record is returned by default - 1592317127349
:type fromId: int
:param limit: optional - Number of records Default:100 Max:500 - 100
:type limit: int
```python
def options_historical_trades(self, **params):
"""Query trade history
https://developers.binance.com/docs/derivatives/option/market-data/Old-Trades-Lookup
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param fromId: optional - The deal ID from which to return. The latest deal record is returned by default - 1592317127349
:type fromId: int
:param limit: optional - Number of records Default:100 Max:500 - 100
:type limit: int
"""
return self._request_options_api("get", "historicalTrades", data=params)
```
Account asset info (USER\_DATA)
[https://developers.binance.com/docs/derivatives/option/account](https://developers.binance.com/docs/derivatives/option/account)
:param recvWindow: optional
:type recvWindow: int
```python
def options_account_info(self, **params):
"""Account asset info (USER_DATA)
https://developers.binance.com/docs/derivatives/option/account
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("get", "account", signed=True, data=params)
```
Get account funding flows
[https://developers.binance.com/docs/derivatives/option/account/Account-Funding-Flow](https://developers.binance.com/docs/derivatives/option/account/Account-Funding-Flow)
:param currency: required
:type currency: str
:param recordId: optional
:type recordId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def options_get_bill(self, **params):
"""Get account funding flows
https://developers.binance.com/docs/derivatives/option/account/Account-Funding-Flow
:param currency: required
:type currency: str
:param recordId: optional
:type recordId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_options_api("get", "bill", signed=True, data=params)
```
Funds transfer (USER\_DATA)
[https://binance-docs.github.io/apidocs/voptions/en/#funds-transfer-user\_data](https://binance-docs.github.io/apidocs/voptions/en/#funds-transfer-user_data)
:param currency: required - Asset type - USDT
:type currency: str
:param type: required - IN: Transfer from spot account to option account OUT: Transfer from option account to spot account - IN
:type type: str (ENUM)
:param amount: required - Amount - 10000
:type amount: float
:param recvWindow: optional
:type recvWindow: int
```python
def options_funds_transfer(self, **params):
"""Funds transfer (USER_DATA)
https://binance-docs.github.io/apidocs/voptions/en/#funds-transfer-user_data
:param currency: required - Asset type - USDT
:type currency: str
:param type: required - IN: Transfer from spot account to option account OUT: Transfer from option account to spot account - IN
:type type: str (ENUM)
:param amount: required - Amount - 10000
:type amount: float
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("post", "transfer", signed=True, data=params)
```
Option holdings info (USER\_DATA)
[https://developers.binance.com/docs/derivatives/option/trade/Option-Position-Information](https://developers.binance.com/docs/derivatives/option/trade/Option-Position-Information)
:param symbol: optional - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
```python
def options_positions(self, **params):
"""Option holdings info (USER_DATA)
https://developers.binance.com/docs/derivatives/option/trade/Option-Position-Information
:param symbol: optional - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("get", "position", signed=True, data=params)
```
Get account exercise records.
[https://developers.binance.com/docs/derivatives/option/trade/User-Exercise-Record](https://developers.binance.com/docs/derivatives/option/trade/User-Exercise-Record)
:param symbol: optional
:type symbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def options_exercise_record(self, **params):
"""
Get account exercise records.
https://developers.binance.com/docs/derivatives/option/trade/User-Exercise-Record
:param symbol: optional
:type symbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_options_api("get", "exerciseRecord", signed=True, data=params)
```
Account funding flow (USER\_DATA)
[https://binance-docs.github.io/apidocs/voptions/en/#account-funding-flow-user\_data](https://binance-docs.github.io/apidocs/voptions/en/#account-funding-flow-user_data)
:param currency: required - Asset type - USDT
:type currency: str
:param recordId: optional - Return the recordId and subsequent data, the latest data is returned by default - 100000
:type recordId: int
:param startTime: optional - Start Time - 1593511200000
:type startTime: int
:param endTime: optional - End Time - 1593511200000
:type endTime: int
:param limit: optional - Number of result sets returned Default:100 Max:1000 - 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
```python
def options_bill(self, **params):
"""Account funding flow (USER_DATA)
https://binance-docs.github.io/apidocs/voptions/en/#account-funding-flow-user_data
:param currency: required - Asset type - USDT
:type currency: str
:param recordId: optional - Return the recordId and subsequent data, the latest data is returned by default - 100000
:type recordId: int
:param startTime: optional - Start Time - 1593511200000
:type startTime: int
:param endTime: optional - End Time - 1593511200000
:type endTime: int
:param limit: optional - Number of result sets returned Default:100 Max:1000 - 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("post", "bill", signed=True, data=params)
```
Option order (TRADE)
[https://developers.binance.com/docs/derivatives/option/trade](https://developers.binance.com/docs/derivatives/option/trade)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param side: required - Buy/sell direction: SELL, BUY - BUY
:type side: str (ENUM)
:param type: required - Order Type: LIMIT, MARKET - LIMIT
:type type: str (ENUM)
:param quantity: required - Order Quantity - 3
:type quantity: float
:param price: optional - Order Price - 1000
:type price: float
:param timeInForce: optional - Time in force method(Default GTC) - GTC
:type timeInForce: str (ENUM)
:param reduceOnly: optional - Reduce Only (Default false) - false
:type reduceOnly: bool
:param postOnly: optional - Post Only (Default false) - false
:type postOnly: bool
:param newOrderRespType: optional - "ACK", "RESULT", Default "ACK" - ACK
:type newOrderRespType: str (ENUM)
:param clientOrderId: optional - User-defined order ID cannot be repeated in pending orders - 10000
:type clientOrderId: str
:param recvWindow: optional
:type recvWindow: int
```python
def options_place_order(self, **params):
"""Option order (TRADE)
https://developers.binance.com/docs/derivatives/option/trade
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param side: required - Buy/sell direction: SELL, BUY - BUY
:type side: str (ENUM)
:param type: required - Order Type: LIMIT, MARKET - LIMIT
:type type: str (ENUM)
:param quantity: required - Order Quantity - 3
:type quantity: float
:param price: optional - Order Price - 1000
:type price: float
:param timeInForce: optional - Time in force method(Default GTC) - GTC
:type timeInForce: str (ENUM)
:param reduceOnly: optional - Reduce Only (Default false) - false
:type reduceOnly: bool
:param postOnly: optional - Post Only (Default false) - false
:type postOnly: bool
:param newOrderRespType: optional - "ACK", "RESULT", Default "ACK" - ACK
:type newOrderRespType: str (ENUM)
:param clientOrderId: optional - User-defined order ID cannot be repeated in pending orders - 10000
:type clientOrderId: str
:param recvWindow: optional
:type recvWindow: int
"""
if "clientOrderId" not in params:
params["clientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._request_options_api("post", "order", signed=True, data=params)
```
Place Multiple Option orders (TRADE)
[https://developers.binance.com/docs/derivatives/option/trade/Place-Multiple-Orders](https://developers.binance.com/docs/derivatives/option/trade/Place-Multiple-Orders)
:param orders: required - order list. Max 5 orders - \[\{"symbol":"BTC-210115-35000-C","price":"100","quantity":"0.0001","side":"BUY","type":"LIMIT"}]
:type orders: list
:param recvWindow: optional
:type recvWindow: int
```python
def options_place_batch_order(self, **params):
"""Place Multiple Option orders (TRADE)
https://developers.binance.com/docs/derivatives/option/trade/Place-Multiple-Orders
:param orders: required - order list. Max 5 orders - [{"symbol":"BTC-210115-35000-C","price":"100","quantity":"0.0001","side":"BUY","type":"LIMIT"}]
:type orders: list
:param recvWindow: optional
:type recvWindow: int
"""
for order in params["batchOrders"]:
if "newClientOrderId" not in order:
order["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._request_options_api(
"post", "batchOrders", signed=True, data=params
)
```
Cancel Option order (TRADE)
[https://developers.binance.com/docs/derivatives/option/trade/Cancel-Option-Order](https://developers.binance.com/docs/derivatives/option/trade/Cancel-Option-Order)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderId: optional - Order ID - 4611875134427365377
:type orderId: str
:param clientOrderId: optional - User-defined order ID - 10000
:type clientOrderId: str
:param recvWindow: optional
:type recvWindow: int
```python
def options_cancel_order(self, **params):
"""Cancel Option order (TRADE)
https://developers.binance.com/docs/derivatives/option/trade/Cancel-Option-Order
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderId: optional - Order ID - 4611875134427365377
:type orderId: str
:param clientOrderId: optional - User-defined order ID - 10000
:type clientOrderId: str
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("delete", "order", signed=True, data=params)
```
Cancel Multiple Option orders (TRADE)
[https://developers.binance.com/docs/derivatives/option/trade/Cancel-Multiple-Option-Orders](https://developers.binance.com/docs/derivatives/option/trade/Cancel-Multiple-Option-Orders)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderIds: optional - Order ID - \[4611875134427365377,4611875134427365378]
:type orderId: list
:param clientOrderIds: optional - User-defined order ID - \["my\_id\_1","my\_id\_2"]
:type clientOrderIds: list
:param recvWindow: optional
:type recvWindow: int
```python
def options_cancel_batch_order(self, **params):
"""Cancel Multiple Option orders (TRADE)
https://developers.binance.com/docs/derivatives/option/trade/Cancel-Multiple-Option-Orders
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderIds: optional - Order ID - [4611875134427365377,4611875134427365378]
:type orderId: list
:param clientOrderIds: optional - User-defined order ID - ["my_id_1","my_id_2"]
:type clientOrderIds: list
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api(
"delete", "batchOrders", signed=True, data=params
)
```
Cancel all Option orders (TRADE)
[https://developers.binance.com/docs/derivatives/option/trade/Cancel-all-Option-orders-on-specific-symbol](https://developers.binance.com/docs/derivatives/option/trade/Cancel-all-Option-orders-on-specific-symbol)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
```python
def options_cancel_all_orders(self, **params):
"""Cancel all Option orders (TRADE)
https://developers.binance.com/docs/derivatives/option/trade/Cancel-all-Option-orders-on-specific-symbol
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api(
"delete", "allOpenOrders", signed=True, data=params
)
```
Query Option order (TRADE)
[https://developers.binance.com/docs/derivatives/option/trade/Query-Single-Order](https://developers.binance.com/docs/derivatives/option/trade/Query-Single-Order)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderId: optional - Order ID - 4611875134427365377
:type orderId: str
:param clientOrderId: optional - User-defined order ID - 10000
:type clientOrderId: str
:param recvWindow: optional
:type recvWindow: int
```python
def options_query_order(self, **params):
"""Query Option order (TRADE)
https://developers.binance.com/docs/derivatives/option/trade/Query-Single-Order
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderId: optional - Order ID - 4611875134427365377
:type orderId: str
:param clientOrderId: optional - User-defined order ID - 10000
:type clientOrderId: str
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("get", "order", signed=True, data=params)
```
Query current pending Option orders (TRADE)
[https://developers.binance.com/docs/derivatives/option/trade/Query-Current-Open-Option-Orders](https://developers.binance.com/docs/derivatives/option/trade/Query-Current-Open-Option-Orders)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderId: optional - Returns the orderId and subsequent orders, the most recent order is returned by default - 100000
:type orderId: str
:param startTime: optional - Start Time - 1593511200000
:type startTime: int
:param endTime: optional - End Time - 1593511200000
:type endTime: int
:param limit: optional - Number of result sets returned Default:100 Max:1000 - 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
```python
def options_query_pending_orders(self, **params):
"""Query current pending Option orders (TRADE)
https://developers.binance.com/docs/derivatives/option/trade/Query-Current-Open-Option-Orders
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderId: optional - Returns the orderId and subsequent orders, the most recent order is returned by default - 100000
:type orderId: str
:param startTime: optional - Start Time - 1593511200000
:type startTime: int
:param endTime: optional - End Time - 1593511200000
:type endTime: int
:param limit: optional - Number of result sets returned Default:100 Max:1000 - 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("get", "openOrders", signed=True, data=params)
```
Query Option order history (TRADE)
[https://developers.binance.com/docs/derivatives/option/trade/Query-Option-Order-History](https://developers.binance.com/docs/derivatives/option/trade/Query-Option-Order-History)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderId: optional - Returns the orderId and subsequent orders, the most recent order is returned by default - 100000
:type orderId: str
:param startTime: optional - Start Time - 1593511200000
:type startTime: int
:param endTime: optional - End Time - 1593511200000
:type endTime: int
:param limit: optional - Number of result sets returned Default:100 Max:1000 - 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
```python
def options_query_order_history(self, **params):
"""Query Option order history (TRADE)
https://developers.binance.com/docs/derivatives/option/trade/Query-Option-Order-History
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param orderId: optional - Returns the orderId and subsequent orders, the most recent order is returned by default - 100000
:type orderId: str
:param startTime: optional - Start Time - 1593511200000
:type startTime: int
:param endTime: optional - End Time - 1593511200000
:type endTime: int
:param limit: optional - Number of result sets returned Default:100 Max:1000 - 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api(
"get", "historyOrders", signed=True, data=params
)
```
Option Trade List (USER\_DATA)
[https://developers.binance.com/docs/derivatives/option/trade/Account-Trade-List](https://developers.binance.com/docs/derivatives/option/trade/Account-Trade-List)
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param fromId: optional - Trade id to fetch from. Default gets most recent trades. - 4611875134427365376
:type fromId: int
:param startTime: optional - Start Time - 1593511200000
:type startTime: int
:param endTime: optional - End Time - 1593511200000
:type endTime: int
:param limit: optional - Number of result sets returned Default:100 Max:1000 - 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
```python
def options_user_trades(self, **params):
"""Option Trade List (USER_DATA)
https://developers.binance.com/docs/derivatives/option/trade/Account-Trade-List
:param symbol: required - Option trading pair - BTC-200730-9000-C
:type symbol: str
:param fromId: optional - Trade id to fetch from. Default gets most recent trades. - 4611875134427365376
:type fromId: int
:param startTime: optional - Start Time - 1593511200000
:type startTime: int
:param endTime: optional - End Time - 1593511200000
:type endTime: int
:param limit: optional - Number of result sets returned Default:100 Max:1000 - 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("get", "userTrades", signed=True, data=params)
```
New Block Trade Order (TRADE)
[https://developers.binance.com/docs/derivatives/option/market-maker-block-trade](https://developers.binance.com/docs/derivatives/option/market-maker-block-trade)
:param liquidity: required - Taker or Maker
:type liquidity: str
:param symbol: required - Option trading pair, e.g BTC-200730-9000-C
:type symbol: str
:param side: required - BUY or SELL
:type side: str
:param price: required - Order Price
:type price: float
:param quantity: required - Order Quantity
:type quantity: float
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"blockTradeSettlementKey": "3668822b8-1baa-6a2f-adb8-d3de6289b361",
"expireTime": 1730171888109,
"liquidity": "TAKER",
"status": "RECEIVED",
"legs": \[
\{
"symbol": "BNB-241101-700-C",
"side": "BUY",
"quantity": "1.2",
"price": "2.8"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def options_create_block_trade_order(self, **params):
"""New Block Trade Order (TRADE)
https://developers.binance.com/docs/derivatives/option/market-maker-block-trade
:param liquidity: required - Taker or Maker
:type liquidity: str
:param symbol: required - Option trading pair, e.g BTC-200730-9000-C
:type symbol: str
:param side: required - BUY or SELL
:type side: str
:param price: required - Order Price
:type price: float
:param quantity: required - Order Quantity
:type quantity: float
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"blockTradeSettlementKey": "3668822b8-1baa-6a2f-adb8-d3de6289b361",
"expireTime": 1730171888109,
"liquidity": "TAKER",
"status": "RECEIVED",
"legs": [
{
"symbol": "BNB-241101-700-C",
"side": "BUY",
"quantity": "1.2",
"price": "2.8"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_options_api(
"post", "block/order/create", signed=True, data=params
)
```
Cancel Block Trade Order (TRADE)
[https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Cancel-Block-Trade-Order](https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Cancel-Block-Trade-Order)
:param blockOrderMatchingKey: required - Block Order Matching Key
:type blockOrderMatchingKey: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
\{}
:raises: BinanceRequestException, BinanceAPIException
```python
def options_cancel_block_trade_order(self, **params):
"""Cancel Block Trade Order (TRADE)
https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Cancel-Block-Trade-Order
:param blockOrderMatchingKey: required - Block Order Matching Key
:type blockOrderMatchingKey: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
{}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_options_api(
"delete", "block/order/create", signed=True, data=params
)
```
Extend Block Trade Order (TRADE)
Extends a block trade expire time by 30 mins from the current time.
[https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Extend-Block-Trade-Order](https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Extend-Block-Trade-Order)
:param blockOrderMatchingKey: required - Block Order Matching Key
:type blockOrderMatchingKey: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"blockTradeSettlementKey": "3668822b8-1baa-6a2f-adb8-d3de6289b361",
"expireTime": 1730172007000,
"liquidity": "TAKER",
"status": "RECEIVED",
"createTime": 1730170088111,
"legs": \[
\{
"symbol": "BNB-241101-700-C",
"side": "BUY",
"quantity": "1.2",
"price": "2.8"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def options_extend_block_trade_order(self, **params):
"""Extend Block Trade Order (TRADE)
Extends a block trade expire time by 30 mins from the current time.
https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Extend-Block-Trade-Order
:param blockOrderMatchingKey: required - Block Order Matching Key
:type blockOrderMatchingKey: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"blockTradeSettlementKey": "3668822b8-1baa-6a2f-adb8-d3de6289b361",
"expireTime": 1730172007000,
"liquidity": "TAKER",
"status": "RECEIVED",
"createTime": 1730170088111,
"legs": [
{
"symbol": "BNB-241101-700-C",
"side": "BUY",
"quantity": "1.2",
"price": "2.8"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_options_api(
"put", "block/order/create", signed=True, data=params
)
```
Query Block Trade Order (TRADE)
Check block trade order status.
[https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Query-Block-Trade-Order](https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Query-Block-Trade-Order)
:param blockOrderMatchingKey: optional - Returns specific block trade for this key
:type blockOrderMatchingKey: str
:param endTime: optional
:type endTime: int
:param startTime: optional
:type startTime: int
:param underlying: optional
:type underlying: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"blockTradeSettlementKey": "7d046e6e-a429-4335-ab9d-6a681febcde5",
"expireTime": 1730172115801,
"liquidity": "TAKER",
"status": "RECEIVED",
"createTime": 1730170315803,
"legs": \[
\{
"symbol": "BNB-241101-700-C",
"side": "BUY",
"quantity": "1.2",
"price": "2.8"
}
]
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def options_get_block_trade_orders(self, **params):
"""Query Block Trade Order (TRADE)
Check block trade order status.
https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Query-Block-Trade-Order
:param blockOrderMatchingKey: optional - Returns specific block trade for this key
:type blockOrderMatchingKey: str
:param endTime: optional
:type endTime: int
:param startTime: optional
:type startTime: int
:param underlying: optional
:type underlying: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"blockTradeSettlementKey": "7d046e6e-a429-4335-ab9d-6a681febcde5",
"expireTime": 1730172115801,
"liquidity": "TAKER",
"status": "RECEIVED",
"createTime": 1730170315803,
"legs": [
{
"symbol": "BNB-241101-700-C",
"side": "BUY",
"quantity": "1.2",
"price": "2.8"
}
]
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_options_api(
"get", "block/order/orders", signed=True, data=params
)
```
Accept Block Trade Order (TRADE)
Accept a block trade order.
[https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Accept-Block-Trade-Order](https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Accept-Block-Trade-Order)
:param blockOrderMatchingKey: required - Block Order Matching Key
:type blockOrderMatchingKey: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"blockTradeSettlementKey": "7d046e6e-a429-4335-ab9d-6a681febcde5",
"expireTime": 1730172115801,
"liquidity": "MAKER",
"status": "ACCEPTED",
"createTime": 1730170315803,
"legs": \[
\{
"symbol": "BNB-241101-700-C",
"side": "SELL",
"quantity": "1.2",
"price": "2.8"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def options_accept_block_trade_order(self, **params):
"""Accept Block Trade Order (TRADE)
Accept a block trade order.
https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Accept-Block-Trade-Order
:param blockOrderMatchingKey: required - Block Order Matching Key
:type blockOrderMatchingKey: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"blockTradeSettlementKey": "7d046e6e-a429-4335-ab9d-6a681febcde5",
"expireTime": 1730172115801,
"liquidity": "MAKER",
"status": "ACCEPTED",
"createTime": 1730170315803,
"legs": [
{
"symbol": "BNB-241101-700-C",
"side": "SELL",
"quantity": "1.2",
"price": "2.8"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_options_api(
"post", "block/order/execute", signed=True, data=params
)
```
Query Block Trade Details (USER\_DATA)
Query block trade details; returns block trade details from counterparty's perspective.
[https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Query-Block-Trade-Detail](https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Query-Block-Trade-Detail)
:param blockOrderMatchingKey: required - Block Order Matching Key
:type blockOrderMatchingKey: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
\{
"blockTradeSettlementKey": "12b96c28-ba05-8906-c89t-703215cfb2e6",
"expireTime": 1730171860460,
"liquidity": "MAKER",
"status": "RECEIVED",
"createTime": 1730170060462,
"legs": \[
\{
"symbol": "BNB-241101-700-C",
"side": "SELL",
"quantity": "1.66",
"price": "20"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def options_get_block_trade_order(self, **params):
"""Query Block Trade Details (USER_DATA)
Query block trade details; returns block trade details from counterparty's perspective.
https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Query-Block-Trade-Detail
:param blockOrderMatchingKey: required - Block Order Matching Key
:type blockOrderMatchingKey: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"blockTradeSettlementKey": "12b96c28-ba05-8906-c89t-703215cfb2e6",
"expireTime": 1730171860460,
"liquidity": "MAKER",
"status": "RECEIVED",
"createTime": 1730170060462,
"legs": [
{
"symbol": "BNB-241101-700-C",
"side": "SELL",
"quantity": "1.66",
"price": "20"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_options_api(
"get", "block/order/execute", signed=True, data=params
)
```
Account Block Trade List (USER\_DATA)
Gets block trades for a specific account.
[https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Account-Block-Trade-List](https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Account-Block-Trade-List)
:param endTime: optional
:type endTime: int
:param startTime: optional
:type startTime: int
:param underlying: optional
:type underlying: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
\[
\{
"parentOrderId": "4675011431944499201",
"crossType": "USER\_BLOCK",
"legs": \[
\{
"createTime": 1730170445600,
"updateTime": 1730170445600,
"symbol": "BNB-241101-700-C",
"orderId": "4675011431944499203",
"orderPrice": 2.8,
"orderQuantity": 1.2,
"orderStatus": "FILLED",
"executedQty": 1.2,
"executedAmount": 3.36,
"fee": 0.336,
"orderType": "PREV\_QUOTED",
"orderSide": "BUY",
"id": "1125899906900937837",
"tradeId": 1,
"tradePrice": 2.8,
"tradeQty": 1.2,
"tradeTime": 1730170445600,
"liquidity": "TAKER",
"commission": 0.336
}
],
"blockTradeSettlementKey": "7d085e6e-a229-2335-ab9d-6a581febcd25"
}
]
:raises: BinanceRequestException, BinanceAPIException
```python
def options_account_get_block_trades(self, **params):
"""Account Block Trade List (USER_DATA)
Gets block trades for a specific account.
https://developers.binance.com/docs/derivatives/option/market-maker-block-trade/Account-Block-Trade-List
:param endTime: optional
:type endTime: int
:param startTime: optional
:type startTime: int
:param underlying: optional
:type underlying: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
.. code-block:: python
[
{
"parentOrderId": "4675011431944499201",
"crossType": "USER_BLOCK",
"legs": [
{
"createTime": 1730170445600,
"updateTime": 1730170445600,
"symbol": "BNB-241101-700-C",
"orderId": "4675011431944499203",
"orderPrice": 2.8,
"orderQuantity": 1.2,
"orderStatus": "FILLED",
"executedQty": 1.2,
"executedAmount": 3.36,
"fee": 0.336,
"orderType": "PREV_QUOTED",
"orderSide": "BUY",
"id": "1125899906900937837",
"tradeId": 1,
"tradePrice": 2.8,
"tradeQty": 1.2,
"tradeTime": 1730170445600,
"liquidity": "TAKER",
"commission": 0.336
}
],
"blockTradeSettlementKey": "7d085e6e-a229-2335-ab9d-6a581febcd25"
}
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_options_api(
"get", "block/user-trades", signed=True, data=params
)
```
Get Fiat Deposit/Withdraw History
[https://binance-docs.github.io/apidocs/spot/en/#get-fiat-deposit-withdraw-history-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-fiat-deposit-withdraw-history-user_data)
:param transactionType: required - 0-deposit,1-withdraw
:type transactionType: str
:param beginTime: optional
:type beginTime: int
:param endTime: optional
:type endTime: int
:param page: optional - default 1
:type page: int
:param rows: optional - default 100, max 500
:type rows: int
:param recvWindow: optional
:type recvWindow: int
```python
def get_fiat_deposit_withdraw_history(self, **params):
"""Get Fiat Deposit/Withdraw History
https://binance-docs.github.io/apidocs/spot/en/#get-fiat-deposit-withdraw-history-user_data
:param transactionType: required - 0-deposit,1-withdraw
:type transactionType: str
:param beginTime: optional
:type beginTime: int
:param endTime: optional
:type endTime: int
:param page: optional - default 1
:type page: int
:param rows: optional - default 100, max 500
:type rows: int
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_margin_api("get", "fiat/orders", signed=True, data=params)
```
Get Fiat Payments History
[https://binance-docs.github.io/apidocs/spot/en/#get-fiat-payments-history-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-fiat-payments-history-user_data)
:param transactionType: required - 0-buy,1-sell
:type transactionType: str
:param beginTime: optional
:type beginTime: int
:param endTime: optional
:type endTime: int
:param page: optional - default 1
:type page: int
:param rows: optional - default 100, max 500
:type rows: int
:param recvWindow: optional
:type recvWindow: int
```python
def get_fiat_payments_history(self, **params):
"""Get Fiat Payments History
https://binance-docs.github.io/apidocs/spot/en/#get-fiat-payments-history-user_data
:param transactionType: required - 0-buy,1-sell
:type transactionType: str
:param beginTime: optional
:type beginTime: int
:param endTime: optional
:type endTime: int
:param page: optional - default 1
:type page: int
:param rows: optional - default 100, max 500
:type rows: int
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_margin_api(
"get", "fiat/payments", signed=True, data=params
)
```
Get C2C Trade History
[https://binance-docs.github.io/apidocs/spot/en/#get-c2c-trade-history-user\_data](https://binance-docs.github.io/apidocs/spot/en/#get-c2c-trade-history-user_data)
:param tradeType: required - BUY, SELL
:type tradeType: str
:param startTimestamp: optional
:type startTime: int
:param endTimestamp: optional
:type endTimestamp: int
:param page: optional - default 1
:type page: int
:param rows: optional - default 100, max 100
:type rows: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
\{
"code": "000000",
"message": "success",
"data": \[
\{
"orderNumber":"20219644646554779648",
"advNo": "11218246497340923904",
"tradeType": "SELL",
"asset": "BUSD",
"fiat": "CNY",
"fiatSymbol": "¥",
"amount": "5000.00000000", // Quantity (in Crypto)
"totalPrice": "33400.00000000",
"unitPrice": "6.68", // Unit Price (in Fiat)
"orderStatus": "COMPLETED", // PENDING, TRADING, BUYER\_PAYED, DISTRIBUTING, COMPLETED, IN\_APPEAL, CANCELLED, CANCELLED\_BY\_SYSTEM
"createTime": 1619361369000,
"commission": "0", // Transaction Fee (in Crypto)
"counterPartNickName": "ab\*\*\*",
"advertisementRole": "TAKER"
}
],
"total": 1,
"success": true
}
```python
def get_c2c_trade_history(self, **params):
"""Get C2C Trade History
https://binance-docs.github.io/apidocs/spot/en/#get-c2c-trade-history-user_data
:param tradeType: required - BUY, SELL
:type tradeType: str
:param startTimestamp: optional
:type startTime: int
:param endTimestamp: optional
:type endTimestamp: int
:param page: optional - default 1
:type page: int
:param rows: optional - default 100, max 100
:type rows: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
{
"code": "000000",
"message": "success",
"data": [
{
"orderNumber":"20219644646554779648",
"advNo": "11218246497340923904",
"tradeType": "SELL",
"asset": "BUSD",
"fiat": "CNY",
"fiatSymbol": "¥",
"amount": "5000.00000000", // Quantity (in Crypto)
"totalPrice": "33400.00000000",
"unitPrice": "6.68", // Unit Price (in Fiat)
"orderStatus": "COMPLETED", // PENDING, TRADING, BUYER_PAYED, DISTRIBUTING, COMPLETED, IN_APPEAL, CANCELLED, CANCELLED_BY_SYSTEM
"createTime": 1619361369000,
"commission": "0", // Transaction Fee (in Crypto)
"counterPartNickName": "ab***",
"advertisementRole": "TAKER"
}
],
"total": 1,
"success": true
}
"""
return self._request_margin_api(
"get", "c2c/orderMatch/listUserOrderHistory", signed=True, data=params
)
```
Get C2C Trade History
[https://binance-docs.github.io/apidocs/spot/en/#pay-endpoints](https://binance-docs.github.io/apidocs/spot/en/#pay-endpoints)
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional - default 100, max 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def get_pay_trade_history(self, **params):
"""Get C2C Trade History
https://binance-docs.github.io/apidocs/spot/en/#pay-endpoints
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional - default 100, max 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_margin_api(
"get", "pay/transactions", signed=True, data=params
)
```
Get C2C Trade History
[https://developers.binance.com/docs/convert/trade/Get-Convert-Trade-History](https://developers.binance.com/docs/convert/trade/Get-Convert-Trade-History)
:param startTime: required - Start Time - 1593511200000
:type startTime: int
:param endTime: required - End Time - 1593511200000
:type endTime: int
:param limit: optional - default 100, max 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def get_convert_trade_history(self, **params):
"""Get C2C Trade History
https://developers.binance.com/docs/convert/trade/Get-Convert-Trade-History
:param startTime: required - Start Time - 1593511200000
:type startTime: int
:param endTime: required - End Time - 1593511200000
:type endTime: int
:param limit: optional - default 100, max 100
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_margin_api(
"get", "convert/tradeFlow", signed=True, data=params
)
```
Request a quote for the requested token pairs
[https://developers.binance.com/docs/convert/trade](https://developers.binance.com/docs/convert/trade)
:param fromAsset: required - Asset to convert from - BUSD
:type fromAsset: str
:param toAsset: required - Asset to convert to - BTC
:type toAsset: str
:param fromAmount: EITHER - When specified, it is the amount you will be debited after the conversion
:type fromAmount: decimal
:param toAmount: EITHER - When specified, it is the amount you will be credited after the conversion
:type toAmount: decimal
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def convert_request_quote(self, **params):
"""Request a quote for the requested token pairs
https://developers.binance.com/docs/convert/trade
:param fromAsset: required - Asset to convert from - BUSD
:type fromAsset: str
:param toAsset: required - Asset to convert to - BTC
:type toAsset: str
:param fromAmount: EITHER - When specified, it is the amount you will be debited after the conversion
:type fromAmount: decimal
:param toAmount: EITHER - When specified, it is the amount you will be credited after the conversion
:type toAmount: decimal
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_margin_api(
"post", "convert/getQuote", signed=True, data=params
)
```
Accept the offered quote by quote ID.
[https://developers.binance.com/docs/convert/trade/Accept-Quote](https://developers.binance.com/docs/convert/trade/Accept-Quote)
:param quoteId: required - 457235734584567
:type quoteId: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def convert_accept_quote(self, **params):
"""Accept the offered quote by quote ID.
https://developers.binance.com/docs/convert/trade/Accept-Quote
:param quoteId: required - 457235734584567
:type quoteId: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_margin_api(
"post", "convert/acceptQuote", signed=True, data=params
)
```
Query account balance.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account](https://developers.binance.com/docs/derivatives/portfolio-margin/account)
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_balance(self, **params):
"""Query account balance.
https://developers.binance.com/docs/derivatives/portfolio-margin/account
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "balance", signed=True, data=params)
```
Query User Rate Limit
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-User-Rate-Limit](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-User-Rate-Limit)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_rate_limit(self, **params):
"""Query User Rate Limit
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-User-Rate-Limit
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "rateLimit/order", signed=True, data=params)
```
Start a new user data stream for Portfolio Margin account.
[https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams/Start-User-Data-Stream](https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams/Start-User-Data-Stream)
:returns: API response
\{
"listenKey": "pM\_XXXXXXX"
}
The stream will close after 60 minutes unless a keepalive is sent.
If the account has an active listenKey, that listenKey will be returned and its validity will be extended for 60 minutes.
Weight: 1
```python
def papi_stream_get_listen_key(self):
"""Start a new user data stream for Portfolio Margin account.
https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams/Start-User-Data-Stream
:returns: API response
{
"listenKey": "pM_XXXXXXX"
}
The stream will close after 60 minutes unless a keepalive is sent.
If the account has an active listenKey, that listenKey will be returned and its validity will be extended for 60 minutes.
Weight: 1
"""
res = self._request_papi_api("post", "listenKey", signed=False, data={})
return res["listenKey"]
```
Keepalive a user data stream to prevent a time out.
[https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams/Keepalive-User-Data-Stream](https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams/Keepalive-User-Data-Stream)
:returns: API response
\{}
User data streams will close after 60 minutes. It's recommended to send a ping about every 60 minutes.
Weight: 1
```python
def papi_stream_keepalive(self, listenKey):
"""Keepalive a user data stream to prevent a time out.
https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams/Keepalive-User-Data-Stream
:returns: API response
{}
User data streams will close after 60 minutes. It's recommended to send a ping about every 60 minutes.
Weight: 1
"""
params = {"listenKey": listenKey}
return self._request_papi_api("put", "listenKey", signed=False, data=params)
```
Close out a user data stream.
[https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams/Close-User-Data-Stream](https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams/Close-User-Data-Stream)
:returns: API response
\{}
Weight: 1
```python
def papi_stream_close(self, listenKey):
"""Close out a user data stream.
https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams/Close-User-Data-Stream
:returns: API response
{}
Weight: 1
"""
params = {"listenKey": listenKey}
return self._request_papi_api("delete", "listenKey", signed=False, data=params)
```
Query account information.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Account-Information](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Account-Information)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_account(self, **params):
"""Query account information.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Account-Information
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "account", signed=True, data=params)
```
Query margin max borrow.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Margin-Max-Borrow](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Margin-Max-Borrow)
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_margin_max_borrowable(self, **params):
"""Query margin max borrow.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Margin-Max-Borrow
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "margin/maxBorrowable", signed=True, data=params
)
```
Query margin max borrow.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-Max-Withdraw](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-Max-Withdraw)
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_margin_max_withdraw(self, **params):
"""Query margin max borrow.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-Max-Withdraw
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "margin/maxWithdraw", signed=True, data=params
)
```
Query margin max borrow.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-UM-Position-Information](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-UM-Position-Information)
:param symbol: required
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_position_risk(self, **params):
"""Query margin max borrow.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-UM-Position-Information
:param symbol: required
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/positionRisk", signed=True, data=params
)
```
Query margin max borrow.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-CM-Position-Information](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-CM-Position-Information)
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_cm_position_risk(self, **params):
"""Query margin max borrow.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-CM-Position-Information
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "cm/positionRisk", signed=True, data=params
)
```
Query margin max borrow.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-UM-Initial-Leverage](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-UM-Initial-Leverage)
:param asset: required
:type asset: str
:param leverage: required
:type leverage: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_set_um_leverage(self, **params):
"""Query margin max borrow.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-UM-Initial-Leverage
:param asset: required
:type asset: str
:param leverage: required
:type leverage: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("post", "um/leverage", signed=True, data=params)
```
Query margin max borrow.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-CM-Initial-Leverage](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-CM-Initial-Leverage)
:param asset: required
:type asset: str
:param leverage: required
:type leverage: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_set_cm_leverage(self, **params):
"""Query margin max borrow.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-CM-Initial-Leverage
:param asset: required
:type asset: str
:param leverage: required
:type leverage: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("post", "cm/leverage", signed=True, data=params)
```
Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in UM.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-UM-Position-Mode](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-UM-Position-Mode)
:param dualSidePosition: required
:type dualSidePosition: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_change_um_position_side_dual(self, **params):
"""Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in UM.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-UM-Position-Mode
:param dualSidePosition: required
:type dualSidePosition: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"post", "um/positionSide/dual", signed=True, data=params
)
```
Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in CM.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-CM-Position-Mode](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-CM-Position-Mode)
:param dualSidePosition: required
:type dualSidePosition: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_change_cm_position_side_dual(self, **params):
"""Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in CM.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-CM-Position-Mode
:param dualSidePosition: required
:type dualSidePosition: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"post", "cm/positionSide/dual", signed=True, data=params
)
```
Get user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in UM.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Current-Position-Mode](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Current-Position-Mode)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_position_side_dual(self, **params):
"""Get user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in UM.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Current-Position-Mode
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/positionSide/dual", signed=True, data=params
)
```
Get user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in CM.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Current-Position-Mode](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Current-Position-Mode)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_cm_position_side_dual(self, **params):
"""Get user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol in CM.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Current-Position-Mode
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "cm/positionSide/dual", signed=True, data=params
)
```
Query UM notional and leverage brackets.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/UM-Notional-and-Leverage-Brackets](https://developers.binance.com/docs/derivatives/portfolio-margin/account/UM-Notional-and-Leverage-Brackets)
:param symbol: optional
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_leverage_bracket(self, **params):
"""Query UM notional and leverage brackets.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/UM-Notional-and-Leverage-Brackets
:param symbol: optional
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/leverageBracket", signed=True, data=params
)
```
Query CM notional and leverage brackets.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/CM-Notional-and-Leverage-Brackets](https://developers.binance.com/docs/derivatives/portfolio-margin/account/CM-Notional-and-Leverage-Brackets)
:param symbol: optional
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_cm_leverage_bracket(self, **params):
"""Query CM notional and leverage brackets.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/CM-Notional-and-Leverage-Brackets
:param symbol: optional
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "cm/leverageBracket", signed=True, data=params
)
```
Portfolio Margin UM Trading Quantitative Rules Indicators.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Portfolio-Margin-UM-Trading-Quantitative-Rules-Indicators](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Portfolio-Margin-UM-Trading-Quantitative-Rules-Indicators)
:param symbol: optional
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_api_trading_status(self, **params):
"""Portfolio Margin UM Trading Quantitative Rules Indicators.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Portfolio-Margin-UM-Trading-Quantitative-Rules-Indicators
:param symbol: optional
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/apiTradingStatus", signed=True, data=params
)
```
Get User Commission Rate for UM.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-UM](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-UM)
:param symbol: required
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_comission_rate(self, **params):
"""Get User Commission Rate for UM.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-UM
:param symbol: required
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/commissionRate", signed=True, data=params
)
```
Get User Commission Rate for CM.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-CM](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-CM)
:param symbol: required
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_cm_comission_rate(self, **params):
"""Get User Commission Rate for CM.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-User-Commission-Rate-for-CM
:param symbol: required
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "cm/commissionRate", signed=True, data=params
)
```
Query margin loan record.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-Loan-Record](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-Loan-Record)
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_margin_margin_loan(self, **params):
"""Query margin loan record.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-Loan-Record
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "margin/marginLoan", signed=True, data=params
)
```
Query margin repay record.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-repay-Record](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-repay-Record)
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_margin_repay_loan(self, **params):
"""Query margin repay record.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Margin-repay-Record
:param asset: required
:type asset: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "margin/repayLoan", signed=True, data=params
)
```
Query Auto-repay-futures Status.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Auto-repay-futures-Status](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Auto-repay-futures-Status)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_repay_futures_switch(self, **params):
"""Query Auto-repay-futures Status.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Auto-repay-futures-Status
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "repay-futures-switch", signed=True, data=params
)
```
Change Auto-repay-futures Status.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-Auto-repay-futures-Status](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-Auto-repay-futures-Status)
:param autoRepay: required
:type autoRepay: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_repay_futures_switch(self, **params):
"""Change Auto-repay-futures Status.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Change-Auto-repay-futures-Status
:param autoRepay: required
:type autoRepay: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"post", "repay-futures-switch", signed=True, data=params
)
```
Get Margin Borrow/Loan Interest History.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Margin-BorrowLoan-Interest-History](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Margin-BorrowLoan-Interest-History)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_margin_interest_history(self, **params):
"""Get Margin Borrow/Loan Interest History.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Margin-BorrowLoan-Interest-History
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "margin/marginInterestHistory", signed=True, data=params
)
```
Repay futures Negative Balance.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Repay-futures-Negative-Balance](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Repay-futures-Negative-Balance)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_repay_futures_negative_balance(self, **params):
"""Repay futures Negative Balance.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Repay-futures-Negative-Balance
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"post", "repay-futures-negative-balance", signed=True, data=params
)
```
Query interest history of negative balance for portfolio margin.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Portfolio-Margin-Negative-Balance-Interest-History](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Portfolio-Margin-Negative-Balance-Interest-History)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_portfolio_interest_history(self, **params):
"""Query interest history of negative balance for portfolio margin.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-Portfolio-Margin-Negative-Balance-Interest-History
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "portfolio/interest-history", signed=True, data=params
)
```
Query user negative balance auto exchange record.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-User-Negative-Balance-Auto-Exchange-Record](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-User-Negative-Balance-Auto-Exchange-Record)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_portfolio_negative_balance_exchange_record(self, **params):
"""Query user negative balance auto exchange record.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Query-User-Negative-Balance-Auto-Exchange-Record
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "portfolio/negative-balance-exchange-record", signed=True, data=params
)
```
Fund collection for Portfolio Margin.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Fund-Auto-collection](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Fund-Auto-collection)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_fund_auto_collection(self, **params):
"""Fund collection for Portfolio Margin.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Fund-Auto-collection
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"post", "auto-collection", signed=True, data=params
)
```
Transfers specific asset from Futures Account to Margin account.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Fund-Collection-by-Asset](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Fund-Collection-by-Asset)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_fund_asset_collection(self, **params):
"""Transfers specific asset from Futures Account to Margin account.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Fund-Collection-by-Asset
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"post", "asset-collection", signed=True, data=params
)
```
Transfer BNB in and out of UM.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/BNB-transfer](https://developers.binance.com/docs/derivatives/portfolio-margin/account/BNB-transfer)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_bnb_transfer(self, **params):
"""Transfer BNB in and out of UM.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/BNB-transfer
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("post", "bnb-transfer", signed=True, data=params)
```
Get UM Income History.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Income-History](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Income-History)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_income_history(self, **params):
"""Get UM Income History.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Income-History
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "um/income", signed=True, data=params)
```
Get CM Income History.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Income-History](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Income-History)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_cm_income_history(self, **params):
"""Get CM Income History.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Income-History
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "cm/income", signed=True, data=params)
```
Get current UM account asset and position information.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Account-Detail](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Account-Detail)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_account(self, **params):
"""Get current UM account asset and position information.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Account-Detail
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "um/account", signed=True, data=params)
```
Get current UM account asset and position information.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Account-Detail-V2](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Account-Detail-V2)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_account_v2(self, **params):
"""Get current UM account asset and position information.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Account-Detail-V2
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/account", version=2, signed=True, data=params
)
```
Get current CM account asset and position information.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Account-Detail](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Account-Detail)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_cm_account(self, **params):
"""Get current CM account asset and position information.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-CM-Account-Detail
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "cm/account", signed=True, data=params)
```
Query UM Futures account configuration.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Account-Config](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Account-Config)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_account_config(self, **params):
"""Query UM Futures account configuration.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Account-Config
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/accountConfig", signed=True, data=params
)
```
Get current UM account symbol configuration.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Symbol-Config](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Symbol-Config)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_symbol_config(self, **params):
"""Get current UM account symbol configuration.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Symbol-Config
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/symbolConfig", signed=True, data=params
)
```
Get download id for UM futures trade history.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Trade-History](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Trade-History)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_trade_asyn(self, **params):
"""Get download id for UM futures trade history.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Trade-History
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "um/trade/asyn", signed=True, data=params)
```
Get UM futures trade download link by Id.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Trade-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Trade-Download-Link-by-Id)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_trade_asyn_id(self, **params):
"""Get UM futures trade download link by Id.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Trade-Download-Link-by-Id
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/trade/asyn/id", signed=True, data=params
)
```
Get download id for UM futures order history.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Order-History](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Order-History)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_order_asyn(self, **params):
"""Get download id for UM futures order history.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Order-History
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "um/order/asyn", signed=True, data=params)
```
Get UM futures order download link by Id.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Order-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Order-Download-Link-by-Id)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_order_asyn_id(self, **params):
"""Get UM futures order download link by Id.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Order-Download-Link-by-Id
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/order/asyn/id", signed=True, data=params
)
```
Get download id for UM futures transaction history.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Transaction-History](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Transaction-History)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_income_asyn(self, **params):
"""Get download id for UM futures transaction history.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-Download-Id-For-UM-Futures-Transaction-History
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api("get", "um/income/asyn", signed=True, data=params)
```
Get UM futures Transaction download link by Id.
[https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Transaction-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Transaction-Download-Link-by-Id)
:param recvWindow: optional
:type recvWindow: int
:returns: API response
```python
def papi_get_um_income_asyn_id(self, **params):
"""Get UM futures Transaction download link by Id.
https://developers.binance.com/docs/derivatives/portfolio-margin/account/Get-UM-Futures-Transaction-Download-Link-by-Id
:param recvWindow: optional
:type recvWindow: int
:returns: API response
"""
return self._request_papi_api(
"get", "um/income/asyn/id", signed=True, data=params
)
```
Test connectivity to the Rest API.
[https://developers.binance.com/docs/derivatives/portfolio-margin/market-data](https://developers.binance.com/docs/derivatives/portfolio-margin/market-data)
:returns: API response
```python
def papi_ping(self, **params):
"""Test connectivity to the Rest API.
https://developers.binance.com/docs/derivatives/portfolio-margin/market-data
:returns: API response
"""
return self._request_papi_api("get", "ping", signed=False, data=params)
```
Place new UM order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade](https://developers.binance.com/docs/derivatives/portfolio-margin/trade)
:returns: API response
```python
def papi_create_um_order(self, **params):
"""Place new UM order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._request_papi_api("post", "um/order", signed=True, data=params)
```
Place new UM Conditional order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-UM-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-UM-Conditional-Order)
:returns: API response
```python
def papi_create_um_conditional_order(self, **params):
"""Place new UM Conditional order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-UM-Conditional-Order
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._request_papi_api(
"post", "um/conditional/order", signed=True, data=params
)
```
Place new CM order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Order)
:returns: API response
```python
def papi_create_cm_order(self, **params):
"""Place new CM order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Order
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._request_papi_api("post", "cm/order", signed=True, data=params)
```
Place new CM Conditional order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Conditional-Order)
:returns: API response
```python
def papi_create_cm_conditional_order(self, **params):
"""Place new CM Conditional order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-CM-Conditional-Order
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._request_papi_api(
"post", "cm/conditional/order", signed=True, data=params
)
```
New Margin Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-Margin-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-Margin-Order)
:returns: API response
```python
def papi_create_margin_order(self, **params):
"""New Margin Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/New-Margin-Order
:returns: API response
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._request_papi_api("post", "margin/order", signed=True, data=params)
```
Apply for a margin loan.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Borrow](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Borrow)
:returns: API response
```python
def papi_margin_loan(self, **params):
"""Apply for a margin loan.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Borrow
:returns: API response
"""
return self._request_papi_api("post", "marginLoan", signed=True, data=params)
```
Repay for a margin loan.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay)
:returns: API response
```python
def papi_repay_loan(self, **params):
"""Repay for a margin loan.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay
:returns: API response
"""
return self._request_papi_api("post", "repayLoan", signed=True, data=params)
```
Send in a new OCO for a margin account.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-New-OCO](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-New-OCO)
:returns: API response
```python
def papi_margin_order_oco(self, **params):
"""Send in a new OCO for a margin account.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-New-OCO
:returns: API response
"""
return self._request_papi_api(
"post", "margin/order/oco", signed=True, data=params
)
```
Cancel an active UM LIMIT order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Order)
:returns: API response
```python
def papi_cancel_um_order(self, **params):
"""Cancel an active UM LIMIT order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Order
:returns: API response
"""
return self._request_papi_api("delete", "um/order", signed=True, data=params)
```
Cancel an active UM LIMIT order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Orders)
:returns: API response
```python
def papi_cancel_um_all_open_orders(self, **params):
"""Cancel an active UM LIMIT order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Orders
:returns: API response
"""
return self._request_papi_api(
"delete", "um/allOpenOrders", signed=True, data=params
)
```
Cancel UM Conditional Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Conditional-Order)
:returns: API response
```python
def papi_cancel_um_conditional_order(self, **params):
"""Cancel UM Conditional Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-UM-Conditional-Order
:returns: API response
"""
return self._request_papi_api(
"delete", "um/conditional/order", signed=True, data=params
)
```
Cancel All UM Open Conditional Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Conditional-Orders)
:returns: API response
```python
def papi_cancel_um_conditional_all_open_orders(self, **params):
"""Cancel All UM Open Conditional Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-UM-Open-Conditional-Orders
:returns: API response
"""
return self._request_papi_api(
"delete", "um/conditional/allOpenOrders", signed=True, data=params
)
```
Cancel an active CM LIMIT order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Order)
:returns: API response
```python
def papi_cancel_cm_order(self, **params):
"""Cancel an active CM LIMIT order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Order
:returns: API response
"""
return self._request_papi_api("delete", "cm/order", signed=True, data=params)
```
Cancel an active CM LIMIT order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Orders)
:returns: API response
```python
def papi_cancel_cm_all_open_orders(self, **params):
"""Cancel an active CM LIMIT order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Orders
:returns: API response
"""
return self._request_papi_api(
"delete", "cm/allOpenOrders", signed=True, data=params
)
```
Cancel CM Conditional Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Conditional-Order)
:returns: API response
```python
def papi_cancel_cm_conditional_order(self, **params):
"""Cancel CM Conditional Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-CM-Conditional-Order
:returns: API response
"""
return self._request_papi_api(
"delete", "cm/conditional/order", signed=True, data=params
)
```
Cancel All CM Open Conditional Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Conditional-Orders)
:returns: API response
```python
def papi_cancel_cm_conditional_all_open_orders(self, **params):
"""Cancel All CM Open Conditional Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-All-CM-Open-Conditional-Orders
:returns: API response
"""
return self._request_papi_api(
"delete", "cm/conditional/allOpenOrders", signed=True, data=params
)
```
Cancel Margin Account Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-Order)
:returns: API response
```python
def papi_cancel_margin_order(self, **params):
"""Cancel Margin Account Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-Order
:returns: API response
"""
return self._request_papi_api(
"delete", "margin/order", signed=True, data=params
)
```
Cancel Margin Account OCO Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-OCO-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-OCO-Orders)
:returns: API response
```python
def papi_cancel_margin_order_list(self, **params):
"""Cancel Margin Account OCO Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-OCO-Orders
:returns: API response
"""
return self._request_papi_api(
"delete", "margin/orderList", signed=True, data=params
)
```
Cancel Margin Account All Open Orders on a Symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-All-Open-Orders-on-a-Symbol](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-All-Open-Orders-on-a-Symbol)
:returns: API response
```python
def papi_cancel_margin_all_open_orders(self, **params):
"""Cancel Margin Account All Open Orders on a Symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Cancel-Margin-Account-All-Open-Orders-on-a-Symbol
:returns: API response
"""
return self._request_papi_api(
"delete", "margin/allOpenOrders", signed=True, data=params
)
```
Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-UM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-UM-Order)
:returns: API response
```python
def papi_modify_um_order(self, **params):
"""Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-UM-Order
:returns: API response
"""
return self._request_papi_api("put", "um/order", signed=True, data=params)
```
Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-CM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-CM-Order)
:returns: API response
```python
def papi_modify_cm_order(self, **params):
"""Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Modify-CM-Order
:returns: API response
"""
return self._request_papi_api("put", "cm/order", signed=True, data=params)
```
Check an UM order's status.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order)
:returns: API response
```python
def papi_get_um_order(self, **params):
"""Check an UM order's status.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Order
:returns: API response
"""
return self._request_papi_api("get", "um/order", signed=True, data=params)
```
Get all account UM orders; active, canceled, or filled.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Orders)
:returns: API response
```python
def papi_get_um_all_orders(self, **params):
"""Get all account UM orders; active, canceled, or filled.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Orders
:returns: API response
"""
return self._request_papi_api("get", "um/allOrders", signed=True, data=params)
```
Query current UM open order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Order)
:returns: API response
```python
def papi_get_um_open_order(self, **params):
"""Query current UM open order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Order
:returns: API response
"""
return self._request_papi_api("get", "um/openOrder", signed=True, data=params)
```
Get all open orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders)
:returns: API response
```python
def papi_get_um_open_orders(self, **params):
"""Get all open orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Orders
:returns: API response
"""
return self._request_papi_api("get", "um/openOrders", signed=True, data=params)
```
Query All UM Conditional Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Conditional-Orders)
:returns: API response
```python
def papi_get_um_conditional_all_orders(self, **params):
"""Query All UM Conditional Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-UM-Conditional-Orders
:returns: API response
"""
return self._request_papi_api(
"get", "um/conditional/allOrders", signed=True, data=params
)
```
Get all open conditional orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Conditional-Orders)
:returns: API response
```python
def papi_get_um_conditional_open_orders(self, **params):
"""Get all open conditional orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-UM-Open-Conditional-Orders
:returns: API response
"""
return self._request_papi_api(
"get", "um/conditional/openOrders", signed=True, data=params
)
```
Query Current UM Open Conditional Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Conditional-Order)
:returns: API response
```python
def papi_get_um_conditional_open_order(self, **params):
"""Query Current UM Open Conditional Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-UM-Open-Conditional-Order
:returns: API response
"""
return self._request_papi_api(
"get", "um/conditional/openOrder", signed=True, data=params
)
```
Get all open conditional orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Conditional-Order-History](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Conditional-Order-History)
:returns: API response
```python
def papi_get_um_conditional_order_history(self, **params):
"""Get all open conditional orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Conditional-Order-History
:returns: API response
"""
return self._request_papi_api(
"get", "um/conditional/orderHistory", signed=True, data=params
)
```
Check an CM order's status.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order)
:returns: API response
```python
def papi_get_cm_order(self, **params):
"""Check an CM order's status.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Order
:returns: API response
"""
return self._request_papi_api("get", "cm/order", signed=True, data=params)
```
Get all account CM orders; active, canceled, or filled.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Orders)
:returns: API response
```python
def papi_get_cm_all_orders(self, **params):
"""Get all account CM orders; active, canceled, or filled.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Orders
:returns: API response
"""
return self._request_papi_api("get", "cm/allOrders", signed=True, data=params)
```
Query current CM open order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Order)
:returns: API response
```python
def papi_get_cm_open_order(self, **params):
"""Query current CM open order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Order
:returns: API response
"""
return self._request_papi_api("get", "cm/openOrder", signed=True, data=params)
```
Get all open orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Orders)
:returns: API response
```python
def papi_get_cm_open_orders(self, **params):
"""Get all open orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Orders
:returns: API response
"""
return self._request_papi_api("get", "cm/openOrders", signed=True, data=params)
```
Query All CM Conditional Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Conditional-Orders)
:returns: API response
```python
def papi_get_cm_conditional_all_orders(self, **params):
"""Query All CM Conditional Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-CM-Conditional-Orders
:returns: API response
"""
return self._request_papi_api(
"get", "cm/conditional/allOrders", signed=True, data=params
)
```
Get all open conditional orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Conditional-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Conditional-Orders)
:returns: API response
```python
def papi_get_cm_conditional_open_orders(self, **params):
"""Get all open conditional orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Current-CM-Open-Conditional-Orders
:returns: API response
"""
return self._request_papi_api(
"get", "cm/conditional/openOrders", signed=True, data=params
)
```
Query Current UM Open Conditional Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Conditional-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Conditional-Order)
:returns: API response
```python
def papi_get_cm_conditional_open_order(self, **params):
"""Query Current UM Open Conditional Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-CM-Open-Conditional-Order
:returns: API response
"""
return self._request_papi_api(
"get", "cm/conditional/openOrder", signed=True, data=params
)
```
Get all open conditional orders on a symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Conditional-Order-History](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Conditional-Order-History)
:returns: API response
```python
def papi_get_cm_conditional_order_history(self, **params):
"""Get all open conditional orders on a symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Conditional-Order-History
:returns: API response
"""
return self._request_papi_api(
"get", "cm/conditional/orderHistory", signed=True, data=params
)
```
Query User's UM Force Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-UM-Force-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-UM-Force-Orders)
:returns: API response
```python
def papi_get_um_force_orders(self, **params):
"""Query User's UM Force Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-UM-Force-Orders
:returns: API response
"""
return self._request_papi_api("get", "um/forceOrders", signed=True, data=params)
```
Query User's CM Force Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-CM-Force-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-CM-Force-Orders)
:returns: API response
```python
def papi_get_cm_force_orders(self, **params):
"""Query User's CM Force Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-CM-Force-Orders
:returns: API response
"""
return self._request_papi_api("get", "cm/forceOrders", signed=True, data=params)
```
Get order modification history.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Modify-Order-History](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Modify-Order-History)
:returns: API response
```python
def papi_get_um_order_amendment(self, **params):
"""Get order modification history.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-UM-Modify-Order-History
:returns: API response
"""
return self._request_papi_api(
"get", "um/orderAmendment", signed=True, data=params
)
```
Get order modification history.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Modify-Order-History](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Modify-Order-History)
:returns: API response
```python
def papi_get_cm_order_amendment(self, **params):
"""Get order modification history.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-CM-Modify-Order-History
:returns: API response
"""
return self._request_papi_api(
"get", "cm/orderAmendment", signed=True, data=params
)
```
Query user's margin force orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-Margin-Force-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-Margin-Force-Orders)
:returns: API response
```python
def papi_get_margin_force_orders(self, **params):
"""Query user's margin force orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Users-Margin-Force-Orders
:returns: API response
"""
return self._request_papi_api(
"get", "margin/forceOrders", signed=True, data=params
)
```
Get trades for a specific account and UM symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Account-Trade-List](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Account-Trade-List)
:returns: API response
```python
def papi_get_um_user_trades(self, **params):
"""Get trades for a specific account and UM symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Account-Trade-List
:returns: API response
"""
return self._request_papi_api("get", "um/userTrades", signed=True, data=params)
```
Get trades for a specific account and CM symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Account-Trade-List](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Account-Trade-List)
:returns: API response
```python
def papi_get_cm_user_trades(self, **params):
"""Get trades for a specific account and CM symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Account-Trade-List
:returns: API response
"""
return self._request_papi_api("get", "cm/userTrades", signed=True, data=params)
```
Query UM Position ADL Quantile Estimation.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Position-ADL-Quantile-Estimation](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Position-ADL-Quantile-Estimation)
:returns: API response
```python
def papi_get_um_adl_quantile(self, **params):
"""Query UM Position ADL Quantile Estimation.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/UM-Position-ADL-Quantile-Estimation
:returns: API response
"""
return self._request_papi_api("get", "um/adlQuantile", signed=True, data=params)
```
Query CM Position ADL Quantile Estimation.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Position-ADL-Quantile-Estimation](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Position-ADL-Quantile-Estimation)
:returns: API response
```python
def papi_get_cm_adl_quantile(self, **params):
"""Query CM Position ADL Quantile Estimation.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/CM-Position-ADL-Quantile-Estimation
:returns: API response
"""
return self._request_papi_api("get", "cm/adlQuantile", signed=True, data=params)
```
Change user's BNB Fee Discount for UM Futures (Fee Discount On or Fee Discount Off ) on EVERY symbol.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Toggle-BNB-Burn-On-UM-Futures-Trade](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Toggle-BNB-Burn-On-UM-Futures-Trade)
:returns: API response
```python
def papi_set_um_fee_burn(self, **params):
"""Change user's BNB Fee Discount for UM Futures (Fee Discount On or Fee Discount Off ) on EVERY symbol.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Toggle-BNB-Burn-On-UM-Futures-Trade
:returns: API response
"""
return self._request_papi_api("post", "um/feeBurn", signed=True, data=params)
```
Get user's BNB Fee Discount for UM Futures (Fee Discount On or Fee Discount Off).
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Get-UM-Futures-BNB-Burn-Status](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Get-UM-Futures-BNB-Burn-Status)
:returns: API response
```python
def papi_get_um_fee_burn(self, **params):
"""Get user's BNB Fee Discount for UM Futures (Fee Discount On or Fee Discount Off).
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Get-UM-Futures-BNB-Burn-Status
:returns: API response
"""
return self._request_papi_api("get", "um/feeBurn", signed=True, data=params)
```
Query Margin Account Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Order)
:returns: API response
```python
def papi_get_margin_order(self, **params):
"""Query Margin Account Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Order
:returns: API response
"""
return self._request_papi_api("get", "margin/order", signed=True, data=params)
```
Query Current Margin Open Order.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-Margin-Open-Order](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-Margin-Open-Order)
:returns: API response
```python
def papi_get_margin_open_orders(self, **params):
"""Query Current Margin Open Order.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Current-Margin-Open-Order
:returns: API response
"""
return self._request_papi_api(
"get", "margin/openOrders", signed=True, data=params
)
```
Query All Margin Account Orders.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Margin-Account-Orders](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Margin-Account-Orders)
:returns: API response
```python
def papi_get_margin_all_orders(self, **params):
"""Query All Margin Account Orders.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-All-Margin-Account-Orders
:returns: API response
"""
return self._request_papi_api(
"get", "margin/allOrders", signed=True, data=params
)
```
Retrieves a specific OCO based on provided optional parameters.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-OCO](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-OCO)
:returns: API response
```python
def papi_get_margin_order_list(self, **params):
"""Retrieves a specific OCO based on provided optional parameters.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-OCO
:returns: API response
"""
return self._request_papi_api(
"get", "margin/orderList", signed=True, data=params
)
```
Query all OCO for a specific margin account based on provided optional parameters.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-all-OCO](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-all-OCO)
:returns: API response
```python
def papi_get_margin_all_order_list(self, **params):
"""Query all OCO for a specific margin account based on provided optional parameters.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-all-OCO
:returns: API response
"""
return self._request_papi_api(
"get", "margin/allOrderList", signed=True, data=params
)
```
Query Margin Account's Open OCO.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Open-OCO](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Open-OCO)
:returns: API response
```python
def papi_get_margin_open_order_list(self, **params):
"""Query Margin Account's Open OCO.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Query-Margin-Account-Open-OCO
:returns: API response
"""
return self._request_papi_api(
"get", "margin/openOrderList", signed=True, data=params
)
```
Margin Account Trade List.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Trade-List](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Trade-List)
:returns: API response
```python
def papi_get_margin_my_trades(self, **params):
"""Margin Account Trade List.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Trade-List
:returns: API response
"""
return self._request_papi_api(
"get", "margin/myTrades", signed=True, data=params
)
```
Repay debt for a margin loan.
[https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay-Debt](https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay-Debt)
:returns: API response
```python
def papi_get_margin_repay_debt(self, **params):
"""Repay debt for a margin loan.
https://developers.binance.com/docs/derivatives/portfolio-margin/trade/Margin-Account-Repay-Debt
:returns: API response
"""
return self._request_papi_api(
"post", "margin/repay-debt", signed=True, data=params
)
```
```python
def close_connection(self):
if self.session:
self.session.close()
```
```python
def __del__(self):
self.close_connection()
```
Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.
[https://binance-docs.github.io/apidocs/websocket\_api/en/#test-new-order-trade](https://binance-docs.github.io/apidocs/websocket_api/en/#test-new-order-trade)
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param type: required
:type type: str
:param timeInForce: required if limit order
:type timeInForce: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: The number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
.. code-block:: python
\{}
```python
def ws_create_test_order(self, **params):
"""Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine.
https://binance-docs.github.io/apidocs/websocket_api/en/#test-new-order-trade
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param type: required
:type type: str
:param timeInForce: required if limit order
:type timeInForce: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: The number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
.. code-block:: python
{}
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return self._ws_api_request_sync("order.test", True, params)
```
Create an order via WebSocket.
[https://binance-docs.github.io/apidocs/websocket\_api/en/#place-new-order-trade](https://binance-docs.github.io/apidocs/websocket_api/en/#place-new-order-trade)
:param id: The request ID to be used. By default uuid22() is used.
:param symbol: The symbol to create an order for
:param side: BUY or SELL
:param type: Order type (e.g., LIMIT, MARKET)
:param quantity: The amount to buy or sell
:param kwargs: Additional order parameters
```python
def ws_create_order(self, **params):
"""Create an order via WebSocket.
https://binance-docs.github.io/apidocs/websocket_api/en/#place-new-order-trade
:param id: The request ID to be used. By default uuid22() is used.
:param symbol: The symbol to create an order for
:param side: BUY or SELL
:param type: Order type (e.g., LIMIT, MARKET)
:param quantity: The amount to buy or sell
:param kwargs: Additional order parameters
"""
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.SPOT_ORDER_PREFIX + self.uuid22()
return self._ws_api_request_sync("order.place", True, params)
```
Send in a new limit order
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP\_LOSS\_LIMIT, and TAKE\_PROFIT\_LIMIT to create an iceberg order.
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
def ws_order_limit(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
"""Send in a new limit order
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param icebergQty: Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({
"type": self.ORDER_TYPE_LIMIT,
"timeInForce": timeInForce,
})
return self.ws_create_order(**params)
```
Send in a new limit buy order
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
def ws_order_limit_buy(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
"""Send in a new limit buy order
Any order with an icebergQty MUST have timeInForce set to GTC.
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({
"side": self.SIDE_BUY,
})
return self.ws_order_limit(timeInForce=timeInForce, **params)
```
Send in a new limit sell order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
def ws_order_limit_sell(self, timeInForce=BaseClient.TIME_IN_FORCE_GTC, **params):
"""Send in a new limit sell order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param price: required
:type price: str
:param timeInForce: default Good till cancelled
:type timeInForce: str
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param stopPrice: Used with stop orders
:type stopPrice: decimal
:param icebergQty: Used with iceberg orders
:type icebergQty: decimal
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({"side": self.SIDE_SELL})
return self.ws_order_limit(timeInForce=timeInForce, **params)
```
Send in a new market order
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: amount the user wants to spend (when buying) or receive (when selling)
of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
def ws_order_market(self, **params):
"""Send in a new market order
:param symbol: required
:type symbol: str
:param side: required
:type side: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: amount the user wants to spend (when buying) or receive (when selling)
of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({"type": self.ORDER_TYPE_MARKET})
return self.ws_create_order(**params)
```
Send in a new market buy order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to spend of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
def ws_order_market_buy(self, **params):
"""Send in a new market buy order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to spend of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({"side": self.SIDE_BUY})
return self.ws_order_market(**params)
```
Send in a new market sell order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to receive of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
```python
def ws_order_market_sell(self, **params):
"""Send in a new market sell order
:param symbol: required
:type symbol: str
:param quantity: required
:type quantity: decimal
:param quoteOrderQty: the amount the user wants to receive of the quote asset
:type quoteOrderQty: decimal
:param newClientOrderId: A unique id for the order. Automatically generated if not sent.
:type newClientOrderId: str
:param newOrderRespType: Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
:type newOrderRespType: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
See order endpoint for full response options
"""
params.update({"side": self.SIDE_SELL})
return self.ws_order_market(**params)
```
Check an order's status. Either orderId or origClientOrderId must be sent.
[https://binance-docs.github.io/apidocs/websocket\_api/en/#query-order-user\_data](https://binance-docs.github.io/apidocs/websocket_api/en/#query-order-user_data)
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param origClientOrderId: optional
:type origClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
```python
def ws_get_order(self, **params):
"""Check an order's status. Either orderId or origClientOrderId must be sent.
https://binance-docs.github.io/apidocs/websocket_api/en/#query-order-user_data
:param symbol: required
:type symbol: str
:param orderId: The unique order id
:type orderId: int
:param origClientOrderId: optional
:type origClientOrderId: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
"""
return self._ws_api_request_sync("order.status", True, params)
```
Cancel an active order.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-order-trade)
:param symbol: required - Trading symbol, e.g. 'BTCUSDT'
:type symbol: str
:param orderId: optional - The unique order id
:type orderId: int
:param origClientOrderId: optional - The original client order id
:type origClientOrderId: str
:param newClientOrderId: optional - Used to uniquely identify this cancel. Automatically generated if not sent
:type newClientOrderId: str
:param cancelRestrictions: optional - ONLY\_NEW - Cancel will succeed if the order status is NEW. ONLY\_PARTIALLY\_FILLED - Cancel will succeed if order status is PARTIALLY\_FILLED.
:type cancelRestrictions: str
:param recvWindow: optional - The number of milliseconds the request is valid for
:type recvWindow: int
Either orderId or origClientOrderId must be sent.
Weight: 1
Returns:
.. code-block:: python
\{
"id": "5633b6a2-90a9-4192-83e7-925c90b6a2fd",
"method": "order.cancel",
"params": \{
"symbol": "BTCUSDT",
"origClientOrderId": "4d96324ff9d44481926157",
"apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
"signature": "33d5b721f278ae17a52f004a82a6f68a70c68e7dd6776ed0be77a455ab855282",
"timestamp": 1660801715830
}
}
```python
def ws_cancel_order(self, **params):
"""Cancel an active order.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-order-trade
:param symbol: required - Trading symbol, e.g. 'BTCUSDT'
:type symbol: str
:param orderId: optional - The unique order id
:type orderId: int
:param origClientOrderId: optional - The original client order id
:type origClientOrderId: str
:param newClientOrderId: optional - Used to uniquely identify this cancel. Automatically generated if not sent
:type newClientOrderId: str
:param cancelRestrictions: optional - ONLY_NEW - Cancel will succeed if the order status is NEW. ONLY_PARTIALLY_FILLED - Cancel will succeed if order status is PARTIALLY_FILLED.
:type cancelRestrictions: str
:param recvWindow: optional - The number of milliseconds the request is valid for
:type recvWindow: int
Either orderId or origClientOrderId must be sent.
Weight: 1
Returns:
.. code-block:: python
{
"id": "5633b6a2-90a9-4192-83e7-925c90b6a2fd",
"method": "order.cancel",
"params": {
"symbol": "BTCUSDT",
"origClientOrderId": "4d96324ff9d44481926157",
"apiKey": "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A",
"signature": "33d5b721f278ae17a52f004a82a6f68a70c68e7dd6776ed0be77a455ab855282",
"timestamp": 1660801715830
}
}
"""
return self._ws_api_request_sync("order.cancel", True, params)
```
Cancels an existing order and places a new order on the same symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-and-replace-order-trade](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-and-replace-order-trade)
:param symbol: required - Trading symbol, e.g. 'BTCUSDT'
:type symbol: str
:param cancelReplaceMode: required - The mode of cancel-replace: STOP\_ON\_FAILURE - If the cancel request fails, new order placement will not be attempted. ALLOW\_FAILURE - New order placement will be attempted even if cancel request fails
:type cancelReplaceMode: str
:param cancelOrderId: optional - The order ID to cancel
:type cancelOrderId: int
:param cancelOrigClientOrderId: optional - The original client order ID to cancel
:type cancelOrigClientOrderId: str
:param cancelNewClientOrderId: optional - Used to uniquely identify this cancel. Automatically generated if not sent
:type cancelNewClientOrderId: str
:param side: required - BUY or SELL
:type side: str
:param type: required - Order type, e.g. LIMIT, MARKET
:type type: str
:param timeInForce: optional - GTC, IOC, FOK
:type timeInForce: str
:param price: optional - Order price
:type price: str
:param quantity: optional - Order quantity
:type quantity: str
:param quoteOrderQty: optional - Quote quantity
:type quoteOrderQty: str
:param newClientOrderId: optional - Used to uniquely identify this new order
:type newClientOrderId: str
:param newOrderRespType: optional - ACK, RESULT, or FULL
:type newOrderRespType: str
:param stopPrice: optional - Used with STOP\_LOSS, STOP\_LOSS\_LIMIT, TAKE\_PROFIT, and TAKE\_PROFIT\_LIMIT orders
:type stopPrice: str
:param trailingDelta: optional - Used with TAKE\_PROFIT, TAKE\_PROFIT\_LIMIT, STOP\_LOSS, STOP\_LOSS\_LIMIT orders
:type trailingDelta: int
:param icebergQty: optional - Used with iceberg orders
:type icebergQty: str
:param strategyId: optional - Arbitrary numeric value identifying the order within an order strategy
:type strategyId: int
:param strategyType: optional - Arbitrary numeric value identifying the order strategy
:type strategyType: int
:param selfTradePreventionMode: optional - The allowed enums is dependent on what is configured on the symbol
:type selfTradePreventionMode: str
:param cancelRestrictions: optional - ONLY\_NEW - Cancel will succeed if order status is NEW. ONLY\_PARTIALLY\_FILLED - Cancel will succeed if order status is PARTIALLY\_FILLED
:type cancelRestrictions: str
:param recvWindow: optional - The number of milliseconds the request is valid for
:type recvWindow: int
Either cancelOrderId or cancelOrigClientOrderId must be provided.
Price is required for LIMIT orders.
Either quantity or quoteOrderQty must be provided.
Weight: 1
Returns:
.. code-block:: python
\{
"id": "99de6b92-0eda-4154-9c8d-a51d93c6f92e",
"status": 200,
"result": \{
"cancelResult": "SUCCESS",
"newOrderResult": "SUCCESS",
"cancelResponse": \{
"symbol": "BTCUSDT",
"origClientOrderId": "4d96324ff9d44481926157",
"orderId": 12569099453,
"orderListId": -1,
"clientOrderId": "91fe37ce9e69c90d6358c0",
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00001000",
"cummulativeQuoteQty": "0.23416100",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"selfTradePreventionMode": "NONE"
},
"newOrderResponse": \{
"symbol": "BTCUSDT",
"orderId": 12569099454,
"orderListId": -1,
"clientOrderId": "bX5wROblo6YeDwa9iTLeyY",
"transactTime": 1660801715639
}
}
}
```python
def ws_cancel_and_replace_order(self, **params):
"""Cancels an existing order and places a new order on the same symbol.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-and-replace-order-trade
:param symbol: required - Trading symbol, e.g. 'BTCUSDT'
:type symbol: str
:param cancelReplaceMode: required - The mode of cancel-replace: STOP_ON_FAILURE - If the cancel request fails, new order placement will not be attempted. ALLOW_FAILURE - New order placement will be attempted even if cancel request fails
:type cancelReplaceMode: str
:param cancelOrderId: optional - The order ID to cancel
:type cancelOrderId: int
:param cancelOrigClientOrderId: optional - The original client order ID to cancel
:type cancelOrigClientOrderId: str
:param cancelNewClientOrderId: optional - Used to uniquely identify this cancel. Automatically generated if not sent
:type cancelNewClientOrderId: str
:param side: required - BUY or SELL
:type side: str
:param type: required - Order type, e.g. LIMIT, MARKET
:type type: str
:param timeInForce: optional - GTC, IOC, FOK
:type timeInForce: str
:param price: optional - Order price
:type price: str
:param quantity: optional - Order quantity
:type quantity: str
:param quoteOrderQty: optional - Quote quantity
:type quoteOrderQty: str
:param newClientOrderId: optional - Used to uniquely identify this new order
:type newClientOrderId: str
:param newOrderRespType: optional - ACK, RESULT, or FULL
:type newOrderRespType: str
:param stopPrice: optional - Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders
:type stopPrice: str
:param trailingDelta: optional - Used with TAKE_PROFIT, TAKE_PROFIT_LIMIT, STOP_LOSS, STOP_LOSS_LIMIT orders
:type trailingDelta: int
:param icebergQty: optional - Used with iceberg orders
:type icebergQty: str
:param strategyId: optional - Arbitrary numeric value identifying the order within an order strategy
:type strategyId: int
:param strategyType: optional - Arbitrary numeric value identifying the order strategy
:type strategyType: int
:param selfTradePreventionMode: optional - The allowed enums is dependent on what is configured on the symbol
:type selfTradePreventionMode: str
:param cancelRestrictions: optional - ONLY_NEW - Cancel will succeed if order status is NEW. ONLY_PARTIALLY_FILLED - Cancel will succeed if order status is PARTIALLY_FILLED
:type cancelRestrictions: str
:param recvWindow: optional - The number of milliseconds the request is valid for
:type recvWindow: int
Either cancelOrderId or cancelOrigClientOrderId must be provided.
Price is required for LIMIT orders.
Either quantity or quoteOrderQty must be provided.
Weight: 1
Returns:
.. code-block:: python
{
"id": "99de6b92-0eda-4154-9c8d-a51d93c6f92e",
"status": 200,
"result": {
"cancelResult": "SUCCESS",
"newOrderResult": "SUCCESS",
"cancelResponse": {
"symbol": "BTCUSDT",
"origClientOrderId": "4d96324ff9d44481926157",
"orderId": 12569099453,
"orderListId": -1,
"clientOrderId": "91fe37ce9e69c90d6358c0",
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00001000",
"cummulativeQuoteQty": "0.23416100",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"selfTradePreventionMode": "NONE"
},
"newOrderResponse": {
"symbol": "BTCUSDT",
"orderId": 12569099454,
"orderListId": -1,
"clientOrderId": "bX5wROblo6YeDwa9iTLeyY",
"transactTime": 1660801715639
}
}
}
"""
return self._ws_api_request_sync("order.cancelReplace", True, params)
```
Get all open orders on a symbol or all symbols.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#current-open-orders-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#current-open-orders-user_data)
:param symbol: optional - Symbol to get open orders for
:type symbol: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
Response format:
\[
\{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"orderListId": -1,
"clientOrderId": "4d96324ff9d44481926157",
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00720000",
"cummulativeQuoteQty": "168.59532000",
"status": "PARTIALLY\_FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"icebergQty": "0.00000000",
"time": 1660801715639,
"updateTime": 1660801717945,
"isWorking": true,
"workingTime": 1660801715639,
"origQuoteOrderQty": "0.00000000",
"selfTradePreventionMode": "NONE"
}
]
Weight: Adjusted based on parameters:
* With symbol: 6
* Without symbol: 12
```python
def ws_get_open_orders(self, **params):
"""Get all open orders on a symbol or all symbols.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#current-open-orders-user_data
:param symbol: optional - Symbol to get open orders for
:type symbol: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response
Response format:
[
{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"orderListId": -1,
"clientOrderId": "4d96324ff9d44481926157",
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00720000",
"cummulativeQuoteQty": "168.59532000",
"status": "PARTIALLY_FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"icebergQty": "0.00000000",
"time": 1660801715639,
"updateTime": 1660801717945,
"isWorking": true,
"workingTime": 1660801715639,
"origQuoteOrderQty": "0.00000000",
"selfTradePreventionMode": "NONE"
}
]
Weight: Adjusted based on parameters:
- With symbol: 6
- Without symbol: 12
"""
return self._ws_api_request_sync("openOrders.status", True, params)
```
Cancel all open orders on a symbol or all symbols.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-open-orders-trade](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-open-orders-trade)
:param symbol: optional - Symbol to cancel orders for
:type symbol: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket message
Response format:
\[
\{
"symbol": "BTCUSDT",
"origClientOrderId": "4d96324ff9d44481926157",
"orderId": 12569099453,
"orderListId": -1,
"clientOrderId": "91fe37ce9e69c90d6358c0",
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00847000",
"cummulativeQuoteQty": "198.33521500",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"trailingDelta": 0,
"trailingTime": -1,
"icebergQty": "0.00000000",
"strategyId": 37463720,
"strategyType": 1000000,
"selfTradePreventionMode": "NONE"
}
]
Weight: 1
```python
def ws_cancel_all_open_orders(self, **params):
"""Cancel all open orders on a symbol or all symbols.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-open-orders-trade
:param symbol: optional - Symbol to cancel orders for
:type symbol: str
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket message
Response format:
[
{
"symbol": "BTCUSDT",
"origClientOrderId": "4d96324ff9d44481926157",
"orderId": 12569099453,
"orderListId": -1,
"clientOrderId": "91fe37ce9e69c90d6358c0",
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00847000",
"cummulativeQuoteQty": "198.33521500",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"trailingDelta": 0,
"trailingTime": -1,
"icebergQty": "0.00000000",
"strategyId": 37463720,
"strategyType": 1000000,
"selfTradePreventionMode": "NONE"
}
]
Weight: 1
"""
return self._ws_api_request_sync("openOrders.cancelAll", True, params)
```
Create a new OCO (One-Cancels-the-Other) order.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#place-new-order-list---oco-trade](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#place-new-order-list---oco-trade)
:param symbol: required - Trading symbol
:type symbol: str
:param side: required - BUY or SELL
:type side: str
:param quantity: required - Order quantity
:type quantity: decimal
:param price: required - Order price for limit leg
:type price: decimal
:param stopPrice: required - Stop trigger price for stop leg
:type stopPrice: decimal
:param stopLimitPrice: optional - Stop limit price for stop leg
:type stopLimitPrice: decimal
:param stopLimitTimeInForce: optional - Time in force for stop leg
:type stopLimitTimeInForce: str
:param listClientOrderId: optional - Unique ID for the entire orderList
:type listClientOrderId: str
:param limitClientOrderId: optional - Unique ID for the limit order
:type limitClientOrderId: str
:param stopClientOrderId: optional - Unique ID for the stop order
:type stopClientOrderId: str
:param limitStrategyId: optional - Arbitrary numeric value identifying the limit order within an order strategy
:type limitStrategyId: int
:param limitStrategyType: optional - Arbitrary numeric value identifying the limit order strategy
:type limitStrategyType: int
:param stopStrategyId: optional - Arbitrary numeric value identifying the stop order within an order strategy
:type stopStrategyId: int
:param stopStrategyType: optional - Arbitrary numeric value identifying the stop order strategy
:type stopStrategyType: int
:param limitIcebergQty: optional - Iceberg quantity for the limit leg
:type limitIcebergQty: decimal
:param stopIcebergQty: optional - Iceberg quantity for the stop leg
:type stopIcebergQty: decimal
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket message
Response format:
.. code-block:: python
\{
"id": "56374a46-3261-486b-a211-99ed972eb648",
"status": 200,
"result":
\{
"orderListId": 2,
"contingencyType": "OCO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "cKPMnDCbcLQILtDYM4f4fX",
"transactionTime": 1711062760648,
"symbol": "LTCBNB",
"orders":
\[
\{
"symbol": "LTCBNB",
"orderId": 2,
"clientOrderId": "0m6I4wfxvTUrOBSMUl0OPU"
},
\{
"symbol": "LTCBNB",
"orderId": 3,
"clientOrderId": "Z2IMlR79XNY5LU0tOxrWyW"
}
],
"orderReports":
\[
\{
"symbol": "LTCBNB",
"orderId": 2,
"orderListId": 2,
"clientOrderId": "0m6I4wfxvTUrOBSMUl0OPU",
"transactTime": 1711062760648,
"price": "1.50000000",
"origQty": "1.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "STOP\_LOSS\_LIMIT",
"side": "BUY",
"stopPrice": "1.50000001",
"workingTime": -1,
"selfTradePreventionMode": "NONE"
},
\{
"symbol": "LTCBNB",
"orderId": 3,
"orderListId": 2,
"clientOrderId": "Z2IMlR79XNY5LU0tOxrWyW",
"transactTime": 1711062760648,
"price": "1.49999999",
"origQty": "1.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT\_MAKER",
"side": "BUY",
"workingTime": 1711062760648,
"selfTradePreventionMode": "NONE"
}
]
},
"rateLimits":
\[
\{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 10,
"limit": 50,
"count": 2
},
\{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 160000,
"count": 2
},
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Weight: 2
```python
def ws_create_oco_order(self, **params):
"""Create a new OCO (One-Cancels-the-Other) order.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#place-new-order-list---oco-trade
:param symbol: required - Trading symbol
:type symbol: str
:param side: required - BUY or SELL
:type side: str
:param quantity: required - Order quantity
:type quantity: decimal
:param price: required - Order price for limit leg
:type price: decimal
:param stopPrice: required - Stop trigger price for stop leg
:type stopPrice: decimal
:param stopLimitPrice: optional - Stop limit price for stop leg
:type stopLimitPrice: decimal
:param stopLimitTimeInForce: optional - Time in force for stop leg
:type stopLimitTimeInForce: str
:param listClientOrderId: optional - Unique ID for the entire orderList
:type listClientOrderId: str
:param limitClientOrderId: optional - Unique ID for the limit order
:type limitClientOrderId: str
:param stopClientOrderId: optional - Unique ID for the stop order
:type stopClientOrderId: str
:param limitStrategyId: optional - Arbitrary numeric value identifying the limit order within an order strategy
:type limitStrategyId: int
:param limitStrategyType: optional - Arbitrary numeric value identifying the limit order strategy
:type limitStrategyType: int
:param stopStrategyId: optional - Arbitrary numeric value identifying the stop order within an order strategy
:type stopStrategyId: int
:param stopStrategyType: optional - Arbitrary numeric value identifying the stop order strategy
:type stopStrategyType: int
:param limitIcebergQty: optional - Iceberg quantity for the limit leg
:type limitIcebergQty: decimal
:param stopIcebergQty: optional - Iceberg quantity for the stop leg
:type stopIcebergQty: decimal
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket message
Response format:
.. code-block:: python
{
"id": "56374a46-3261-486b-a211-99ed972eb648",
"status": 200,
"result":
{
"orderListId": 2,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "cKPMnDCbcLQILtDYM4f4fX",
"transactionTime": 1711062760648,
"symbol": "LTCBNB",
"orders":
[
{
"symbol": "LTCBNB",
"orderId": 2,
"clientOrderId": "0m6I4wfxvTUrOBSMUl0OPU"
},
{
"symbol": "LTCBNB",
"orderId": 3,
"clientOrderId": "Z2IMlR79XNY5LU0tOxrWyW"
}
],
"orderReports":
[
{
"symbol": "LTCBNB",
"orderId": 2,
"orderListId": 2,
"clientOrderId": "0m6I4wfxvTUrOBSMUl0OPU",
"transactTime": 1711062760648,
"price": "1.50000000",
"origQty": "1.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "STOP_LOSS_LIMIT",
"side": "BUY",
"stopPrice": "1.50000001",
"workingTime": -1,
"selfTradePreventionMode": "NONE"
},
{
"symbol": "LTCBNB",
"orderId": 3,
"orderListId": 2,
"clientOrderId": "Z2IMlR79XNY5LU0tOxrWyW",
"transactTime": 1711062760648,
"price": "1.49999999",
"origQty": "1.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT_MAKER",
"side": "BUY",
"workingTime": 1711062760648,
"selfTradePreventionMode": "NONE"
}
]
},
"rateLimits":
[
{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 10,
"limit": 50,
"count": 2
},
{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 160000,
"count": 2
},
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Weight: 2
"""
return self._ws_api_request_sync("orderList.place.oco", True, params)
```
Create a new OTO (One-Triggers-Other) order list.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#place-new-order-list---oto-trade](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#place-new-order-list---oto-trade)
An OTO order list consists of two orders:
1. Primary order that must be filled first
2. Secondary order that is placed only after the primary order is filled
:param symbol: required - Trading symbol
:type symbol: str
:param orders: required - Array of order objects containing:
\[
\{ # Primary order
"type": required - Order type (e.g. LIMIT, MARKET),
"side": required - BUY or SELL,
"price": required for LIMIT orders,
"quantity": required - Order quantity,
"timeInForce": required for LIMIT orders,
"icebergQty": optional,
"strategyId": optional,
"strategyType": optional,
"selfTradePreventionMode": optional
},
\{ # Secondary order - same parameters as primary
...
}
]
:type orders: list
:param listClientOrderId: optional - Unique ID for the entire order list
:type listClientOrderId: str
:param limitClientOrderId: optional - Client order ID for the LIMIT leg
:type limitClientOrderId: str
:param limitStrategyId: optional - Strategy ID for the LIMIT leg
:type limitStrategyId: int
:param limitStrategyType: optional - Strategy type for the LIMIT leg
:type limitStrategyType: int
:param stopClientOrderId: optional - Client order ID for the STOP\_LOSS/STOP\_LOSS\_LIMIT leg
:type stopClientOrderId: str
:param stopStrategyId: optional - Strategy ID for the STOP\_LOSS/STOP\_LOSS\_LIMIT leg
:type stopStrategyId: int
:param stopStrategyType: optional - Strategy type for the STOP\_LOSS/STOP\_LOSS\_LIMIT leg
:type stopStrategyType: int
:param newOrderRespType: optional - Set the response JSON
:type newOrderRespType: str
Response example:
.. code-block:: python
\{
"id": "c5899911-d3f4-47ae-8835-97da553d27d0",
"status": 200,
"result": \{
"orderListId": 1,
"contingencyType": "OTO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "C3wyRVh3aqKyI2RpBZYmFz",
"transactionTime": 1669632210676,
"symbol": "BTCUSDT",
"orders": \[
\{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"clientOrderId": "bX5wROblo6YeDwa9iTLeyY"
},
\{
"symbol": "BTCUSDT",
"orderId": 12569099454,
"clientOrderId": "Tnu2IP0J5Y4mxw3IxZYeFi"
}
],
"orderReports": \[
\{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"orderListId": 1,
"clientOrderId": "bX5wROblo6YeDwa9iTLeyY",
"transactTime": 1669632210676,
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00847000",
"cummulativeQuoteQty": "198.33521500",
"status": "FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"workingTime": 1669632210676,
"selfTradePreventionMode": "NONE"
},
\{
"symbol": "BTCUSDT",
"orderId": 12569099454,
"orderListId": 1,
"clientOrderId": "Tnu2IP0J5Y4mxw3IxZYeFi",
"transactTime": 1669632210676,
"price": "0.00000000",
"origQty": "0.00847000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "MARKET",
"side": "BUY",
"stopPrice": "0.00000000",
"workingTime": -1,
"selfTradePreventionMode": "NONE"
}
]
},
"rateLimits": \[
\{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 10,
"limit": 50,
"count": 1
},
\{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 160000,
"count": 1
},
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Weight: 1
```python
def ws_create_oto_order(self, **params):
"""Create a new OTO (One-Triggers-Other) order list.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#place-new-order-list---oto-trade
An OTO order list consists of two orders:
1. Primary order that must be filled first
2. Secondary order that is placed only after the primary order is filled
:param symbol: required - Trading symbol
:type symbol: str
:param orders: required - Array of order objects containing:
[
{ # Primary order
"type": required - Order type (e.g. LIMIT, MARKET),
"side": required - BUY or SELL,
"price": required for LIMIT orders,
"quantity": required - Order quantity,
"timeInForce": required for LIMIT orders,
"icebergQty": optional,
"strategyId": optional,
"strategyType": optional,
"selfTradePreventionMode": optional
},
{ # Secondary order - same parameters as primary
...
}
]
:type orders: list
:param listClientOrderId: optional - Unique ID for the entire order list
:type listClientOrderId: str
:param limitClientOrderId: optional - Client order ID for the LIMIT leg
:type limitClientOrderId: str
:param limitStrategyId: optional - Strategy ID for the LIMIT leg
:type limitStrategyId: int
:param limitStrategyType: optional - Strategy type for the LIMIT leg
:type limitStrategyType: int
:param stopClientOrderId: optional - Client order ID for the STOP_LOSS/STOP_LOSS_LIMIT leg
:type stopClientOrderId: str
:param stopStrategyId: optional - Strategy ID for the STOP_LOSS/STOP_LOSS_LIMIT leg
:type stopStrategyId: int
:param stopStrategyType: optional - Strategy type for the STOP_LOSS/STOP_LOSS_LIMIT leg
:type stopStrategyType: int
:param newOrderRespType: optional - Set the response JSON
:type newOrderRespType: str
Response example:
.. code-block:: python
{
"id": "c5899911-d3f4-47ae-8835-97da553d27d0",
"status": 200,
"result": {
"orderListId": 1,
"contingencyType": "OTO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "C3wyRVh3aqKyI2RpBZYmFz",
"transactionTime": 1669632210676,
"symbol": "BTCUSDT",
"orders": [
{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"clientOrderId": "bX5wROblo6YeDwa9iTLeyY"
},
{
"symbol": "BTCUSDT",
"orderId": 12569099454,
"clientOrderId": "Tnu2IP0J5Y4mxw3IxZYeFi"
}
],
"orderReports": [
{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"orderListId": 1,
"clientOrderId": "bX5wROblo6YeDwa9iTLeyY",
"transactTime": 1669632210676,
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00847000",
"cummulativeQuoteQty": "198.33521500",
"status": "FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"workingTime": 1669632210676,
"selfTradePreventionMode": "NONE"
},
{
"symbol": "BTCUSDT",
"orderId": 12569099454,
"orderListId": 1,
"clientOrderId": "Tnu2IP0J5Y4mxw3IxZYeFi",
"transactTime": 1669632210676,
"price": "0.00000000",
"origQty": "0.00847000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "MARKET",
"side": "BUY",
"stopPrice": "0.00000000",
"workingTime": -1,
"selfTradePreventionMode": "NONE"
}
]
},
"rateLimits": [
{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 10,
"limit": 50,
"count": 1
},
{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 160000,
"count": 1
},
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Weight: 1
"""
return self._ws_api_request_sync("orderList.place.oto", True, params)
```
Returns: Websocket message
.. code-block:: python
\{
"id": "1712544408508",
"status": 200,
"result": \{
"orderListId": 629,
"contingencyType": "OTO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "GaeJHjZPasPItFj4x7Mqm6",
"transactionTime": 1712544408537,
"symbol": "1712544378871",
"orders": \[
\{
"symbol": "1712544378871",
"orderId": 23,
"clientOrderId": "OVQOpKwfmPCfaBTD0n7e7H"
},
\{
"symbol": "1712544378871",
"orderId": 24,
"clientOrderId": "YcCPKCDMQIjNvLtNswt82X"
},
\{
"symbol": "1712544378871",
"orderId": 25,
"clientOrderId": "ilpIoShcFZ1ZGgSASKxMPt"
}
],
"orderReports": \[
\{
"symbol": "LTCBNB",
"orderId": 23,
"orderListId": 629,
"clientOrderId": "OVQOpKwfmPCfaBTD0n7e7H",
"transactTime": 1712544408537,
"price": "1.500000",
"origQty": "1.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"workingTime": 1712544408537,
"selfTradePreventionMode": "NONE"
},
\{
"symbol": "LTCBNB",
"orderId": 24,
"orderListId": 629,
"clientOrderId": "YcCPKCDMQIjNvLtNswt82X",
"transactTime": 1712544408537,
"price": "0.000000",
"origQty": "5.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "PENDING\_NEW",
"timeInForce": "GTC",
"type": "STOP\_LOSS",
"side": "SELL",
"stopPrice": "0.500000",
"workingTime": -1,
"selfTradePreventionMode": "NONE"
},
\{
"symbol": "LTCBNB",
"orderId": 25,
"orderListId": 629,
"clientOrderId": "ilpIoShcFZ1ZGgSASKxMPt",
"transactTime": 1712544408537,
"price": "5.000000",
"origQty": "5.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "PENDING\_NEW",
"timeInForce": "GTC",
"type": "LIMIT\_MAKER",
"side": "SELL",
"workingTime": -1,
"selfTradePreventionMode": "NONE"
}
]
},
"rateLimits": \[
\{
"rateLimitType": "ORDERS",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 10000000,
"count": 18
},
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 1000,
"count": 65
}
]
}
Weight: 1
```python
def ws_create_otoco_order(self, **params):
"""
Returns: Websocket message
.. code-block:: python
{
"id": "1712544408508",
"status": 200,
"result": {
"orderListId": 629,
"contingencyType": "OTO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "GaeJHjZPasPItFj4x7Mqm6",
"transactionTime": 1712544408537,
"symbol": "1712544378871",
"orders": [
{
"symbol": "1712544378871",
"orderId": 23,
"clientOrderId": "OVQOpKwfmPCfaBTD0n7e7H"
},
{
"symbol": "1712544378871",
"orderId": 24,
"clientOrderId": "YcCPKCDMQIjNvLtNswt82X"
},
{
"symbol": "1712544378871",
"orderId": 25,
"clientOrderId": "ilpIoShcFZ1ZGgSASKxMPt"
}
],
"orderReports": [
{
"symbol": "LTCBNB",
"orderId": 23,
"orderListId": 629,
"clientOrderId": "OVQOpKwfmPCfaBTD0n7e7H",
"transactTime": 1712544408537,
"price": "1.500000",
"origQty": "1.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "NEW",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"workingTime": 1712544408537,
"selfTradePreventionMode": "NONE"
},
{
"symbol": "LTCBNB",
"orderId": 24,
"orderListId": 629,
"clientOrderId": "YcCPKCDMQIjNvLtNswt82X",
"transactTime": 1712544408537,
"price": "0.000000",
"origQty": "5.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "PENDING_NEW",
"timeInForce": "GTC",
"type": "STOP_LOSS",
"side": "SELL",
"stopPrice": "0.500000",
"workingTime": -1,
"selfTradePreventionMode": "NONE"
},
{
"symbol": "LTCBNB",
"orderId": 25,
"orderListId": 629,
"clientOrderId": "ilpIoShcFZ1ZGgSASKxMPt",
"transactTime": 1712544408537,
"price": "5.000000",
"origQty": "5.000000",
"executedQty": "0.000000",
"origQuoteOrderQty": "0.000000",
"cummulativeQuoteQty": "0.000000",
"status": "PENDING_NEW",
"timeInForce": "GTC",
"type": "LIMIT_MAKER",
"side": "SELL",
"workingTime": -1,
"selfTradePreventionMode": "NONE"
}
]
},
"rateLimits": [
{
"rateLimitType": "ORDERS",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 10000000,
"count": 18
},
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 1000,
"count": 65
}
]
}
Weight: 1
"""
return self._ws_api_request_sync("orderList.place.otoco", True, params)
```
Query information about a specific OCO order list.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#query-order-list-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#query-order-list-user_data)
:param orderListId: int - The identifier for the OCO order list (optional)
:param origClientOrderId: str - The client-specified OCO order list ID (optional)
:returns: API response containing OCO order list information including:
.. code-block:: python
\{
"id": "b53fd5ff-82c7-4a04-bd64-5f9dc42c2100",
"status": 200,
"result": \{
"orderListId": 1274512,
"contingencyType": "OCO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "08985fedd9ea2cf6b28996",
"transactionTime": 1660801713793,
"symbol": "BTCUSDT",
"orders": \[
\{
"symbol": "BTCUSDT",
"orderId": 12569138901,
"clientOrderId": "BqtFCj5odMoWtSqGk2X9tU"
},
\{
"symbol": "BTCUSDT",
"orderId": 12569138902,
"clientOrderId": "jLnZpj5enfMXTuhKB1d0us"
}
]
},
"rateLimits": \[
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 4
}
]
}
Notes:
* Either orderListId or origClientOrderId must be provided
* Weight: 4
* Data Source: Database
```python
def ws_get_oco_order(self, **params):
"""Query information about a specific OCO order list.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#query-order-list-user_data
:param orderListId: int - The identifier for the OCO order list (optional)
:param origClientOrderId: str - The client-specified OCO order list ID (optional)
:returns: API response containing OCO order list information including:
.. code-block:: python
{
"id": "b53fd5ff-82c7-4a04-bd64-5f9dc42c2100",
"status": 200,
"result": {
"orderListId": 1274512,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "08985fedd9ea2cf6b28996",
"transactionTime": 1660801713793,
"symbol": "BTCUSDT",
"orders": [
{
"symbol": "BTCUSDT",
"orderId": 12569138901,
"clientOrderId": "BqtFCj5odMoWtSqGk2X9tU"
},
{
"symbol": "BTCUSDT",
"orderId": 12569138902,
"clientOrderId": "jLnZpj5enfMXTuhKB1d0us"
}
]
},
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 4
}
]
}
Notes:
- Either orderListId or origClientOrderId must be provided
- Weight: 4
- Data Source: Database
"""
return self._ws_api_request_sync("orderList.status", True, params)
```
Cancel an OCO (One-Cancels-the-Other) order list.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-order-list-trade](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-order-list-trade)
:param symbol: required - Trading symbol
:type symbol: str
:param orderListId: optional - The ID of the OCO order list to cancel
:type orderListId: int
:param listClientOrderId: optional - The client-specified ID of the OCO order list
:type listClientOrderId: str
:param newClientOrderId: optional - Client ID to identify the cancel request
:type newClientOrderId: str
:param apiKey: required - Your API key
:type apiKey: str
:param recvWindow: optional - Number of milliseconds the request is valid for
:type recvWindow: int
:param signature: required - HMAC SHA256 signature
:type signature: str
:param timestamp: required - Current timestamp in milliseconds
:type timestamp: int
**Notes**:
* Either orderListId or listClientOrderId must be provided
* newClientOrderId will be auto-generated if not provided
Response example:
.. code-block:: python
\{
"id": "c5899911-d3f4-47ae-8835-97da553d27d0",
"status": 200,
"result": \{
"orderListId": 1274512,
"contingencyType": "OCO",
"listStatusType": "ALL\_DONE",
"listOrderStatus": "ALL\_DONE",
"listClientOrderId": "6023531d7edaad348f5aff",
"transactionTime": 1660801720215,
"symbol": "BTCUSDT",
"orders": \[
\{
"symbol": "BTCUSDT",
"orderId": 12569138901,
"clientOrderId": "BqtFCj5odMoWtSqGk2X9tU"
},
\{
"symbol": "BTCUSDT",
"orderId": 12569138902,
"clientOrderId": "jLnZpj5enfMXTuhKB1d0us"
}
],
"orderReports": \[
\{
"symbol": "BTCUSDT",
"orderId": 12569138901,
"orderListId": 1274512,
"clientOrderId": "BqtFCj5odMoWtSqGk2X9tU",
"transactTime": 1660801720215,
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "STOP\_LOSS\_LIMIT",
"side": "SELL",
"stopPrice": "23416.10000000",
"selfTradePreventionMode": "NONE"
},
\{
"symbol": "BTCUSDT",
"orderId": 12569138902,
"orderListId": 1274512,
"clientOrderId": "jLnZpj5enfMXTuhKB1d0us",
"transactTime": 1660801720215,
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT\_MAKER",
"side": "SELL",
"selfTradePreventionMode": "NONE"
}
]
},
"rateLimits": \[
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
```python
def ws_cancel_oco_order(self, **params):
"""Cancel an OCO (One-Cancels-the-Other) order list.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#cancel-order-list-trade
:param symbol: required - Trading symbol
:type symbol: str
:param orderListId: optional - The ID of the OCO order list to cancel
:type orderListId: int
:param listClientOrderId: optional - The client-specified ID of the OCO order list
:type listClientOrderId: str
:param newClientOrderId: optional - Client ID to identify the cancel request
:type newClientOrderId: str
:param apiKey: required - Your API key
:type apiKey: str
:param recvWindow: optional - Number of milliseconds the request is valid for
:type recvWindow: int
:param signature: required - HMAC SHA256 signature
:type signature: str
:param timestamp: required - Current timestamp in milliseconds
:type timestamp: int
**Notes**:
- Either orderListId or listClientOrderId must be provided
- newClientOrderId will be auto-generated if not provided
Response example:
.. code-block:: python
{
"id": "c5899911-d3f4-47ae-8835-97da553d27d0",
"status": 200,
"result": {
"orderListId": 1274512,
"contingencyType": "OCO",
"listStatusType": "ALL_DONE",
"listOrderStatus": "ALL_DONE",
"listClientOrderId": "6023531d7edaad348f5aff",
"transactionTime": 1660801720215,
"symbol": "BTCUSDT",
"orders": [
{
"symbol": "BTCUSDT",
"orderId": 12569138901,
"clientOrderId": "BqtFCj5odMoWtSqGk2X9tU"
},
{
"symbol": "BTCUSDT",
"orderId": 12569138902,
"clientOrderId": "jLnZpj5enfMXTuhKB1d0us"
}
],
"orderReports": [
{
"symbol": "BTCUSDT",
"orderId": 12569138901,
"orderListId": 1274512,
"clientOrderId": "BqtFCj5odMoWtSqGk2X9tU",
"transactTime": 1660801720215,
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "STOP_LOSS_LIMIT",
"side": "SELL",
"stopPrice": "23416.10000000",
"selfTradePreventionMode": "NONE"
},
{
"symbol": "BTCUSDT",
"orderId": 12569138902,
"orderListId": 1274512,
"clientOrderId": "jLnZpj5enfMXTuhKB1d0us",
"transactTime": 1660801720215,
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00000000",
"cummulativeQuoteQty": "0.00000000",
"status": "CANCELED",
"timeInForce": "GTC",
"type": "LIMIT_MAKER",
"side": "SELL",
"selfTradePreventionMode": "NONE"
}
]
},
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
"""
return self._ws_api_request_sync("orderList.cancel", True, params)
```
Query current open OCO (One-Cancels-the-Other) order lists.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#current-open-order-lists-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#current-open-order-lists-user_data)
:param recvWindow: optional - Number of milliseconds after timestamp the request is valid for. Default 5000, max 60000
:type recvWindow: int
:param apiKey: required - Your API key
:type apiKey: str
:param signature: required - HMAC SHA256 signature
:type signature: str
:param timestamp: required - Current timestamp in milliseconds
:type timestamp: int
:returns: API response in JSON format with open OCO orders
\{
"id": "c5899911-d3f5-47b3-9b67-4c1342f2a7e1",
"status": 200,
"result": \[
\{
"orderListId": 1274512,
"contingencyType": "OCO",
"listStatusType": "EXEC\_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "08985fedd9ea2cf6b28996",
"transactionTime": 1660801713793,
"symbol": "BTCUSDT",
"orders": \[
\{
"symbol": "BTCUSDT",
"orderId": 12569138901,
"clientOrderId": "BqtFCj5odMoWtSqGk2X9tU"
},
\{
"symbol": "BTCUSDT",
"orderId": 12569138902,
"clientOrderId": "jLnZpj5enfMXTuhKB1d0us"
}
]
}
],
"rateLimits": \[
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 10
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Weight: 10
Data Source: Memory
```python
def ws_get_oco_open_orders(self, **params):
"""Query current open OCO (One-Cancels-the-Other) order lists.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#current-open-order-lists-user_data
:param recvWindow: optional - Number of milliseconds after timestamp the request is valid for. Default 5000, max 60000
:type recvWindow: int
:param apiKey: required - Your API key
:type apiKey: str
:param signature: required - HMAC SHA256 signature
:type signature: str
:param timestamp: required - Current timestamp in milliseconds
:type timestamp: int
:returns: API response in JSON format with open OCO orders
{
"id": "c5899911-d3f5-47b3-9b67-4c1342f2a7e1",
"status": 200,
"result": [
{
"orderListId": 1274512,
"contingencyType": "OCO",
"listStatusType": "EXEC_STARTED",
"listOrderStatus": "EXECUTING",
"listClientOrderId": "08985fedd9ea2cf6b28996",
"transactionTime": 1660801713793,
"symbol": "BTCUSDT",
"orders": [
{
"symbol": "BTCUSDT",
"orderId": 12569138901,
"clientOrderId": "BqtFCj5odMoWtSqGk2X9tU"
},
{
"symbol": "BTCUSDT",
"orderId": 12569138902,
"clientOrderId": "jLnZpj5enfMXTuhKB1d0us"
}
]
}
],
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 10
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Weight: 10
Data Source: Memory
"""
return self._ws_api_request_sync("openOrderLists.status", True, params)
```
Place a new order using Smart Order Routing (SOR).
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#place-new-order-using-sor-trade](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#place-new-order-using-sor-trade)
:param symbol: required - Trading symbol, e.g. BTCUSDT
:type symbol: str
:param side: required - Order side: BUY or SELL
:type side: str
:param type: required - Order type: LIMIT or MARKET
:type type: str
:param quantity: required - Order quantity
:type quantity: float
:param timeInForce: required for LIMIT orders - Time in force: GTC, IOC, FOK
:type timeInForce: str
:param price: required for LIMIT orders - Order price
:type price: float
:param newClientOrderId: optional - Unique order ID. Automatically generated if not sent
:type newClientOrderId: str
:param newOrderRespType: optional - Response format: ACK, RESULT, FULL. MARKET and LIMIT orders use FULL by default
:type newOrderRespType: str
:param strategyId: optional - Arbitrary numeric value identifying the order within an order strategy
:type strategyId: int
:param strategyType: optional - Arbitrary numeric value identifying the order strategy. Values \< 1000000 are reserved
:type strategyType: int
:param selfTradePreventionMode: optional - Supported values depend on exchange configuration: EXPIRE\_TAKER, EXPIRE\_MAKER, EXPIRE\_BOTH, NONE
:type selfTradePreventionMode: str
:param recvWindow: optional - Number of milliseconds after timestamp the request is valid for. Default 5000, max 60000
:type recvWindow: int
:returns: Websocket message
.. code-block:: python
\{
"id": "3a4437e2-41a3-4c19-897c-9cadc5dce8b6",
"status": 200,
"result": \[
\{
"symbol": "BTCUSDT",
"orderId": 2,
"orderListId": -1,
"clientOrderId": "sBI1KM6nNtOfj5tccZSKly",
"transactTime": 1689149087774,
"price": "31000.00000000",
"origQty": "0.50000000",
"executedQty": "0.50000000",
"cummulativeQuoteQty": "14000.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"workingTime": 1689149087774,
"fills": \[
\{
"matchType": "ONE\_PARTY\_TRADE\_REPORT",
"price": "28000.00000000",
"qty": "0.50000000",
"commission": "0.00000000",
"commissionAsset": "BTC",
"tradeId": -1,
"allocId": 0
}
],
"workingFloor": "SOR",
"selfTradePreventionMode": "NONE",
"usedSor": true
}
],
"rateLimits": \[
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Notes:
* SOR only supports LIMIT and MARKET orders
* quoteOrderQty is not supported
* Weight: 1
* Data Source: Matching Engine
```python
def ws_create_sor_order(self, **params):
"""Place a new order using Smart Order Routing (SOR).
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#place-new-order-using-sor-trade
:param symbol: required - Trading symbol, e.g. BTCUSDT
:type symbol: str
:param side: required - Order side: BUY or SELL
:type side: str
:param type: required - Order type: LIMIT or MARKET
:type type: str
:param quantity: required - Order quantity
:type quantity: float
:param timeInForce: required for LIMIT orders - Time in force: GTC, IOC, FOK
:type timeInForce: str
:param price: required for LIMIT orders - Order price
:type price: float
:param newClientOrderId: optional - Unique order ID. Automatically generated if not sent
:type newClientOrderId: str
:param newOrderRespType: optional - Response format: ACK, RESULT, FULL. MARKET and LIMIT orders use FULL by default
:type newOrderRespType: str
:param strategyId: optional - Arbitrary numeric value identifying the order within an order strategy
:type strategyId: int
:param strategyType: optional - Arbitrary numeric value identifying the order strategy. Values < 1000000 are reserved
:type strategyType: int
:param selfTradePreventionMode: optional - Supported values depend on exchange configuration: EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH, NONE
:type selfTradePreventionMode: str
:param recvWindow: optional - Number of milliseconds after timestamp the request is valid for. Default 5000, max 60000
:type recvWindow: int
:returns: Websocket message
.. code-block:: python
{
"id": "3a4437e2-41a3-4c19-897c-9cadc5dce8b6",
"status": 200,
"result": [
{
"symbol": "BTCUSDT",
"orderId": 2,
"orderListId": -1,
"clientOrderId": "sBI1KM6nNtOfj5tccZSKly",
"transactTime": 1689149087774,
"price": "31000.00000000",
"origQty": "0.50000000",
"executedQty": "0.50000000",
"cummulativeQuoteQty": "14000.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "BUY",
"workingTime": 1689149087774,
"fills": [
{
"matchType": "ONE_PARTY_TRADE_REPORT",
"price": "28000.00000000",
"qty": "0.50000000",
"commission": "0.00000000",
"commissionAsset": "BTC",
"tradeId": -1,
"allocId": 0
}
],
"workingFloor": "SOR",
"selfTradePreventionMode": "NONE",
"usedSor": true
}
],
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Notes:
- SOR only supports LIMIT and MARKET orders
- quoteOrderQty is not supported
- Weight: 1
- Data Source: Matching Engine
"""
return self._ws_api_request_sync("sor.order.place", True, params)
```
Test new order creation using Smart Order Routing (SOR).
Creates and validates a new order but does not send it into the matching engine.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#test-new-order-using-sor-trade](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#test-new-order-using-sor-trade)
:param symbol: required - Trading symbol, e.g. BTCUSDT
:type symbol: str
:param side: required - Order side: BUY or SELL
:type side: str
:param type: required - Order type: LIMIT or MARKET
:type type: str
:param quantity: required - Order quantity
:type quantity: float
:param timeInForce: required for LIMIT orders - Time in force: GTC, IOC, FOK
:type timeInForce: str
:param price: required for LIMIT orders - Order price
:type price: float
:param newClientOrderId: optional - Unique order ID. Generated automatically if not sent
:type newClientOrderId: str
:param strategyId: optional - Arbitrary numeric value identifying the order within an order strategy
:type strategyId: int
:param strategyType: optional - Arbitrary numeric value identifying the order strategy. Values \< 1000000 are reserved
:type strategyType: int
:param selfTradePreventionMode: optional - EXPIRE\_TAKER, EXPIRE\_MAKER, EXPIRE\_BOTH, NONE
:type selfTradePreventionMode: str
:param computeCommissionRates: optional - Calculate commission rates. Default: False
:type computeCommissionRates: bool
:returns: Websocket message
Without computeCommissionRates:
.. code-block:: python
\{
"id": "3a4437e2-41a3-4c19-897c-9cadc5dce8b6",
"status": 200,
"result": \{},
"rateLimits": \[
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
With computeCommissionRates:
.. code-block:: python
\{
"id": "3a4437e2-41a3-4c19-897c-9cadc5dce8b6",
"status": 200,
"result": \{
"standardCommissionForOrder": \{
"maker": "0.00000112",
"taker": "0.00000114"
},
"taxCommissionForOrder": \{
"maker": "0.00000112",
"taker": "0.00000114"
},
"discount": \{
"enabledForAccount": true,
"enabledForSymbol": true,
"discountAsset": "BNB",
"discount": "0.25"
}
},
"rateLimits": \[...]
}
Notes:
* SOR only supports LIMIT and MARKET orders
* quoteOrderQty is not supported
* Weight: 1 (without computeCommissionRates), 20 (with computeCommissionRates)
* Data Source: Memory
```python
def ws_create_test_sor_order(self, **params):
"""Test new order creation using Smart Order Routing (SOR).
Creates and validates a new order but does not send it into the matching engine.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#test-new-order-using-sor-trade
:param symbol: required - Trading symbol, e.g. BTCUSDT
:type symbol: str
:param side: required - Order side: BUY or SELL
:type side: str
:param type: required - Order type: LIMIT or MARKET
:type type: str
:param quantity: required - Order quantity
:type quantity: float
:param timeInForce: required for LIMIT orders - Time in force: GTC, IOC, FOK
:type timeInForce: str
:param price: required for LIMIT orders - Order price
:type price: float
:param newClientOrderId: optional - Unique order ID. Generated automatically if not sent
:type newClientOrderId: str
:param strategyId: optional - Arbitrary numeric value identifying the order within an order strategy
:type strategyId: int
:param strategyType: optional - Arbitrary numeric value identifying the order strategy. Values < 1000000 are reserved
:type strategyType: int
:param selfTradePreventionMode: optional - EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH, NONE
:type selfTradePreventionMode: str
:param computeCommissionRates: optional - Calculate commission rates. Default: False
:type computeCommissionRates: bool
:returns: Websocket message
Without computeCommissionRates:
.. code-block:: python
{
"id": "3a4437e2-41a3-4c19-897c-9cadc5dce8b6",
"status": 200,
"result": {},
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
With computeCommissionRates:
.. code-block:: python
{
"id": "3a4437e2-41a3-4c19-897c-9cadc5dce8b6",
"status": 200,
"result": {
"standardCommissionForOrder": {
"maker": "0.00000112",
"taker": "0.00000114"
},
"taxCommissionForOrder": {
"maker": "0.00000112",
"taker": "0.00000114"
},
"discount": {
"enabledForAccount": true,
"enabledForSymbol": true,
"discountAsset": "BNB",
"discount": "0.25"
}
},
"rateLimits": [...]
}
Notes:
- SOR only supports LIMIT and MARKET orders
- quoteOrderQty is not supported
- Weight: 1 (without computeCommissionRates), 20 (with computeCommissionRates)
- Data Source: Memory
"""
return self._ws_api_request_sync("sor.order.test", True, params)
```
Get current account information.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-information-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-information-user_data)
:param omitZeroBalances: optional - When set to true, emits only the non-zero balances of an account. Default: false
:type omitZeroBalances: bool
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket message
.. code-block:: python
\{
"makerCommission": 15,
"takerCommission": 15,
"buyerCommission": 0,
"sellerCommission": 0,
"canTrade": true,
"canWithdraw": true,
"canDeposit": true,
"commissionRates": \{
"maker": "0.00150000",
"taker": "0.00150000",
"buyer": "0.00000000",
"seller": "0.00000000"
},
"brokered": false,
"requireSelfTradePrevention": false,
"preventSor": false,
"updateTime": 1660801833000,
"accountType": "SPOT",
"balances": \[
\{
"asset": "BNB",
"free": "0.00000000",
"locked": "0.00000000"
},
\{
"asset": "BTC",
"free": "1.34471120",
"locked": "0.08600000"
}
],
"permissions": \[
"SPOT"
],
"uid": 354937868
}
Notes:
* Weight: 20
* Data Source: Memory => Database
```python
def ws_get_account(self, **params):
"""Get current account information.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-information-user_data
:param omitZeroBalances: optional - When set to true, emits only the non-zero balances of an account. Default: false
:type omitZeroBalances: bool
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket message
.. code-block:: python
{
"makerCommission": 15,
"takerCommission": 15,
"buyerCommission": 0,
"sellerCommission": 0,
"canTrade": true,
"canWithdraw": true,
"canDeposit": true,
"commissionRates": {
"maker": "0.00150000",
"taker": "0.00150000",
"buyer": "0.00000000",
"seller": "0.00000000"
},
"brokered": false,
"requireSelfTradePrevention": false,
"preventSor": false,
"updateTime": 1660801833000,
"accountType": "SPOT",
"balances": [
{
"asset": "BNB",
"free": "0.00000000",
"locked": "0.00000000"
},
{
"asset": "BTC",
"free": "1.34471120",
"locked": "0.08600000"
}
],
"permissions": [
"SPOT"
],
"uid": 354937868
}
Notes:
- Weight: 20
- Data Source: Memory => Database
"""
return self._ws_api_request_sync("account.status", True, params)
```
Query your current unfilled order count for all intervals.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-unfilled-order-count-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-unfilled-order-count-user_data)
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket response
.. code-block:: python
\{
"result": \[
\{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 10,
"limit": 50,
"count": 0
},
\{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 160000,
"count": 0
}
],
"id": "d3783d8d-f8d1-4d2c-b8a0-b7596af5a664"
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
* Weight: 40
* Data Source: Memory
```python
def ws_get_account_rate_limits_orders(self, **params):
"""Query your current unfilled order count for all intervals.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-unfilled-order-count-user_data
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket response
.. code-block:: python
{
"result": [
{
"rateLimitType": "ORDERS",
"interval": "SECOND",
"intervalNum": 10,
"limit": 50,
"count": 0
},
{
"rateLimitType": "ORDERS",
"interval": "DAY",
"intervalNum": 1,
"limit": 160000,
"count": 0
}
],
"id": "d3783d8d-f8d1-4d2c-b8a0-b7596af5a664"
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
- Weight: 40
- Data Source: Memory
"""
return self._ws_api_request_sync("account.rateLimits.orders", True, params)
```
Query information about all your orders – active, canceled, filled – filtered by time range.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-order-history-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-order-history-user_data)
:param symbol: STRING - Required
:type symbol: str
:param orderId: optional - Order ID to begin at
:type orderId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional - Default 500; max 1000
:type limit: int
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket response
.. code-block:: python
\{
"id": "734235c2-13d2-4574-be68-723e818c08f3",
"status": 200,
"result": \[
\{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"orderListId": -1,
"clientOrderId": "4d96324ff9d44481926157",
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00847000",
"cummulativeQuoteQty": "198.33521500",
"status": "FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"icebergQty": "0.00000000",
"time": 1660801715639,
"updateTime": 1660801717945,
"isWorking": true,
"workingTime": 1660801715639,
"origQuoteOrderQty": "0.00000000",
"selfTradePreventionMode": "NONE",
"preventedMatchId": 0, // Only appears if order expired due to STP
"preventedQuantity": "1.200000" // Only appears if order expired due to STP
}
]
}
Notes:
* Weight: 20
* Data Source: Database
* If startTime and/or endTime are specified, orderId is ignored
* Orders are filtered by time of the last execution status update
* If orderId is specified, return orders with order ID >= orderId
* If no condition is specified, the most recent orders are returned
* For some historical orders the cummulativeQuoteQty response field may be negative
* The time between startTime and endTime can't be longer than 24 hours
```python
def ws_get_all_orders(self, **params):
"""Query information about all your orders – active, canceled, filled – filtered by time range.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-order-history-user_data
:param symbol: STRING - Required
:type symbol: str
:param orderId: optional - Order ID to begin at
:type orderId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param limit: optional - Default 500; max 1000
:type limit: int
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket response
.. code-block:: python
{
"id": "734235c2-13d2-4574-be68-723e818c08f3",
"status": 200,
"result": [
{
"symbol": "BTCUSDT",
"orderId": 12569099453,
"orderListId": -1,
"clientOrderId": "4d96324ff9d44481926157",
"price": "23416.10000000",
"origQty": "0.00847000",
"executedQty": "0.00847000",
"cummulativeQuoteQty": "198.33521500",
"status": "FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL",
"stopPrice": "0.00000000",
"icebergQty": "0.00000000",
"time": 1660801715639,
"updateTime": 1660801717945,
"isWorking": true,
"workingTime": 1660801715639,
"origQuoteOrderQty": "0.00000000",
"selfTradePreventionMode": "NONE",
"preventedMatchId": 0, // Only appears if order expired due to STP
"preventedQuantity": "1.200000" // Only appears if order expired due to STP
}
]
}
Notes:
- Weight: 20
- Data Source: Database
- If startTime and/or endTime are specified, orderId is ignored
- Orders are filtered by time of the last execution status update
- If orderId is specified, return orders with order ID >= orderId
- If no condition is specified, the most recent orders are returned
- For some historical orders the cummulativeQuoteQty response field may be negative
- The time between startTime and endTime can't be longer than 24 hours
"""
return self._ws_api_request_sync("allOrders", True, params)
```
Query information about your trades, filtered by time range.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-trade-history-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-trade-history-user_data)
:param symbol: STRING - Required
:type symbol: str
:param orderId: optional - Get trades for a specific order
:type orderId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param fromId: optional - Trade ID to fetch from
:type fromId: int
:param limit: optional - Default 500; max 1000
:type limit: int
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket response
.. code-block:: python
\[
\{
"symbol": "BTCUSDT",
"id": 1650422481,
"orderId": 12569099453,
"orderListId": -1,
"price": "23416.10000000",
"qty": "0.00635000",
"quoteQty": "148.69223500",
"commission": "0.00000000",
"commissionAsset": "BNB",
"time": 1660801715793,
"isBuyer": false,
"isMaker": true,
"isBestMatch": true
}
]
Notes:
* Weight: 20
* Data Source: Memory => Database
* If fromId is specified, return trades with trade ID >= fromId
* If startTime and/or endTime are specified, trades are filtered by execution time (time)
* fromId cannot be used together with startTime and endTime
* If orderId is specified, only trades related to that order are returned
* startTime and endTime cannot be used together with orderId
* If no condition is specified, the most recent trades are returned
* The time between startTime and endTime can't be longer than 24 hours
```python
def ws_get_my_trades(self, **params):
"""Query information about your trades, filtered by time range.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-trade-history-user_data
:param symbol: STRING - Required
:type symbol: str
:param orderId: optional - Get trades for a specific order
:type orderId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param fromId: optional - Trade ID to fetch from
:type fromId: int
:param limit: optional - Default 500; max 1000
:type limit: int
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket response
.. code-block:: python
[
{
"symbol": "BTCUSDT",
"id": 1650422481,
"orderId": 12569099453,
"orderListId": -1,
"price": "23416.10000000",
"qty": "0.00635000",
"quoteQty": "148.69223500",
"commission": "0.00000000",
"commissionAsset": "BNB",
"time": 1660801715793,
"isBuyer": false,
"isMaker": true,
"isBestMatch": true
}
]
Notes:
- Weight: 20
- Data Source: Memory => Database
- If fromId is specified, return trades with trade ID >= fromId
- If startTime and/or endTime are specified, trades are filtered by execution time (time)
- fromId cannot be used together with startTime and endTime
- If orderId is specified, only trades related to that order are returned
- startTime and endTime cannot be used together with orderId
- If no condition is specified, the most recent trades are returned
- The time between startTime and endTime can't be longer than 24 hours
"""
return self._ws_api_request_sync("myTrades", True, params)
```
Displays the list of orders that were expired due to STP (Self-Trade Prevention).
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-prevented-matches-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-prevented-matches-user_data)
:param symbol: STRING - Required
:type symbol: str
:param preventedMatchId: optional - Get specific prevented match by ID
:type preventedMatchId: int
:param orderId: optional - Get prevented matches for specific order
:type orderId: int
:param fromPreventedMatchId: optional - Get prevented matches from this ID
:type fromPreventedMatchId: int
:param limit: optional - Default 500; max 1000
:type limit: int
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket response
.. code-block:: python
\{
"symbol": "BTCUSDT", # Trading pair
"preventedMatchId": 1, # Unique ID for prevented match
"takerOrderId": 5, # Order ID of the taker order
"makerSymbol": "BTCUSDT", # Symbol of maker order
"makerOrderId": 3, # Order ID of maker order
"tradeGroupId": 1, # Trade group ID
"selfTradePreventionMode": "EXPIRE\_MAKER", # STP mode used
"price": "1.100000", # Price level where match was prevented
"makerPreventedQuantity": "1.300000", # Quantity that was prevented
"transactTime": 1669101687094 # Time of prevention
}
Supported parameter combinations:
* symbol + preventedMatchId
* symbol + orderId
* symbol + orderId + fromPreventedMatchId (limit defaults to 500)
* symbol + orderId + fromPreventedMatchId + limit
Weight:
* 2 if symbol is invalid
* 2 when querying by preventedMatchId
* 20 when querying by orderId
Data Source: Database
```python
def ws_get_prevented_matches(self, **params):
"""Displays the list of orders that were expired due to STP (Self-Trade Prevention).
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-prevented-matches-user_data
:param symbol: STRING - Required
:type symbol: str
:param preventedMatchId: optional - Get specific prevented match by ID
:type preventedMatchId: int
:param orderId: optional - Get prevented matches for specific order
:type orderId: int
:param fromPreventedMatchId: optional - Get prevented matches from this ID
:type fromPreventedMatchId: int
:param limit: optional - Default 500; max 1000
:type limit: int
:param recvWindow: optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: Websocket response
.. code-block:: python
{
"symbol": "BTCUSDT", # Trading pair
"preventedMatchId": 1, # Unique ID for prevented match
"takerOrderId": 5, # Order ID of the taker order
"makerSymbol": "BTCUSDT", # Symbol of maker order
"makerOrderId": 3, # Order ID of maker order
"tradeGroupId": 1, # Trade group ID
"selfTradePreventionMode": "EXPIRE_MAKER", # STP mode used
"price": "1.100000", # Price level where match was prevented
"makerPreventedQuantity": "1.300000", # Quantity that was prevented
"transactTime": 1669101687094 # Time of prevention
}
Supported parameter combinations:
- symbol + preventedMatchId
- symbol + orderId
- symbol + orderId + fromPreventedMatchId (limit defaults to 500)
- symbol + orderId + fromPreventedMatchId + limit
Weight:
- 2 if symbol is invalid
- 2 when querying by preventedMatchId
- 20 when querying by orderId
Data Source: Database
"""
return self._ws_api_request_sync("myPreventedMatches", True, params)
```
Get information about orders that were expired due to STP (Self-Trade Prevention).
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-prevented-matches-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-prevented-matches-user_data)
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param preventedMatchId: LONG - Optional - Get specific prevented match by ID
:type preventedMatchId: int
:param orderId: LONG - Optional - Get prevented matches for specific order
:type orderId: int
:param fromPreventedMatchId: LONG - Optional - Get prevented matches from this ID
:type fromPreventedMatchId: int
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
:param recvWindow: LONG - Optional - The value cannot be greater than 60000
:type recvWindow: int
:param timestamp: LONG - Required
:type timestamp: int
:returns: API response
.. code-block:: python
\{
"symbol": "BTCUSDT",
"preventedMatchId": 1,
"takerOrderId": 5,
"makerSymbol": "BTCUSDT",
"makerOrderId": 3,
"tradeGroupId": 1,
"selfTradePreventionMode": "EXPIRE\_MAKER",
"price": "1.100000",
"makerPreventedQuantity": "1.300000",
"transactTime": 1669101687094
}
Supported parameter combinations:
* symbol + preventedMatchId
* symbol + orderId
* symbol + orderId + fromPreventedMatchId (limit defaults to 500)
* symbol + orderId + fromPreventedMatchId + limit
Weight:
* 2 if symbol is invalid
* 2 when querying by preventedMatchId
* 20 when querying by orderId
Data Source: Database
```python
def ws_get_allocations(self, **params):
"""Get information about orders that were expired due to STP (Self-Trade Prevention).
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-prevented-matches-user_data
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param preventedMatchId: LONG - Optional - Get specific prevented match by ID
:type preventedMatchId: int
:param orderId: LONG - Optional - Get prevented matches for specific order
:type orderId: int
:param fromPreventedMatchId: LONG - Optional - Get prevented matches from this ID
:type fromPreventedMatchId: int
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
:param recvWindow: LONG - Optional - The value cannot be greater than 60000
:type recvWindow: int
:param timestamp: LONG - Required
:type timestamp: int
:returns: API response
.. code-block:: python
{
"symbol": "BTCUSDT",
"preventedMatchId": 1,
"takerOrderId": 5,
"makerSymbol": "BTCUSDT",
"makerOrderId": 3,
"tradeGroupId": 1,
"selfTradePreventionMode": "EXPIRE_MAKER",
"price": "1.100000",
"makerPreventedQuantity": "1.300000",
"transactTime": 1669101687094
}
Supported parameter combinations:
- symbol + preventedMatchId
- symbol + orderId
- symbol + orderId + fromPreventedMatchId (limit defaults to 500)
- symbol + orderId + fromPreventedMatchId + limit
Weight:
- 2 if symbol is invalid
- 2 when querying by preventedMatchId
- 20 when querying by orderId
Data Source: Database
"""
return self._ws_api_request_sync("myAllocations", True, params)
```
Get current account commission rates for a symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-commission-rates-user\_data](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-commission-rates-user_data)
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param recvWindow: LONG - Optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response dict with commission rates:
\{
"symbol": "BTCUSDT",
"standardCommission": \{ # Standard commission rates on trades
"maker": "0.00000010",
"taker": "0.00000020",
"buyer": "0.00000030",
"seller": "0.00000040"
},
"taxCommission": \{ # Tax commission rates on trades
"maker": "0.00000112",
"taker": "0.00000114",
"buyer": "0.00000118",
"seller": "0.00000116"
},
"discount": \{ # Discount on standard commissions when paying in BNB
"enabledForAccount": true,
"enabledForSymbol": true,
"discountAsset": "BNB",
"discount": "0.75000000" # Standard commission reduction rate when paying in BNB
}
}
:raises: BinanceRequestException, BinanceAPIException
Weight: 20
Data Source: Database
```python
def ws_get_commission_rates(self, **params):
"""Get current account commission rates for a symbol.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#account-commission-rates-user_data
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param recvWindow: LONG - Optional - The value cannot be greater than 60000
:type recvWindow: int
:returns: API response dict with commission rates:
{
"symbol": "BTCUSDT",
"standardCommission": { # Standard commission rates on trades
"maker": "0.00000010",
"taker": "0.00000020",
"buyer": "0.00000030",
"seller": "0.00000040"
},
"taxCommission": { # Tax commission rates on trades
"maker": "0.00000112",
"taker": "0.00000114",
"buyer": "0.00000118",
"seller": "0.00000116"
},
"discount": { # Discount on standard commissions when paying in BNB
"enabledForAccount": true,
"enabledForSymbol": true,
"discountAsset": "BNB",
"discount": "0.75000000" # Standard commission reduction rate when paying in BNB
}
}
:raises: BinanceRequestException, BinanceAPIException
Weight: 20
Data Source: Database
"""
return self._ws_api_request_sync("account.commission", True, params)
```
Get current order book for a symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#order-book](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#order-book)
Note that this request returns limited market depth. If you need to continuously monitor
order book updates, consider using WebSocket Streams:
* \@depth\
* \@depth
You can use `depth` request together with `\@depth` streams to maintain a local order book.
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param limit: INT - Optional - Default 100; max 5000
:type limit: int
:returns: Websocket message
\{
"lastUpdateId": 2731179239,
"bids": \[ // Bid levels sorted from highest to lowest price
\[
"0.01379900", // Price level
"3.43200000" // Quantity
],
...
],
"asks": \[ // Ask levels sorted from lowest to highest price
\[
"0.01380000", // Price level
"5.91700000" // Quantity
],
...
]
}
Weight: Adjusted based on limit:
* 1-100: 5
* 101-500: 25
* 501-1000: 50
* 1001-5000: 250
Data Source: Memory
```python
def ws_get_order_book(self, **params):
"""Get current order book for a symbol.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#order-book
Note that this request returns limited market depth. If you need to continuously monitor
order book updates, consider using WebSocket Streams:
- @depth
- @depth
You can use `depth` request together with `@depth` streams to maintain a local order book.
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param limit: INT - Optional - Default 100; max 5000
:type limit: int
:returns: Websocket message
{
"lastUpdateId": 2731179239,
"bids": [ // Bid levels sorted from highest to lowest price
[
"0.01379900", // Price level
"3.43200000" // Quantity
],
...
],
"asks": [ // Ask levels sorted from lowest to highest price
[
"0.01380000", // Price level
"5.91700000" // Quantity
],
...
]
}
Weight: Adjusted based on limit:
- 1-100: 5
- 101-500: 25
- 501-1000: 50
- 1001-5000: 250
Data Source: Memory
"""
return self._ws_api_request_sync("depth", False, params)
```
Get recent trades for a symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#recent-trades](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#recent-trades)
If you need access to real-time trading activity, please consider using WebSocket Streams:
* \@trade
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
:returns: API response
.. code-block:: python
\{
"id": "409a20bd-253d-41db-a6dd-687862a5882f",
"status": 200,
"result": \[
\{
"id": 194686783, # Trade ID
"price": "0.01361000", # Price
"qty": "0.01400000", # Quantity
"quoteQty": "0.00019054", # Quote quantity
"time": 1660009530807, # Trade time
"isBuyerMaker": true, # Was the buyer the maker?
"isBestMatch": true # Was this the best price match?
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Weight: 25
Data Source: Memory
```python
def ws_get_recent_trades(self, **params):
"""Get recent trades for a symbol.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#recent-trades
If you need access to real-time trading activity, please consider using WebSocket Streams:
- @trade
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
:returns: API response
.. code-block:: python
{
"id": "409a20bd-253d-41db-a6dd-687862a5882f",
"status": 200,
"result": [
{
"id": 194686783, # Trade ID
"price": "0.01361000", # Price
"qty": "0.01400000", # Quantity
"quoteQty": "0.00019054", # Quote quantity
"time": 1660009530807, # Trade time
"isBuyerMaker": true, # Was the buyer the maker?
"isBestMatch": true # Was this the best price match?
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Weight: 25
Data Source: Memory
"""
return self._ws_api_request_sync("trades.recent", False, params)
```
Get historical trades.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#historical-trades](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#historical-trades)
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param fromId: INT - Optional - Trade ID to begin at
:type fromId: int
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
:returns: Websocket message
.. code-block:: python
\{
"id": "cffc9c7d-4efc-4ce0-b587-6b87448f052a",
"result": \[
\{
"id": 0, # Trade ID
"price": "0.00005000", # Price
"qty": "40.00000000", # Quantity
"quoteQty": "0.00200000", # Quote quantity
"time": 1500004800376, # Trade time
"isBuyerMaker": true, # Was the buyer the maker?
"isBestMatch": true # Was this the best price match?
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
* If fromId is not specified, the most recent trades are returned
Weight: 25
Data Source: Database
```python
def ws_get_historical_trades(self, **params):
"""Get historical trades.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#historical-trades
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param fromId: INT - Optional - Trade ID to begin at
:type fromId: int
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
:returns: Websocket message
.. code-block:: python
{
"id": "cffc9c7d-4efc-4ce0-b587-6b87448f052a",
"result": [
{
"id": 0, # Trade ID
"price": "0.00005000", # Price
"qty": "40.00000000", # Quantity
"quoteQty": "0.00200000", # Quote quantity
"time": 1500004800376, # Trade time
"isBuyerMaker": true, # Was the buyer the maker?
"isBestMatch": true # Was this the best price match?
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
- If fromId is not specified, the most recent trades are returned
Weight: 25
Data Source: Database
"""
return self._ws_api_request_sync("trades.historical", False, params)
```
Get aggregate trades.
An aggregate trade represents one or more individual trades that fill at the same time,
from the same taker order, with the same price.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#aggregate-trades](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#aggregate-trades)
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param fromId: INT - Optional - Aggregate trade ID to begin at
:type fromId: int
:param startTime: INT - Optional - Start time in milliseconds
:type startTime: int
:param endTime: INT - Optional - End time in milliseconds
:type endTime: int
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
:returns: API response
.. code-block:: python
\{
"id": "...",
"status": 200,
"result": \[
\{
"a": 50000000, # Aggregate trade ID
"p": "0.00274100", # Price
"q": "57.19000000", # Quantity
"f": 59120167, # First trade ID
"l": 59120170, # Last trade ID
"T": 1565877971222, # Timestamp
"m": true, # Was the buyer the maker?
"M": true # Was the trade the best price match?
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
* If fromId is specified, return aggtrades with aggregate trade ID >= fromId.
Use fromId and limit to page through all aggtrades.
* If startTime and/or endTime are specified, aggtrades are filtered by execution time (T).
fromId cannot be used together with startTime and endTime.
* If no condition is specified, the most recent aggregate trades are returned.
* For real-time updates, consider using WebSocket Streams: \@aggTrade
* For historical data, consider using data.binance.vision
Weight: 2
Data Source: Database
```python
def ws_get_aggregate_trades(self, **params):
"""Get aggregate trades.
An aggregate trade represents one or more individual trades that fill at the same time,
from the same taker order, with the same price.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#aggregate-trades
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param fromId: INT - Optional - Aggregate trade ID to begin at
:type fromId: int
:param startTime: INT - Optional - Start time in milliseconds
:type startTime: int
:param endTime: INT - Optional - End time in milliseconds
:type endTime: int
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
:returns: API response
.. code-block:: python
{
"id": "...",
"status": 200,
"result": [
{
"a": 50000000, # Aggregate trade ID
"p": "0.00274100", # Price
"q": "57.19000000", # Quantity
"f": 59120167, # First trade ID
"l": 59120170, # Last trade ID
"T": 1565877971222, # Timestamp
"m": true, # Was the buyer the maker?
"M": true # Was the trade the best price match?
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
- If fromId is specified, return aggtrades with aggregate trade ID >= fromId.
Use fromId and limit to page through all aggtrades.
- If startTime and/or endTime are specified, aggtrades are filtered by execution time (T).
fromId cannot be used together with startTime and endTime.
- If no condition is specified, the most recent aggregate trades are returned.
- For real-time updates, consider using WebSocket Streams: @aggTrade
- For historical data, consider using data.binance.vision
Weight: 2
Data Source: Database
"""
return self._ws_api_request_sync("trades.aggregate", False, params)
```
Get klines (candlestick bars).
Klines are uniquely identified by their open & close time.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#klines](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#klines)
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param interval: ENUM - Required - Kline interval
:type interval: str
:param startTime: INT - Optional - Start time in milliseconds
:type startTime: int
:param endTime: INT - Optional - End time in milliseconds
:type endTime: int
:param timeZone: STRING - Optional - Default: 0 (UTC)
:type timeZone: str
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
Supported kline intervals:
* seconds: 1s
* minutes: 1m, 3m, 5m, 15m, 30m
* hours: 1h, 2h, 4h, 6h, 8h, 12h
* days: 1d, 3d
* weeks: 1w
* months: 1M
Notes:
* If startTime/endTime not specified, returns most recent klines
* Supported timeZone values:
* Hours and minutes (e.g. "-1:00", "05:45")
* Only hours (e.g. "0", "8", "4")
* Accepted range is strictly \[-12:00 to +14:00] inclusive
* If timeZone provided, kline intervals interpreted in that timezone instead of UTC
* startTime and endTime always interpreted in UTC, regardless of timeZone
* For real-time updates, consider using WebSocket Streams: \@kline\_\
* For historical data, consider using data.binance.vision
Weight: 2
Data Source: Database
:returns: API response
.. code-block:: python
\{
"id": "1dbbeb56-8eea-466a-8f6e-86bdcfa2fc0b",
"status": 200,
"result": \[
\[
1655971200000, # Kline open time
"0.01086000", # Open price
"0.01086600", # High price
"0.01083600", # Low price
"0.01083800", # Close price
"2290.53800000", # Volume
1655974799999, # Kline close time
"24.85074442", # Quote asset volume
2283, # Number of trades
"1171.64000000", # Taker buy base asset volume
"12.71225884", # Taker buy quote asset volume
"0" # Unused field, ignore
]
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def ws_get_klines(self, **params):
"""Get klines (candlestick bars).
Klines are uniquely identified by their open & close time.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#klines
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param interval: ENUM - Required - Kline interval
:type interval: str
:param startTime: INT - Optional - Start time in milliseconds
:type startTime: int
:param endTime: INT - Optional - End time in milliseconds
:type endTime: int
:param timeZone: STRING - Optional - Default: 0 (UTC)
:type timeZone: str
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
Supported kline intervals:
- seconds: 1s
- minutes: 1m, 3m, 5m, 15m, 30m
- hours: 1h, 2h, 4h, 6h, 8h, 12h
- days: 1d, 3d
- weeks: 1w
- months: 1M
Notes:
- If startTime/endTime not specified, returns most recent klines
- Supported timeZone values:
- Hours and minutes (e.g. "-1:00", "05:45")
- Only hours (e.g. "0", "8", "4")
- Accepted range is strictly [-12:00 to +14:00] inclusive
- If timeZone provided, kline intervals interpreted in that timezone instead of UTC
- startTime and endTime always interpreted in UTC, regardless of timeZone
- For real-time updates, consider using WebSocket Streams: @kline_
- For historical data, consider using data.binance.vision
Weight: 2
Data Source: Database
:returns: API response
.. code-block:: python
{
"id": "1dbbeb56-8eea-466a-8f6e-86bdcfa2fc0b",
"status": 200,
"result": [
[
1655971200000, # Kline open time
"0.01086000", # Open price
"0.01086600", # High price
"0.01083600", # Low price
"0.01083800", # Close price
"2290.53800000", # Volume
1655974799999, # Kline close time
"24.85074442", # Quote asset volume
2283, # Number of trades
"1171.64000000", # Taker buy base asset volume
"12.71225884", # Taker buy quote asset volume
"0" # Unused field, ignore
]
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._ws_api_request_sync("klines", False, params)
```
Get klines (candlestick bars) optimized for presentation.
This request is similar to klines, having the same parameters and response.
uiKlines return modified kline data, optimized for presentation of candlestick charts.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#ui-klines](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#ui-klines)
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param interval: ENUM - Required - Kline interval
:type interval: str
:param startTime: INT - Optional - Start time in milliseconds
:type startTime: int
:param endTime: INT - Optional - End time in milliseconds
:type endTime: int
:param timeZone: STRING - Optional - Default: 0 (UTC)
:type timeZone: str
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
Supported kline intervals:
* seconds: 1s
* minutes: 1m, 3m, 5m, 15m, 30m
* hours: 1h, 2h, 4h, 6h, 8h, 12h
* days: 1d, 3d
* weeks: 1w
* months: 1M
Notes:
* If startTime/endTime not specified, returns most recent klines
* Supported timeZone values:
* Hours and minutes (e.g. "-1:00", "05:45")
* Only hours (e.g. "0", "8", "4")
* Accepted range is strictly \[-12:00 to +14:00] inclusive
* If timeZone provided, kline intervals are interpreted in that timezone instead of UTC
* startTime and endTime are always interpreted in UTC, regardless of timeZone
:returns: API response
.. code-block:: python
\{
"id": "b137468a-fb20-4c06-bd6b-625148eec958",
"result": \[
\[
1655971200000, # Kline open time
"0.01086000", # Open price
"0.01086600", # High price
"0.01083600", # Low price
"0.01083800", # Close price
"2290.53800000", # Volume
1655974799999, # Kline close time
"24.85074442", # Quote asset volume
2283, # Number of trades
"1171.64000000", # Taker buy base asset volume
"12.71225884", # Taker buy quote asset volume
"0" # Unused field, ignore
]
]
}
:raises: BinanceRequestException, BinanceAPIException
```python
def ws_get_uiKlines(self, **params):
"""Get klines (candlestick bars) optimized for presentation.
This request is similar to klines, having the same parameters and response.
uiKlines return modified kline data, optimized for presentation of candlestick charts.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#ui-klines
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:param interval: ENUM - Required - Kline interval
:type interval: str
:param startTime: INT - Optional - Start time in milliseconds
:type startTime: int
:param endTime: INT - Optional - End time in milliseconds
:type endTime: int
:param timeZone: STRING - Optional - Default: 0 (UTC)
:type timeZone: str
:param limit: INT - Optional - Default 500; max 1000
:type limit: int
Supported kline intervals:
- seconds: 1s
- minutes: 1m, 3m, 5m, 15m, 30m
- hours: 1h, 2h, 4h, 6h, 8h, 12h
- days: 1d, 3d
- weeks: 1w
- months: 1M
Notes:
- If startTime/endTime not specified, returns most recent klines
- Supported timeZone values:
- Hours and minutes (e.g. "-1:00", "05:45")
- Only hours (e.g. "0", "8", "4")
- Accepted range is strictly [-12:00 to +14:00] inclusive
- If timeZone provided, kline intervals are interpreted in that timezone instead of UTC
- startTime and endTime are always interpreted in UTC, regardless of timeZone
:returns: API response
.. code-block:: python
{
"id": "b137468a-fb20-4c06-bd6b-625148eec958",
"result": [
[
1655971200000, # Kline open time
"0.01086000", # Open price
"0.01086600", # High price
"0.01083600", # Low price
"0.01083800", # Close price
"2290.53800000", # Volume
1655974799999, # Kline close time
"24.85074442", # Quote asset volume
2283, # Number of trades
"1171.64000000", # Taker buy base asset volume
"12.71225884", # Taker buy quote asset volume
"0" # Unused field, ignore
]
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._ws_api_request_sync("uiKlines", False, params)
```
Get current average price for a symbol.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#current-average-price](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#current-average-price)
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:returns: Websocket message
.. code-block:: python
\{
"mins": 5, # Average price interval (in minutes)
"price": "9.35751834", # Average price
"closeTime": 1694061154503 # Last trade time
}
Weight: 2
```python
def ws_get_avg_price(self, **params):
"""Get current average price for a symbol.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#current-average-price
:param symbol: STRING - Required - Trading symbol
:type symbol: str
:returns: Websocket message
.. code-block:: python
{
"mins": 5, # Average price interval (in minutes)
"price": "9.35751834", # Average price
"closeTime": 1694061154503 # Last trade time
}
Weight: 2
"""
return self._ws_api_request_sync("avgPrice", False, params)
```
Get 24-hour rolling window price change statistics.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#24hr-ticker-price-change-statistics](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#24hr-ticker-price-change-statistics)
:param symbol: STRING - Optional - Query ticker for a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:param type: ENUM - Optional - Ticker type: FULL (default) or MINI
:type type: str
Note:
* symbol and symbols cannot be used together
* If no symbol is specified, returns information about all symbols currently trading on the exchange
Weight:
Adjusted based on the number of requested symbols:
* 1-20 symbols: 2
* 21-100 symbols: 40
* 101 or more symbols: 80
* all symbols: 80
:returns: Websocket message
For a single symbol with type=FULL:
.. code-block:: python
\{
"symbol": "BNBBTC",
"priceChange": "0.00013900", # Absolute price change
"priceChangePercent": "1.020", # Relative price change in percent
"weightedAvgPrice": "0.01382453", # Quote volume divided by volume
"prevClosePrice": "0.01362800", # Previous day's close price
"lastPrice": "0.01376700", # Latest price
"lastQty": "1.78800000", # Latest quantity
"bidPrice": "0.01376700", # Best bid price
"bidQty": "4.64600000", # Best bid quantity
"askPrice": "0.01376800", # Best ask price
"askQty": "14.31400000", # Best ask quantity
"openPrice": "0.01362800", # Open price 24 hours ago
"highPrice": "0.01414900", # Highest price in the last 24 hours
"lowPrice": "0.01346600", # Lowest price in the last 24 hours
"volume": "69412.40500000", # Trading volume in base asset
"quoteVolume": "959.59411487", # Trading volume in quote asset
"openTime": 1660014164909, # Open time for 24hr rolling window
"closeTime": 1660100564909, # Close time for 24hr rolling window
"firstId": 194696115, # First trade ID
"lastId": 194968287, # Last trade ID
"count": 272173 # Number of trades
}
For a single symbol with type=MINI:
.. code-block:: python
\{
"symbol": "BNBBTC",
"openPrice": "0.01362800",
"highPrice": "0.01414900",
"lowPrice": "0.01346600",
"lastPrice": "0.01376700",
"volume": "69412.40500000",
"quoteVolume": "959.59411487",
"openTime": 1660014164909,
"closeTime": 1660100564909,
"firstId": 194696115,
"lastId": 194968287,
"count": 272173
}
```python
def ws_get_ticker(self, **params):
"""Get 24-hour rolling window price change statistics.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#24hr-ticker-price-change-statistics
:param symbol: STRING - Optional - Query ticker for a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:param type: ENUM - Optional - Ticker type: FULL (default) or MINI
:type type: str
Note:
- symbol and symbols cannot be used together
- If no symbol is specified, returns information about all symbols currently trading on the exchange
Weight:
Adjusted based on the number of requested symbols:
- 1-20 symbols: 2
- 21-100 symbols: 40
- 101 or more symbols: 80
- all symbols: 80
:returns: Websocket message
For a single symbol with type=FULL:
.. code-block:: python
{
"symbol": "BNBBTC",
"priceChange": "0.00013900", # Absolute price change
"priceChangePercent": "1.020", # Relative price change in percent
"weightedAvgPrice": "0.01382453", # Quote volume divided by volume
"prevClosePrice": "0.01362800", # Previous day's close price
"lastPrice": "0.01376700", # Latest price
"lastQty": "1.78800000", # Latest quantity
"bidPrice": "0.01376700", # Best bid price
"bidQty": "4.64600000", # Best bid quantity
"askPrice": "0.01376800", # Best ask price
"askQty": "14.31400000", # Best ask quantity
"openPrice": "0.01362800", # Open price 24 hours ago
"highPrice": "0.01414900", # Highest price in the last 24 hours
"lowPrice": "0.01346600", # Lowest price in the last 24 hours
"volume": "69412.40500000", # Trading volume in base asset
"quoteVolume": "959.59411487", # Trading volume in quote asset
"openTime": 1660014164909, # Open time for 24hr rolling window
"closeTime": 1660100564909, # Close time for 24hr rolling window
"firstId": 194696115, # First trade ID
"lastId": 194968287, # Last trade ID
"count": 272173 # Number of trades
}
For a single symbol with type=MINI:
.. code-block:: python
{
"symbol": "BNBBTC",
"openPrice": "0.01362800",
"highPrice": "0.01414900",
"lowPrice": "0.01346600",
"lastPrice": "0.01376700",
"volume": "69412.40500000",
"quoteVolume": "959.59411487",
"openTime": 1660014164909,
"closeTime": 1660100564909,
"firstId": 194696115,
"lastId": 194968287,
"count": 272173
}
"""
return self._ws_api_request_sync("ticker.24hr", False, params)
```
Price change statistics for a trading day.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#trading-day-ticker](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#trading-day-ticker)
:param symbol: STRING - Optional - Query ticker of a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:param timeZone: STRING - Optional - Default: 0 (UTC)
Supported values:
* Hours and minutes (e.g. "-1:00", "05:45")
* Only hours (e.g. "0", "8", "4")
* Accepted range is strictly \[-12:00 to +14:00] inclusive
:type timeZone: str
:param type: ENUM - Optional - FULL (default) or MINI
:type type: str
:returns: Websocket message
Response FULL type example:
\{
"symbol": "BTCUSDT",
"priceChange": "-83.13000000", # Absolute price change
"priceChangePercent": "-0.317", # Relative price change in percent
"weightedAvgPrice": "26234.58803036", # quoteVolume / volume
"openPrice": "26304.80000000",
"highPrice": "26397.46000000",
"lowPrice": "26088.34000000",
"lastPrice": "26221.67000000",
"volume": "18495.35066000", # Volume in base asset
"quoteVolume": "485217905.04210480",
"openTime": 1695686400000,
"closeTime": 1695772799999,
"firstId": 3220151555,
"lastId": 3220849281,
"count": 697727
}
Response MINI type example:
\{
"symbol": "BTCUSDT",
"openPrice": "26304.80000000",
"highPrice": "26397.46000000",
"lowPrice": "26088.34000000",
"lastPrice": "26221.67000000",
"volume": "18495.35066000", # Volume in base asset
"quoteVolume": "485217905.04210480", # Volume in quote asset
"openTime": 1695686400000,
"closeTime": 1695772799999,
"firstId": 3220151555, # Trade ID of the first trade in the interval
"lastId": 3220849281, # Trade ID of the last trade in the interval
"count": 697727 # Number of trades in the interval
}
Weight:
* 4 for each requested symbol
* Weight caps at 200 once number of symbols > 50
```python
def ws_get_trading_day_ticker(self, **params):
"""Price change statistics for a trading day.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#trading-day-ticker
:param symbol: STRING - Optional - Query ticker of a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:param timeZone: STRING - Optional - Default: 0 (UTC)
Supported values:
- Hours and minutes (e.g. "-1:00", "05:45")
- Only hours (e.g. "0", "8", "4")
- Accepted range is strictly [-12:00 to +14:00] inclusive
:type timeZone: str
:param type: ENUM - Optional - FULL (default) or MINI
:type type: str
:returns: Websocket message
Response FULL type example:
{
"symbol": "BTCUSDT",
"priceChange": "-83.13000000", # Absolute price change
"priceChangePercent": "-0.317", # Relative price change in percent
"weightedAvgPrice": "26234.58803036", # quoteVolume / volume
"openPrice": "26304.80000000",
"highPrice": "26397.46000000",
"lowPrice": "26088.34000000",
"lastPrice": "26221.67000000",
"volume": "18495.35066000", # Volume in base asset
"quoteVolume": "485217905.04210480",
"openTime": 1695686400000,
"closeTime": 1695772799999,
"firstId": 3220151555,
"lastId": 3220849281,
"count": 697727
}
Response MINI type example:
{
"symbol": "BTCUSDT",
"openPrice": "26304.80000000",
"highPrice": "26397.46000000",
"lowPrice": "26088.34000000",
"lastPrice": "26221.67000000",
"volume": "18495.35066000", # Volume in base asset
"quoteVolume": "485217905.04210480", # Volume in quote asset
"openTime": 1695686400000,
"closeTime": 1695772799999,
"firstId": 3220151555, # Trade ID of the first trade in the interval
"lastId": 3220849281, # Trade ID of the last trade in the interval
"count": 697727 # Number of trades in the interval
}
Weight:
- 4 for each requested symbol
- Weight caps at 200 once number of symbols > 50
"""
return self._ws_api_request_sync("ticker.tradingDay", False, params)
```
Get rolling window price change statistics.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#rolling-window-price-change-statistics](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#rolling-window-price-change-statistics)
:param symbol: STRING - Optional - Query ticker of a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:param windowSize: STRING - Required - Supported windowSize values:
* 1h, 2h, 4h, 6h, 12h
* 1d, 2d, 3d, 4d, 5d, 6d, 7d, 14d, 30d
:type windowSize: str
:param type: ENUM - Optional - FULL (default) or MINI
:type type: str
:returns: Websocket message
With symbol parameter:
.. code-block:: python
\{
"symbol": "BTCUSDT",
"priceChange": "-83.13000000", # Absolute price change
"priceChangePercent": "-0.317", # Relative price change in percent
"weightedAvgPrice": "26234.58803036", # quoteVolume / volume
"openPrice": "26304.80000000",
"highPrice": "26397.46000000",
"lowPrice": "26088.34000000",
"lastPrice": "26221.67000000",
"volume": "18495.35066000", # Volume in base asset
"quoteVolume": "485217905.04210480", # Volume in quote asset
"openTime": 1695686400000,
"closeTime": 1695772799999,
"firstId": 3220151555, # Trade ID of first trade in the interval
"lastId": 3220849281, # Trade ID of last trade in the interval
"count": 697727 # Number of trades in the interval
}
With symbols parameter:
.. code-block:: python
\[
\{
Same fields as above [#same-fields-as-above]
},
\{
Same fields as above for next symbol [#same-fields-as-above-for-next-symbol]
}
]
For MINI type response:
.. code-block:: python
\{
"symbol": "BTCUSDT",
"openPrice": "26304.80000000",
"highPrice": "26397.46000000",
"lowPrice": "26088.34000000",
"lastPrice": "26221.67000000",
"volume": "18495.35066000",
"quoteVolume": "485217905.04210480",
"openTime": 1695686400000,
"closeTime": 1695772799999,
"firstId": 3220151555,
"lastId": 3220849281,
"count": 697727
}
Weight:
* 4 for each requested symbol
* Weight caps at 200 once number of symbols > 50
```python
def ws_get_symbol_ticker_window(self, **params):
"""Get rolling window price change statistics.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#rolling-window-price-change-statistics
:param symbol: STRING - Optional - Query ticker of a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:param windowSize: STRING - Required - Supported windowSize values:
- 1h, 2h, 4h, 6h, 12h
- 1d, 2d, 3d, 4d, 5d, 6d, 7d, 14d, 30d
:type windowSize: str
:param type: ENUM - Optional - FULL (default) or MINI
:type type: str
:returns: Websocket message
With symbol parameter:
.. code-block:: python
{
"symbol": "BTCUSDT",
"priceChange": "-83.13000000", # Absolute price change
"priceChangePercent": "-0.317", # Relative price change in percent
"weightedAvgPrice": "26234.58803036", # quoteVolume / volume
"openPrice": "26304.80000000",
"highPrice": "26397.46000000",
"lowPrice": "26088.34000000",
"lastPrice": "26221.67000000",
"volume": "18495.35066000", # Volume in base asset
"quoteVolume": "485217905.04210480", # Volume in quote asset
"openTime": 1695686400000,
"closeTime": 1695772799999,
"firstId": 3220151555, # Trade ID of first trade in the interval
"lastId": 3220849281, # Trade ID of last trade in the interval
"count": 697727 # Number of trades in the interval
}
With symbols parameter:
.. code-block:: python
[
{
# Same fields as above
},
{
# Same fields as above for next symbol
}
]
For MINI type response:
.. code-block:: python
{
"symbol": "BTCUSDT",
"openPrice": "26304.80000000",
"highPrice": "26397.46000000",
"lowPrice": "26088.34000000",
"lastPrice": "26221.67000000",
"volume": "18495.35066000",
"quoteVolume": "485217905.04210480",
"openTime": 1695686400000,
"closeTime": 1695772799999,
"firstId": 3220151555,
"lastId": 3220849281,
"count": 697727
}
Weight:
- 4 for each requested symbol
- Weight caps at 200 once number of symbols > 50
"""
return self._ws_api_request_sync("ticker", False, params)
```
Get latest price for a symbol or symbols.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#symbol-price-ticker](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#symbol-price-ticker)
:param symbol: STRING - Optional - Query ticker of a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:returns: Websocket message
With symbol parameter:
\{
"symbol": "BNBBTC",
"price": "0.01361000"
}
With symbols parameter:
\[
\{
"symbol": "BNBBTC",
"price": "0.01361000"
},
\{
"symbol": "BTCUSDT",
"price": "23440.91000000"
}
]
Weight:
* 1 for a single symbol
* 2 for up to 20 symbols
* 40 for 21 to 100 symbols
* 40 for all symbols
```python
def ws_get_symbol_ticker(self, **params):
"""Get latest price for a symbol or symbols.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#symbol-price-ticker
:param symbol: STRING - Optional - Query ticker of a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:returns: Websocket message
With symbol parameter:
{
"symbol": "BNBBTC",
"price": "0.01361000"
}
With symbols parameter:
[
{
"symbol": "BNBBTC",
"price": "0.01361000"
},
{
"symbol": "BTCUSDT",
"price": "23440.91000000"
}
]
Weight:
- 1 for a single symbol
- 2 for up to 20 symbols
- 40 for 21 to 100 symbols
- 40 for all symbols
"""
return self._ws_api_request_sync("ticker.price", False, params)
```
Get the best price/quantity on the order book for a symbol or symbols.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#symbol-order-book-ticker](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#symbol-order-book-ticker)
:param symbol: STRING - Optional - Query ticker of a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:returns: Websocket response
With symbol parameter:
\{
"symbol": "BNBBTC",
"bidPrice": "0.01358000",
"bidQty": "0.95200000",
"askPrice": "0.01358100",
"askQty": "11.91700000"
}
With symbols parameter:
\[
\{
"symbol": "BNBBTC",
"bidPrice": "0.01358000",
"bidQty": "0.95200000",
"askPrice": "0.01358100",
"askQty": "11.91700000"
},
\{
"symbol": "BTCUSDT",
"bidPrice": "23440.90000000",
"bidQty": "0.00200000",
"askPrice": "23440.91000000",
"askQty": "0.00200000"
}
]
Weight:
* 2 for a single symbol
* 4 for up to 100 symbols
* 40 for 101 or more symbols
```python
def ws_get_orderbook_ticker(self, **params):
"""Get the best price/quantity on the order book for a symbol or symbols.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#symbol-order-book-ticker
:param symbol: STRING - Optional - Query ticker of a single symbol
:type symbol: str
:param symbols: ARRAY of STRING - Optional - Query ticker for multiple symbols
:type symbols: list
:returns: Websocket response
With symbol parameter:
{
"symbol": "BNBBTC",
"bidPrice": "0.01358000",
"bidQty": "0.95200000",
"askPrice": "0.01358100",
"askQty": "11.91700000"
}
With symbols parameter:
[
{
"symbol": "BNBBTC",
"bidPrice": "0.01358000",
"bidQty": "0.95200000",
"askPrice": "0.01358100",
"askQty": "11.91700000"
},
{
"symbol": "BTCUSDT",
"bidPrice": "23440.90000000",
"bidQty": "0.00200000",
"askPrice": "23440.91000000",
"askQty": "0.00200000"
}
]
Weight:
- 2 for a single symbol
- 4 for up to 100 symbols
- 40 for 101 or more symbols
"""
return self._ws_api_request_sync("ticker.book", False, params)
```
Test connectivity to the WebSocket API.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#test-connectivity](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#test-connectivity)
:returns: API response
\{
"id": "922bcc6e-9de8-440d-9e84-7c80933a8d0d",
"status": 200,
"result": \{},
"rateLimits": \[
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Weight: 1
```python
def ws_ping(self, **params):
"""Test connectivity to the WebSocket API.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#test-connectivity
:returns: API response
{
"id": "922bcc6e-9de8-440d-9e84-7c80933a8d0d",
"status": 200,
"result": {},
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Weight: 1
"""
return self._ws_api_request_sync("ping", False, params)
```
Test connectivity to the WebSocket API and get the current server time.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#check-server-time](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#check-server-time)
:returns: API response with server time
\{
"id": "187d3cb2-942d-484c-8271-4e2141bbadb1",
"status": 200,
"result": \{
"serverTime": 1656400526260
},
"rateLimits": \[
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Weight: 1
Data Source: Memory
```python
def ws_get_time(self, **params):
"""Test connectivity to the WebSocket API and get the current server time.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#check-server-time
:returns: API response with server time
{
"id": "187d3cb2-942d-484c-8271-4e2141bbadb1",
"status": 200,
"result": {
"serverTime": 1656400526260
},
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000,
"count": 1
}
]
}
Weight: 1
Data Source: Memory
"""
return self._ws_api_request_sync("time", False, params)
```
Query current exchange trading rules, rate limits, and symbol information.
[https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#exchange-information](https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#exchange-information)
:param symbol: str - Filter by single symbol (optional)
:param symbols: list - Filter by multiple symbols (optional)
:param permissions: list or str - Filter symbols by permissions (optional)
:returns: API response containing exchange information including:
* Rate limits
* Exchange filters
* Symbol information including:
* Status
* Base/quote assets
* Order types allowed
* Filters (price, lot size, etc)
* Trading permissions
* Self-trade prevention modes
Example response:
\{
"timezone": "UTC",
"serverTime": 1655969291181,
"rateLimits": \[
\{
"rateLimitType": "REQUEST\_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000
},
...
],
"exchangeFilters": \[],
"symbols": \[
\{
"symbol": "BTCUSDT",
"status": "TRADING",
"baseAsset": "BTC",
"baseAssetPrecision": 8,
...
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
* Only one of symbol, symbols, permissions parameters can be specified
* Without parameters, displays all symbols with \["SPOT", "MARGIN", "LEVERAGED"] permissions
* To list all active symbols, explicitly request all permissions
* Permissions accepts either a list or single permission name (e.g. "SPOT")
Weight: 20
Data Source: Memory
```python
def ws_get_exchange_info(self, **params):
"""Query current exchange trading rules, rate limits, and symbol information.
https://developers.binance.com/docs/binance-spot-api-docs/testnet/web-socket-api/public-api-requests#exchange-information
:param symbol: str - Filter by single symbol (optional)
:param symbols: list - Filter by multiple symbols (optional)
:param permissions: list or str - Filter symbols by permissions (optional)
:returns: API response containing exchange information including:
- Rate limits
- Exchange filters
- Symbol information including:
- Status
- Base/quote assets
- Order types allowed
- Filters (price, lot size, etc)
- Trading permissions
- Self-trade prevention modes
Example response:
{
"timezone": "UTC",
"serverTime": 1655969291181,
"rateLimits": [
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 6000
},
...
],
"exchangeFilters": [],
"symbols": [
{
"symbol": "BTCUSDT",
"status": "TRADING",
"baseAsset": "BTC",
"baseAssetPrecision": 8,
...
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
- Only one of symbol, symbols, permissions parameters can be specified
- Without parameters, displays all symbols with ["SPOT", "MARGIN", "LEVERAGED"] permissions
- To list all active symbols, explicitly request all permissions
- Permissions accepts either a list or single permission name (e.g. "SPOT")
Weight: 20
Data Source: Memory
"""
return self._ws_api_request_sync("exchangeInfo", False, params)
```
Get the order book for a symbol
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api)
```python
def ws_futures_get_order_book(self, **params):
"""
Get the order book for a symbol
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api
"""
return self._ws_futures_api_request_sync("depth", False, params)
```
Latest price for a symbol or symbols
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Price-Ticker](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Price-Ticker)
```python
def ws_futures_get_all_tickers(self, **params):
"""
Latest price for a symbol or symbols
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Price-Ticker
"""
return self._ws_futures_api_request_sync("ticker.price", False, params)
```
Best price/qty on the order book for a symbol or symbols.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Order-Book-Ticker](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Order-Book-Ticker)
```python
def ws_futures_get_order_book_ticker(self, **params):
"""
Best price/qty on the order book for a symbol or symbols.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-api/Symbol-Order-Book-Ticker
"""
return self._ws_futures_api_request_sync("ticker.book", False, params)
```
Send in a new order
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api)
```python
def ws_futures_create_order(self, **params):
"""
Send in a new order
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api
"""
# Check if this is a conditional order type that needs to use algo endpoint
order_type = params.get("type", "").upper()
conditional_types = [
"STOP",
"STOP_MARKET",
"TAKE_PROFIT",
"TAKE_PROFIT_MARKET",
"TRAILING_STOP_MARKET",
]
if order_type in conditional_types:
# Route to algo order endpoint
if "clientAlgoId" not in params:
params["clientAlgoId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
# Remove newClientOrderId if it was added by default
params.pop("newClientOrderId", None)
if "algoType" not in params:
params["algoType"] = "CONDITIONAL"
# Convert stopPrice to triggerPrice for algo orders
if "stopPrice" in params and "triggerPrice" not in params:
params["triggerPrice"] = params.pop("stopPrice")
return self._ws_futures_api_request_sync("algoOrder.place", True, params)
else:
# Use regular order endpoint
if "newClientOrderId" not in params:
params["newClientOrderId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._ws_futures_api_request_sync("order.place", True, params)
```
Edit an order
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Modify-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Modify-Order)
```python
def ws_futures_edit_order(self, **params):
"""
Edit an order
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Modify-Order
"""
return self._ws_futures_api_request_sync("order.modify", True, params)
```
cancel an order
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order)
```python
def ws_futures_cancel_order(self, **params):
"""
cancel an order
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Cancel-Order
"""
is_conditional = False
if "algoId" in params or "clientAlgoId" in params:
is_conditional = True
if is_conditional:
return self._ws_futures_api_request_sync("algoOrder.cancel", True, params)
else:
return self._ws_futures_api_request_sync("order.cancel", True, params)
```
Get an order
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Query-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Query-Order)
Note: Algo/conditional orders cannot be queried via websocket API
```python
def ws_futures_get_order(self, **params):
"""
Get an order
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Query-Order
Note: Algo/conditional orders cannot be queried via websocket API
"""
return self._ws_futures_api_request_sync("order.status", True, params)
```
Get current position information(only symbol that has position or open orders will be returned).
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Info-V2](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Info-V2)
```python
def ws_futures_v2_account_position(self, **params):
"""
Get current position information(only symbol that has position or open orders will be returned).
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Info-V2
"""
return self._ws_futures_api_request_sync("v2/account.position", True, params)
```
Get current position information.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Information](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Information)
```python
def ws_futures_account_position(self, **params):
"""
Get current position information.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api/Position-Information
"""
return self._ws_futures_api_request_sync("account.position", True, params)
```
Get current account information.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api#api-description](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api#api-description)
```python
def ws_futures_v2_account_balance(self, **params):
"""
Get current account information.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api#api-description
"""
return self._ws_futures_api_request_sync("v2/account.balance", True, params)
```
Get current account information.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Futures-Account-Balance](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Futures-Account-Balance)
```python
def ws_futures_account_balance(self, **params):
"""
Get current account information.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Futures-Account-Balance
"""
return self._ws_futures_api_request_sync("account.balance", True, params)
```
Get current account information. User in single-asset/ multi-assets mode will see different value, see comments in response section for detail.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information-V2](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information-V2)
```python
def ws_futures_v2_account_status(self, **params):
"""
Get current account information. User in single-asset/ multi-assets mode will see different value, see comments in response section for detail.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information-V2
"""
return self._ws_futures_api_request_sync("v2/account.status", True, params)
```
Get current account information. User in single-asset/ multi-assets mode will see different value, see comments in response section for detail.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information)
```python
def ws_futures_account_status(self, **params):
"""
Get current account information. User in single-asset/ multi-assets mode will see different value, see comments in response section for detail.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/websocket-api/Account-Information
"""
return self._ws_futures_api_request_sync("account.status", True, params)
```
Send in a new algo order (conditional order).
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api)
:param symbol: required
:type symbol: str
:param side: required - BUY or SELL
:type side: str
:param type: required - STOP, TAKE\_PROFIT, STOP\_MARKET, TAKE\_PROFIT\_MARKET, TRAILING\_STOP\_MARKET
:type type: str
:param algoType: required - Only support CONDITIONAL
:type algoType: str
:param positionSide: optional - Default BOTH for One-way Mode; LONG or SHORT for Hedge Mode
:type positionSide: str
:param timeInForce: optional - IOC or GTC or FOK, default GTC
:type timeInForce: str
:param quantity: optional - Cannot be sent with closePosition=true
:type quantity: decimal
:param price: optional
:type price: decimal
:param triggerPrice: optional - Used with STOP, STOP\_MARKET, TAKE\_PROFIT, TAKE\_PROFIT\_MARKET
:type triggerPrice: decimal
:param workingType: optional - triggerPrice triggered by: MARK\_PRICE, CONTRACT\_PRICE. Default CONTRACT\_PRICE
:type workingType: str
:param priceMatch: optional - only available for LIMIT/STOP/TAKE\_PROFIT order
:type priceMatch: str
:param closePosition: optional - true or false; Close-All, used with STOP\_MARKET or TAKE\_PROFIT\_MARKET
:type closePosition: bool
:param priceProtect: optional - "TRUE" or "FALSE", default "FALSE"
:type priceProtect: str
:param reduceOnly: optional - "true" or "false", default "false"
:type reduceOnly: str
:param activationPrice: optional - Used with TRAILING\_STOP\_MARKET orders
:type activationPrice: decimal
:param callbackRate: optional - Used with TRAILING\_STOP\_MARKET orders, min 0.1, max 10
:type callbackRate: decimal
:param clientAlgoId: optional - A unique id among open orders
:type clientAlgoId: str
:param selfTradePreventionMode: optional - EXPIRE\_TAKER, EXPIRE\_MAKER, EXPIRE\_BOTH; default NONE
:type selfTradePreventionMode: str
:param goodTillDate: optional - order cancel time for timeInForce GTD
:type goodTillDate: int
:param newOrderRespType: optional - "ACK", "RESULT", default "ACK"
:type newOrderRespType: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
```python
def ws_futures_create_algo_order(self, **params):
"""
Send in a new algo order (conditional order).
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api
:param symbol: required
:type symbol: str
:param side: required - BUY or SELL
:type side: str
:param type: required - STOP, TAKE_PROFIT, STOP_MARKET, TAKE_PROFIT_MARKET, TRAILING_STOP_MARKET
:type type: str
:param algoType: required - Only support CONDITIONAL
:type algoType: str
:param positionSide: optional - Default BOTH for One-way Mode; LONG or SHORT for Hedge Mode
:type positionSide: str
:param timeInForce: optional - IOC or GTC or FOK, default GTC
:type timeInForce: str
:param quantity: optional - Cannot be sent with closePosition=true
:type quantity: decimal
:param price: optional
:type price: decimal
:param triggerPrice: optional - Used with STOP, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET
:type triggerPrice: decimal
:param workingType: optional - triggerPrice triggered by: MARK_PRICE, CONTRACT_PRICE. Default CONTRACT_PRICE
:type workingType: str
:param priceMatch: optional - only available for LIMIT/STOP/TAKE_PROFIT order
:type priceMatch: str
:param closePosition: optional - true or false; Close-All, used with STOP_MARKET or TAKE_PROFIT_MARKET
:type closePosition: bool
:param priceProtect: optional - "TRUE" or "FALSE", default "FALSE"
:type priceProtect: str
:param reduceOnly: optional - "true" or "false", default "false"
:type reduceOnly: str
:param activationPrice: optional - Used with TRAILING_STOP_MARKET orders
:type activationPrice: decimal
:param callbackRate: optional - Used with TRAILING_STOP_MARKET orders, min 0.1, max 10
:type callbackRate: decimal
:param clientAlgoId: optional - A unique id among open orders
:type clientAlgoId: str
:param selfTradePreventionMode: optional - EXPIRE_TAKER, EXPIRE_MAKER, EXPIRE_BOTH; default NONE
:type selfTradePreventionMode: str
:param goodTillDate: optional - order cancel time for timeInForce GTD
:type goodTillDate: int
:param newOrderRespType: optional - "ACK", "RESULT", default "ACK"
:type newOrderRespType: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
"""
if "clientAlgoId" not in params:
params["clientAlgoId"] = self.CONTRACT_ORDER_PREFIX + self.uuid22()
return self._ws_futures_api_request_sync("algoOrder.place", True, params)
```
Cancel an active algo order.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api)
:param symbol: required
:type symbol: str
:param algoId: optional - Either algoId or clientAlgoId must be sent
:type algoId: int
:param clientAlgoId: optional - Either algoId or clientAlgoId must be sent
:type clientAlgoId: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
```python
def ws_futures_cancel_algo_order(self, **params):
"""
Cancel an active algo order.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/websocket-api
:param symbol: required
:type symbol: str
:param algoId: optional - Either algoId or clientAlgoId must be sent
:type algoId: int
:param clientAlgoId: optional - Either algoId or clientAlgoId must be sent
:type clientAlgoId: str
:param recvWindow: optional - the number of milliseconds the request is valid for
:type recvWindow: int
:returns: WS response
"""
return self._ws_futures_api_request_sync("algoOrder.cancel", True, params)
```
Verify which tokens are available for you to create Stablecoin-Denominated gift cards
[https://developers.binance.com/docs/gift\_card/market-data/Fetch-Token-Limit](https://developers.binance.com/docs/gift_card/market-data/Fetch-Token-Limit)
:param baseToken: The token you want to pay, example: BUSD
:type baseToken: str
:return: api response
.. code-block:: python
\{
"code": "000000",
"message": "success",
"data": \[
\{
"coin": "BNB",
"fromMin": "0.01",
"fromMax": "1"
}
],
"success": true
}
```python
def gift_card_fetch_token_limit(self, **params):
"""Verify which tokens are available for you to create Stablecoin-Denominated gift cards
https://developers.binance.com/docs/gift_card/market-data/Fetch-Token-Limit
:param baseToken: The token you want to pay, example: BUSD
:type baseToken: str
:return: api response
.. code-block:: python
{
"code": "000000",
"message": "success",
"data": [
{
"coin": "BNB",
"fromMin": "0.01",
"fromMax": "1"
}
],
"success": true
}
"""
return self._request_margin_api(
"get", "giftcard/buyCode/token-limit", signed=True, data=params
)
```
This API is for fetching the RSA Public Key. This RSA Public key will be used to encrypt the card code.
Important Note:
The RSA Public key fetched is valid only for the current day.
[https://developers.binance.com/docs/gift\_card/market-data/Fetch-RSA-Public-Key](https://developers.binance.com/docs/gift_card/market-data/Fetch-RSA-Public-Key)
:param recvWindow: The receive window for the request in milliseconds (optional)
:type recvWindow: int
:return: api response
.. code-block:: python
\{
"code": "000000",
"message": "success",
"data": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXBBVKLAc1GQ5FsIFFqOHrPTox5noBONIKr+IAedTR9FkVxq6e65updEbfdhRNkMOeYIO2i0UylrjGC0X8YSoIszmrVHeV0l06Zh1oJuZos1+7N+WLuz9JvlPaawof3GUakTxYWWCa9+8KIbLKsoKMdfS96VT+8iOXO3quMGKUmQIDAQAB",
"success": true
}
```python
def gift_card_fetch_rsa_public_key(self, **params):
"""This API is for fetching the RSA Public Key. This RSA Public key will be used to encrypt the card code.
Important Note:
The RSA Public key fetched is valid only for the current day.
https://developers.binance.com/docs/gift_card/market-data/Fetch-RSA-Public-Key
:param recvWindow: The receive window for the request in milliseconds (optional)
:type recvWindow: int
:return: api response
.. code-block:: python
{
"code": "000000",
"message": "success",
"data": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXBBVKLAc1GQ5FsIFFqOHrPTox5noBONIKr+IAedTR9FkVxq6e65updEbfdhRNkMOeYIO2i0UylrjGC0X8YSoIszmrVHeV0l06Zh1oJuZos1+7N+WLuz9JvlPaawof3GUakTxYWWCa9+8KIbLKsoKMdfS96VT+8iOXO3quMGKUmQIDAQAB",
"success": true
}
"""
return self._request_margin_api(
"get", "giftcard/cryptography/rsa-public-key", signed=True, data=params
)
```
This API is for verifying whether the Binance Gift Card is valid or not by entering Gift Card Number.
Important Note:
If you enter the wrong Gift Card Number 5 times within an hour, you will no longer be able
to verify any Gift Card Number for that hour.
[https://developers.binance.com/docs/gift\_card/market-data/Verify-Binance-Gift-Card-by-Gift-Card-Number](https://developers.binance.com/docs/gift_card/market-data/Verify-Binance-Gift-Card-by-Gift-Card-Number)
:param referenceNo: Enter the Gift Card Number
:type referenceNo: str
:return: api response
.. code-block:: python
\{
"code": "000000",
"message": "success",
"data": \{
"valid": true,
"token": "BNB", # coin
"amount": "0.00000001" # amount
},
"success": true
}
```python
def gift_card_verify(self, **params):
"""This API is for verifying whether the Binance Gift Card is valid or not by entering Gift Card Number.
Important Note:
If you enter the wrong Gift Card Number 5 times within an hour, you will no longer be able
to verify any Gift Card Number for that hour.
https://developers.binance.com/docs/gift_card/market-data/Verify-Binance-Gift-Card-by-Gift-Card-Number
:param referenceNo: Enter the Gift Card Number
:type referenceNo: str
:return: api response
.. code-block:: python
{
"code": "000000",
"message": "success",
"data": {
"valid": true,
"token": "BNB", # coin
"amount": "0.00000001" # amount
},
"success": true
}
"""
return self._request_margin_api(
"get", "giftcard/verify", signed=True, data=params
)
```
This API is for redeeming a Binance Gift Card. Once redeemed, the coins will be deposited in your funding wallet.
Important Note:
If you enter the wrong redemption code 5 times within 24 hours, you will no longer be able to
redeem any Binance Gift Cards that day.
Code Format Options:
* Plaintext
* Encrypted (Recommended for better security)
For encrypted format:
1. Fetch RSA public key from the RSA public key endpoint
2. Encrypt the code using algorithm: RSA/ECB/OAEPWithSHA-256AndMGF1Padding
[https://developers.binance.com/docs/gift\_card/market-data/Redeem-a-Binance-Gift-Card](https://developers.binance.com/docs/gift_card/market-data/Redeem-a-Binance-Gift-Card)
:param code: Redemption code of Binance Gift Card to be redeemed, supports both Plaintext & Encrypted code
:type code: str
:param externalUid: External unique ID representing a user on the partner platform.
Helps identify redemption behavior and control risks/limits.
Max 400 characters. (optional)
:type externalUid: str
:param recvWindow: The receive window for the request in milliseconds (optional)
:type recvWindow: int
:return: api response
.. code-block:: python
\{
"code": "000000",
"message": "success",
"data": \{
"referenceNo": "0033002328060227",
"identityNo": "10317392647411060736",
"token": "BNB",
"amount": "0.00000001"
},
"success": true
}
```python
def gift_card_redeem(self, **params):
"""This API is for redeeming a Binance Gift Card. Once redeemed, the coins will be deposited in your funding wallet.
Important Note:
If you enter the wrong redemption code 5 times within 24 hours, you will no longer be able to
redeem any Binance Gift Cards that day.
Code Format Options:
- Plaintext
- Encrypted (Recommended for better security)
For encrypted format:
1. Fetch RSA public key from the RSA public key endpoint
2. Encrypt the code using algorithm: RSA/ECB/OAEPWithSHA-256AndMGF1Padding
https://developers.binance.com/docs/gift_card/market-data/Redeem-a-Binance-Gift-Card
:param code: Redemption code of Binance Gift Card to be redeemed, supports both Plaintext & Encrypted code
:type code: str
:param externalUid: External unique ID representing a user on the partner platform.
Helps identify redemption behavior and control risks/limits.
Max 400 characters. (optional)
:type externalUid: str
:param recvWindow: The receive window for the request in milliseconds (optional)
:type recvWindow: int
:return: api response
.. code-block:: python
{
"code": "000000",
"message": "success",
"data": {
"referenceNo": "0033002328060227",
"identityNo": "10317392647411060736",
"token": "BNB",
"amount": "0.00000001"
},
"success": true
}
"""
return self._request_margin_api(
"post", "giftcard/redeemCode", signed=True, data=params
)
```
This API is for creating a Binance Gift Card.
To get started with, please make sure:
* You have a Binance account
* You have passed KYB
* You have a sufficient balance(Gift Card amount and fee amount) in your Binance funding wallet
* You need Enable Withdrawals for the API Key which requests this endpoint.
[https://developers.binance.com/docs/gift\_card/market-data](https://developers.binance.com/docs/gift_card/market-data)
:param token: The token type contained in the Binance Gift Card
:type token: str
:param amount: The amount of the token contained in the Binance Gift Card
:type amount: float
:return: api response
.. code-block:: python
\{
"code": "000000",
"message": "success",
"data": \{
"referenceNo": "0033002144060553",
"code": "6H9EKF5ECCWFBHGE",
"expiredTime": 1727417154000
},
"success": true
}
```python
def gift_card_create(self, **params):
"""
This API is for creating a Binance Gift Card.
To get started with, please make sure:
- You have a Binance account
- You have passed KYB
- You have a sufficient balance(Gift Card amount and fee amount) in your Binance funding wallet
- You need Enable Withdrawals for the API Key which requests this endpoint.
https://developers.binance.com/docs/gift_card/market-data
:param token: The token type contained in the Binance Gift Card
:type token: str
:param amount: The amount of the token contained in the Binance Gift Card
:type amount: float
:return: api response
.. code-block:: python
{
"code": "000000",
"message": "success",
"data": {
"referenceNo": "0033002144060553",
"code": "6H9EKF5ECCWFBHGE",
"expiredTime": 1727417154000
},
"success": true
}
"""
return self._request_margin_api(
"post", "giftcard/createCode", signed=True, data=params
)
```
This API is for creating a dual-token ( stablecoin-denominated) Binance Gift Card. You may create a gift card using USDT as baseToken, that is redeemable to another designated token (faceToken). For example, you can create a fixed-value BTC gift card and pay with 100 USDT plus 1 USDT fee. This gift card can keep the value fixed at 100 USDT before redemption, and will be redeemable to BTC equivalent to 100 USDT upon redemption.
Once successfully created, the amount of baseToken (e.g. USDT) in the fixed-value gift card along with the fee would be deducted from your funding wallet.
To get started with, please make sure:
* You have a Binance account
* You have passed KYB
* You have a sufficient balance(Gift Card amount and fee amount) in your Binance funding wallet
* You need Enable Withdrawals for the API Key which requests this endpoint.
[https://developers.binance.com/docs/gift\_card/market-data/Create-a-dual-token-gift-card](https://developers.binance.com/docs/gift_card/market-data/Create-a-dual-token-gift-card)
:param baseToken: The token you want to pay, example: BUSD
:type baseToken: str
:param faceToken: The token you want to buy, example: BNB. If faceToken = baseToken, it's the same as createCode endpoint.
:type faceToken: str
:param discount: Stablecoin-denominated card discount percentage, Example: 1 for 1% discount. Scale should be less than 6.
:type discount: float
:return: api response
.. code-block:: python
\{
"code": "000000",
"message": "success",
"data": \{
"referenceNo": "0033002144060553",
"code": "6H9EKF5ECCWFBHGE",
"expiredTime": 1727417154000
},
"success": true
}
```python
def gift_card_create_dual_token(self, **params):
"""This API is for creating a dual-token ( stablecoin-denominated) Binance Gift Card. You may create a gift card using USDT as baseToken, that is redeemable to another designated token (faceToken). For example, you can create a fixed-value BTC gift card and pay with 100 USDT plus 1 USDT fee. This gift card can keep the value fixed at 100 USDT before redemption, and will be redeemable to BTC equivalent to 100 USDT upon redemption.
Once successfully created, the amount of baseToken (e.g. USDT) in the fixed-value gift card along with the fee would be deducted from your funding wallet.
To get started with, please make sure:
- You have a Binance account
- You have passed KYB
- You have a sufficient balance(Gift Card amount and fee amount) in your Binance funding wallet
- You need Enable Withdrawals for the API Key which requests this endpoint.
https://developers.binance.com/docs/gift_card/market-data/Create-a-dual-token-gift-card
:param baseToken: The token you want to pay, example: BUSD
:type baseToken: str
:param faceToken: The token you want to buy, example: BNB. If faceToken = baseToken, it's the same as createCode endpoint.
:type faceToken: str
:param discount: Stablecoin-denominated card discount percentage, Example: 1 for 1% discount. Scale should be less than 6.
:type discount: float
:return: api response
.. code-block:: python
{
"code": "000000",
"message": "success",
"data": {
"referenceNo": "0033002144060553",
"code": "6H9EKF5ECCWFBHGE",
"expiredTime": 1727417154000
},
"success": true
}
"""
return self._request_margin_api(
"post", "giftcard/buyCode", signed=True, data=params
)
```
Get future hourly interest rate (USER\_DATA)
[https://developers.binance.com/docs/margin\_trading/borrow-and-repay](https://developers.binance.com/docs/margin_trading/borrow-and-repay)
:param assets: required - List of assets, separated by commas, up to 20
:type assets: str
:param isIsolated: required - for isolated margin or not, "TRUE", "FALSE"
:type isIsolated: bool
:returns: API response
.. code-block:: python
\[
\{
"asset": "BTC",
"nextHourlyInterestRate": "0.00000571"
},
\{
"asset": "ETH",
"nextHourlyInterestRate": "0.00000578"
}
]
```python
def margin_next_hourly_interest_rate(self, **params):
"""Get future hourly interest rate (USER_DATA)
https://developers.binance.com/docs/margin_trading/borrow-and-repay
:param assets: required - List of assets, separated by commas, up to 20
:type assets: str
:param isIsolated: required - for isolated margin or not, "TRUE", "FALSE"
:type isIsolated: bool
:returns: API response
.. code-block:: python
[
{
"asset": "BTC",
"nextHourlyInterestRate": "0.00000571"
},
{
"asset": "ETH",
"nextHourlyInterestRate": "0.00000578"
}
]
"""
return self._request_margin_api(
"get", "margin/next-hourly-interest-rate", signed=True, data=params
)
```
Get Interest History (USER\_DATA)
[https://developers.binance.com/docs/margin\_trading/borrow-and-repay/Get-Interest-History](https://developers.binance.com/docs/margin_trading/borrow-and-repay/Get-Interest-History)
:param asset: optional
:type asset: str
:param isolatedSymbol: optional - isolated symbol
:type isolatedSymbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10 Max:100
:type size: int
:returns: API response
.. code-block:: python
\{
"rows": \[
\{
"txId": 1352286576452864727,
"interestAccuredTime": 1672160400000,
"asset": "USDT",
"rawAsset": “USDT”, // will not be returned for isolated margin
"principal": "45.3313",
"interest": "0.00024995",
"interestRate": "0.00013233",
"type": "ON\_BORROW",
"isolatedSymbol": "BNBUSDT" // isolated symbol, will not be returned for crossed margin
}
],
"total": 1
}
```python
def margin_interest_history(self, **params):
"""Get Interest History (USER_DATA)
https://developers.binance.com/docs/margin_trading/borrow-and-repay/Get-Interest-History
:param asset: optional
:type asset: str
:param isolatedSymbol: optional - isolated symbol
:type isolatedSymbol: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10 Max:100
:type size: int
:returns: API response
.. code-block:: python
{
"rows": [
{
"txId": 1352286576452864727,
"interestAccuredTime": 1672160400000,
"asset": "USDT",
"rawAsset": “USDT”, // will not be returned for isolated margin
"principal": "45.3313",
"interest": "0.00024995",
"interestRate": "0.00013233",
"type": "ON_BORROW",
"isolatedSymbol": "BNBUSDT" // isolated symbol, will not be returned for crossed margin
}
],
"total": 1
}
"""
return self._request_margin_api(
"get", "margin/interestHistory", signed=True, data=params
)
```
Margin Account Borrow/Repay (MARGIN)
[https://developers.binance.com/docs/margin\_trading/borrow-and-repay/Margin-Account-Borrow-Repay](https://developers.binance.com/docs/margin_trading/borrow-and-repay/Margin-Account-Borrow-Repay)
:param asset: required
:type asset: str
:param amount: required
:type amount: float
:param isIsolated: optional - for isolated margin or not, "TRUE", "FALSE", default "FALSE"
:type isIsolated: str
:param symbol: optional - isolated symbol
:type symbol: str
:param type: str
:type type: str - BORROW or REPAY
:returns: API response
.. code-block:: python
\{
//transaction id
"tranId": 100000001
}
```python
def margin_borrow_repay(self, **params):
"""Margin Account Borrow/Repay (MARGIN)
https://developers.binance.com/docs/margin_trading/borrow-and-repay/Margin-Account-Borrow-Repay
:param asset: required
:type asset: str
:param amount: required
:type amount: float
:param isIsolated: optional - for isolated margin or not, "TRUE", "FALSE", default "FALSE"
:type isIsolated: str
:param symbol: optional - isolated symbol
:type symbol: str
:param type: str
:type type: str - BORROW or REPAY
:returns: API response
.. code-block:: python
{
//transaction id
"tranId": 100000001
}
"""
return self._request_margin_api(
"post", "margin/borrow-repay", signed=True, data=params
)
```
Query Query borrow/repay records in Margin account (USER\_DATA)
[https://developers.binance.com/docs/margin\_trading/borrow-and-repay/Query-Borrow-Repay](https://developers.binance.com/docs/margin_trading/borrow-and-repay/Query-Borrow-Repay)
:param asset: required
:type asset: str
:param isolatedSymbol: optional - isolated symbol
:type isolatedSymbol: str
:param txId: optional - the tranId in POST /sapi/v1/margin/loan
:type txId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10 Max:100
:type size: int
:returns: API response
.. code-block:: python
\{
"rows": \[
\{
"type": "AUTO", // AUTO,MANUAL for Cross Margin Borrow; MANUAL,AUTO,BNB\_AUTO\_REPAY,POINT\_AUTO\_REPAY for Cross Margin Repay; AUTO,MANUAL for Isolated Margin Borrow/Repay;
"isolatedSymbol": "BNBUSDT", // isolated symbol, will not be returned for crossed margin
"amount": "14.00000000", // Total amount borrowed/repaid
"asset": "BNB",
"interest": "0.01866667", // Interest repaid
"principal": "13.98133333", // Principal repaid
"status": "CONFIRMED", //one of PENDING (pending execution), CONFIRMED (successfully execution), FAILED (execution failed, nothing happened to your account);
"timestamp": 1563438204000,
"txId": 2970933056
}
],
"total": 1
}
```python
def margin_get_borrow_repay_records(self, **params):
"""Query Query borrow/repay records in Margin account (USER_DATA)
https://developers.binance.com/docs/margin_trading/borrow-and-repay/Query-Borrow-Repay
:param asset: required
:type asset: str
:param isolatedSymbol: optional - isolated symbol
:type isolatedSymbol: str
:param txId: optional - the tranId in POST /sapi/v1/margin/loan
:type txId: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param current: optional - Currently querying page. Start from 1. Default:1
:type current: int
:param size: optional - Default:10 Max:100
:type size: int
:returns: API response
.. code-block:: python
{
"rows": [
{
"type": "AUTO", // AUTO,MANUAL for Cross Margin Borrow; MANUAL,AUTO,BNB_AUTO_REPAY,POINT_AUTO_REPAY for Cross Margin Repay; AUTO,MANUAL for Isolated Margin Borrow/Repay;
"isolatedSymbol": "BNBUSDT", // isolated symbol, will not be returned for crossed margin
"amount": "14.00000000", // Total amount borrowed/repaid
"asset": "BNB",
"interest": "0.01866667", // Interest repaid
"principal": "13.98133333", // Principal repaid
"status": "CONFIRMED", //one of PENDING (pending execution), CONFIRMED (successfully execution), FAILED (execution failed, nothing happened to your account);
"timestamp": 1563438204000,
"txId": 2970933056
}
],
"total": 1
}
"""
return self._request_margin_api(
"get", "margin/borrow-repay", signed=True, data=params
)
```
Query Margin Interest Rate History (USER\_DATA)
[https://developers.binance.com/docs/margin\_trading/borrow-and-repay/Query-Margin-Interest-Rate-History](https://developers.binance.com/docs/margin_trading/borrow-and-repay/Query-Margin-Interest-Rate-History)
:param asset: required
:type asset: str
:param vipLevel: optional
:type vipLevel: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:returns: API response
.. code-block:: python
\[
\{
"asset": "BTC",
"dailyInterestRate": "0.00025000",
"timestamp": 1611544731000,
"vipLevel": 1
},
\{
"asset": "BTC",
"dailyInterestRate": "0.00035000",
"timestamp": 1610248118000,
"vipLevel": 1
}
]
```python
def margin_interest_rate_history(self, **params):
"""Query Margin Interest Rate History (USER_DATA)
https://developers.binance.com/docs/margin_trading/borrow-and-repay/Query-Margin-Interest-Rate-History
:param asset: required
:type asset: str
:param vipLevel: optional
:type vipLevel: int
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:returns: API response
.. code-block:: python
[
{
"asset": "BTC",
"dailyInterestRate": "0.00025000",
"timestamp": 1611544731000,
"vipLevel": 1
},
{
"asset": "BTC",
"dailyInterestRate": "0.00035000",
"timestamp": 1610248118000,
"vipLevel": 1
}
]
"""
return self._request_margin_api(
"get", "margin/interestRateHistory", signed=True, data=params
)
```
Query Max Borrow (USER\_DATA)
[https://developers.binance.com/docs/margin\_trading/borrow-and-repay/Query-Max-Borrow](https://developers.binance.com/docs/margin_trading/borrow-and-repay/Query-Max-Borrow)
:param asset: required
:type asset: str
:param isolatedSymbol: optional - isolated symbol
:type isolatedSymbol: str
:returns: API response
.. code-block:: python
\{
"amount": "1.69248805", // account's currently max borrowable amount with sufficient system availability
"borrowLimit": "60" // max borrowable amount limited by the account level
}
```python
def margin_max_borrowable(self, **params):
"""Query Max Borrow (USER_DATA)
https://developers.binance.com/docs/margin_trading/borrow-and-repay/Query-Max-Borrow
:param asset: required
:type asset: str
:param isolatedSymbol: optional - isolated symbol
:type isolatedSymbol: str
:returns: API response
.. code-block:: python
{
"amount": "1.69248805", // account's currently max borrowable amount with sufficient system availability
"borrowLimit": "60" // max borrowable amount limited by the account level
}
"""
return self._request_margin_api(
"get", "margin/maxBorrowable", signed=True, data=params
)
```
Get Future TickLevel Orderbook Historical Data Download Link.
[https://developers.binance.com/docs/derivatives/futures-data/market-data](https://developers.binance.com/docs/derivatives/futures-data/market-data)
:param symbol: STRING - Required - Symbol name, e.g. BTCUSDT or BTCUSD\_PERP
:type symbol: str
:param dataType: ENUM - Required - Data type:
* T\_DEPTH for ticklevel orderbook data
* S\_DEPTH for orderbook snapshot data
:type dataType: str
:param startTime: LONG - Required - Start time in milliseconds
:type startTime: int
:param endTime: LONG - Required - End time in milliseconds
:type endTime: int
:param recvWindow: LONG - Optional - Number of milliseconds after timestamp the request is valid for
:type recvWindow: int
:param timestamp: LONG - Required - Current timestamp in milliseconds
:type timestamp: int
:returns: API response
.. code-block:: python
\{
"data": \[
\{
"day": "2023-06-30",
"url": ""
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
* The span between startTime and endTime can't be more than 7 days
* The download link will be valid for 1 day
* Only VIP users can query this endpoint
* Weight: 200
```python
def futures_historical_data_link(self, **params):
"""Get Future TickLevel Orderbook Historical Data Download Link.
https://developers.binance.com/docs/derivatives/futures-data/market-data
:param symbol: STRING - Required - Symbol name, e.g. BTCUSDT or BTCUSD_PERP
:type symbol: str
:param dataType: ENUM - Required - Data type:
- T_DEPTH for ticklevel orderbook data
- S_DEPTH for orderbook snapshot data
:type dataType: str
:param startTime: LONG - Required - Start time in milliseconds
:type startTime: int
:param endTime: LONG - Required - End time in milliseconds
:type endTime: int
:param recvWindow: LONG - Optional - Number of milliseconds after timestamp the request is valid for
:type recvWindow: int
:param timestamp: LONG - Required - Current timestamp in milliseconds
:type timestamp: int
:returns: API response
.. code-block:: python
{
"data": [
{
"day": "2023-06-30",
"url": ""
}
]
}
:raises: BinanceRequestException, BinanceAPIException
Notes:
- The span between startTime and endTime can't be more than 7 days
- The download link will be valid for 1 day
- Only VIP users can query this endpoint
- Weight: 200
"""
return self._request_margin_api("get", "futures/data/histDataLink", signed=True, data=params)
```
Placeholder function for GET /sapi/v1/loan/vip/ongoing/orders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
GET /sapi/v1/loan/vip/ongoing/orders
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_vip_ongoing_orders(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/vip/ongoing/orders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
GET /sapi/v1/loan/vip/ongoing/orders
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/vip/ongoing/orders", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/mining/payment/other.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Extra-Bonus-List](https://developers.binance.com/docs/mining/rest-api/Extra-Bonus-List)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_payment_other(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/payment/other.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Extra-Bonus-List
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/payment/other", signed=True, data=params, version=1)
```
Placeholder function for GET /dapi/v1/income/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Transaction-History-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Transaction-History-Download-Link-by-Id)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_coin_v1_get_income_asyn_id(self, **params):
"""
Placeholder function for GET /dapi/v1/income/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Futures-Transaction-History-Download-Link-by-Id
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_coin_api("get", "income/asyn/id", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/simple-earn/flexible/history/subscriptionRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/simple\_earn/history](https://developers.binance.com/docs/simple_earn/history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_simple_earn_flexible_history_subscription_record(self, **params):
"""
Placeholder function for GET /sapi/v1/simple-earn/flexible/history/subscriptionRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/simple_earn/history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "simple-earn/flexible/history/subscriptionRecord", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/lending/auto-invest/one-off.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_lending_auto_invest_one_off(self, **params):
"""
Placeholder function for POST /sapi/v1/lending/auto-invest/one-off.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "lending/auto-invest/one-off", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccountApi/commission/coinFutures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/fee/Change-Sub-Account-CM-Futures-Commission](https://developers.binance.com/docs/binance_link/exchange-link/fee/Change-Sub-Account-CM-Futures-Commission)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_api_commission_coin_futures(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccountApi/commission/coinFutures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/fee/Change-Sub-Account-CM-Futures-Commission
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi/commission/coinFutures", signed=True, data=params, version=1)
```
Placeholder function for POST /api/v3/orderList/otoco.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_post_order_list_otoco(self, **params):
"""
Placeholder function for POST /api/v3/orderList/otoco.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("post", "orderList/otoco", signed=True, data=params, version="v3")
```
Placeholder function for GET /fapi/v1/order/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Order-History](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Order-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_order_asyn(self, **params):
"""
Placeholder function for GET /fapi/v1/order/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Order-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "order/asyn", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/asset/custody/transfer-history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/asset/query-user-delegation](https://developers.binance.com/docs/wallet/asset/query-user-delegation)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_asset_custody_transfer_history(self, **params):
"""
Placeholder function for GET /sapi/v1/asset/custody/transfer-history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/asset/query-user-delegation
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "asset/custody/transfer-history", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccount/blvt.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_blvt(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccount/blvt.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccount/blvt", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/sol-staking/sol/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/staking/Redeem-SOL](https://developers.binance.com/docs/staking/sol-staking/staking/Redeem-SOL)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_sol_staking_sol_redeem(self, **params):
"""
Placeholder function for POST /sapi/v1/sol-staking/sol/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/staking/Redeem-SOL
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "sol-staking/sol/redeem", signed=True, data=params, version=1)
```
Placeholder function for GET /eapi/v1/countdownCancelAll.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Get-Auto-Cancel-All-Open-Orders-Config](https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Get-Auto-Cancel-All-Open-Orders-Config)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def options_v1_get_countdown_cancel_all(self, **params):
"""
Placeholder function for GET /eapi/v1/countdownCancelAll.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Get-Auto-Cancel-All-Open-Orders-Config
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_options_api("get", "countdownCancelAll", signed=True, data=params)
```
Placeholder function for GET /sapi/v1/margin/tradeCoeff.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/margin\_trading/account/Get-Summary-Of-Margin-Account](https://developers.binance.com/docs/margin_trading/account/Get-Summary-Of-Margin-Account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_margin_trade_coeff(self, **params):
"""
Placeholder function for GET /sapi/v1/margin/tradeCoeff.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/margin_trading/account/Get-Summary-Of-Margin-Account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "margin/tradeCoeff", signed=True, data=params, version=1)
```
Placeholder function for GET /dapi/v1/orderAmendment.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Get-Order-Modify-History](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Get-Order-Modify-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_coin_v1_get_order_amendment(self, **params):
"""
Placeholder function for GET /dapi/v1/orderAmendment.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Get-Order-Modify-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_coin_api("get", "orderAmendment", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/margin/available-inventory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/margin\_trading/market-data/Query-margin-avaliable-inventory](https://developers.binance.com/docs/margin_trading/market-data/Query-margin-avaliable-inventory)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_margin_available_inventory(self, **params):
"""
Placeholder function for GET /sapi/v1/margin/available-inventory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/margin_trading/market-data/Query-margin-avaliable-inventory
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "margin/available-inventory", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/account/apiRestrictions/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_account_api_restrictions_ip_restriction_ip_list(self, **params):
"""
Placeholder function for POST /sapi/v1/account/apiRestrictions/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "account/apiRestrictions/ipRestriction/ipList", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/eth-staking/account.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/eth-staking/account](https://developers.binance.com/docs/staking/eth-staking/account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_eth_staking_account(self, **params):
"""
Placeholder function for GET /sapi/v2/eth-staking/account.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/eth-staking/account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "eth-staking/account", signed=True, data=params, version=2)
```
Placeholder function for GET /sapi/v1/loan/income.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/stable-rate/market-data](https://developers.binance.com/docs/crypto_loan/stable-rate/market-data)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_income(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/income.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/stable-rate/market-data
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/income", signed=True, data=params, version=1)
```
Placeholder function for GET /dapi/v1/pmAccountInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/portfolio-margin-endpoints](https://developers.binance.com/docs/derivatives/coin-margined-futures/portfolio-margin-endpoints)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_coin_v1_get_pm_account_info(self, **params):
"""
Placeholder function for GET /dapi/v1/pmAccountInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/coin-margined-futures/portfolio-margin-endpoints
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_coin_api("get", "pmAccountInfo", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/managed-subaccount/queryTransLogForInvestor.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Investor](https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Investor)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_managed_subaccount_query_trans_log_for_investor(self, **params):
"""
Placeholder function for GET /sapi/v1/managed-subaccount/queryTransLogForInvestor.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Investor
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "managed-subaccount/queryTransLogForInvestor", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/dci/product/auto\_compound/edit-status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/dual\_investment/trade/Change-Auto-Compound-status](https://developers.binance.com/docs/dual_investment/trade/Change-Auto-Compound-status)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_dci_product_auto_compound_edit_status(self, **params):
"""
Placeholder function for POST /sapi/v1/dci/product/auto_compound/edit-status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/dual_investment/trade/Change-Auto-Compound-status
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "dci/product/auto_compound/edit-status", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/trade/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Trade-History](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Trade-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_trade_asyn(self, **params):
"""
Placeholder function for GET /fapi/v1/trade/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Trade-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "trade/asyn", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/loan/vip/request/interestRate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/vip\_loan/market-data](https://developers.binance.com/docs/vip_loan/market-data)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_vip_request_interest_rate(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/vip/request/interestRate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/vip_loan/market-data
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/vip/request/interestRate", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/fundingInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-Info](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-Info)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_funding_info(self, **params):
"""
Placeholder function for GET /fapi/v1/fundingInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Get-Funding-Rate-Info
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "fundingInfo", signed=False, data=params, version=1)
```
Placeholder function for GET /sapi/v2/loan/flexible/repay/rate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/user-information/Check-Collateral-Repay-Rate](https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Check-Collateral-Repay-Rate)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_loan_flexible_repay_rate(self, **params):
"""
Placeholder function for GET /sapi/v2/loan/flexible/repay/rate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Check-Collateral-Repay-Rate
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/flexible/repay/rate", signed=True, data=params, version=2)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/plan/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_plan_id(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/plan/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/plan/id", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/loan/adjust/ltv.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_loan_adjust_ltv(self, **params):
"""
Placeholder function for POST /sapi/v1/loan/adjust/ltv.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/adjust/ltv", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/mining/statistics/user/status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Statistic-List](https://developers.binance.com/docs/mining/rest-api/Statistic-List)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_statistics_user_status(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/statistics/user/status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Statistic-List
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/statistics/user/status", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/transfer/futures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset/Query-Sub-Account-Transfer-History-Futures](https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Transfer-History-Futures)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_transfer_futures(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/transfer/futures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Transfer-History-Futures
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/transfer/futures", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/algo/spot/newOrderTwap.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/algo/spot-algo/Time-Weighted-Average-Price-New-Order](https://developers.binance.com/docs/algo/spot-algo/Time-Weighted-Average-Price-New-Order)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_algo_spot_new_order_twap(self, **params):
"""
Placeholder function for POST /sapi/v1/algo/spot/newOrderTwap.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/algo/spot-algo/Time-Weighted-Average-Price-New-Order
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "algo/spot/newOrderTwap", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/target-asset/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_target_asset_list(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/target-asset/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/target-asset/list", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/capital/deposit/address/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/capital/deposite-address](https://developers.binance.com/docs/wallet/capital/deposite-address)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_capital_deposit_address_list(self, **params):
"""
Placeholder function for GET /sapi/v1/capital/deposit/address/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/capital/deposite-address
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "capital/deposit/address/list", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccount/bnbBurn/marginInterest.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Enable-Or-Disable-BNB-Burn-for-Sub-Account-Margin-Interest](https://developers.binance.com/docs/binance_link/exchange-link/account/Enable-Or-Disable-BNB-Burn-for-Sub-Account-Margin-Interest)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_bnb_burn_margin_interest(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccount/bnbBurn/marginInterest.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Enable-Or-Disable-BNB-Burn-for-Sub-Account-Margin-Interest
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccount/bnbBurn/marginInterest", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v2/loan/flexible/repay.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/trade/Flexible-Loan-Repay](https://developers.binance.com/docs/crypto_loan/flexible-rate/trade/Flexible-Loan-Repay)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_post_loan_flexible_repay(self, **params):
"""
Placeholder function for POST /sapi/v2/loan/flexible/repay.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/trade/Flexible-Loan-Repay
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/flexible/repay", signed=True, data=params, version=2)
```
Placeholder function for GET /sapi/v2/loan/flexible/loanable/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/market-data/Get-Flexible-Loan-Assets-Data](https://developers.binance.com/docs/crypto_loan/flexible-rate/market-data/Get-Flexible-Loan-Assets-Data)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_loan_flexible_loanable_data(self, **params):
"""
Placeholder function for GET /sapi/v2/loan/flexible/loanable/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/market-data/Get-Flexible-Loan-Assets-Data
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/flexible/loanable/data", signed=True, data=params, version=2)
```
Placeholder function for POST /sapi/v1/broker/subAccountApi/permission.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Change-Sub-Account-Api-Permission](https://developers.binance.com/docs/binance_link/exchange-link/account/Change-Sub-Account-Api-Permission)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_api_permission(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccountApi/permission.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Change-Sub-Account-Api-Permission
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi/permission", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccountApi.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Create-Api-Key-for-Sub-Account](https://developers.binance.com/docs/binance_link/exchange-link/account/Create-Api-Key-for-Sub-Account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_api(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccountApi.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Create-Api-Key-for-Sub-Account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/dci/product/positions.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/dual\_investment/trade/Get-Dual-Investment-positions](https://developers.binance.com/docs/dual_investment/trade/Get-Dual-Investment-positions)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_dci_product_positions(self, **params):
"""
Placeholder function for GET /sapi/v1/dci/product/positions.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/dual_investment/trade/Get-Dual-Investment-positions
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "dci/product/positions", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/convert/limit/cancelOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/convert/trade/Cancel-Order](https://developers.binance.com/docs/convert/trade/Cancel-Order)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_convert_limit_cancel_order(self, **params):
"""
Placeholder function for POST /sapi/v1/convert/limit/cancelOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/convert/trade/Cancel-Order
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "convert/limit/cancelOrder", signed=True, data=params, version=1)
```
Placeholder function for POST /api/v3/orderList/oto.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_post_order_list_oto(self, **params):
"""
Placeholder function for POST /api/v3/orderList/oto.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("post", "orderList/oto", signed=True, data=params, version="v3")
```
Placeholder function for GET /sapi/v1/mining/hash-transfer/config/details/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-List](https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-List)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_hash_transfer_config_details_list(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/hash-transfer/config/details/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-List
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/hash-transfer/config/details/list", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/mining/hash-transfer/profit/details.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-Detail](https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-Detail)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_hash_transfer_profit_details(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/hash-transfer/profit/details.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-Detail
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/hash-transfer/profit/details", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/subAccount.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Query-Sub-Account](https://developers.binance.com/docs/binance_link/exchange-link/account/Query-Sub-Account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccount.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Query-Sub-Account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccount", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/portfolio/balance.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Get-Classic-Portfolio-Margin-Balance-Info](https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Get-Classic-Portfolio-Margin-Balance-Info)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_portfolio_balance(self, **params):
"""
Placeholder function for GET /sapi/v1/portfolio/balance.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Get-Classic-Portfolio-Margin-Balance-Info
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "portfolio/balance", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/sub-account/eoptions/enable.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/account-management/Enable-Options-for-Sub-account](https://developers.binance.com/docs/sub_account/account-management/Enable-Options-for-Sub-account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_sub_account_eoptions_enable(self, **params):
"""
Placeholder function for POST /sapi/v1/sub-account/eoptions/enable.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/account-management/Enable-Options-for-Sub-account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "sub-account/eoptions/enable", signed=True, data=params, version=1)
```
Placeholder function for POST /papi/v1/ping.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def papi_v1_post_ping(self, **params):
"""
Placeholder function for POST /papi/v1/ping.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_papi_api("post", "ping", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/loan/loanable/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_loanable_data(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/loanable/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/loanable/data", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/eth-staking/wbeth/unwrap.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_eth_staking_wbeth_unwrap(self, **params):
"""
Placeholder function for POST /sapi/v1/eth-staking/wbeth/unwrap.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "eth-staking/wbeth/unwrap", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/eth-staking/eth/history/stakingHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/eth-staking/history](https://developers.binance.com/docs/staking/eth-staking/history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_eth_staking_eth_history_staking_history(self, **params):
"""
Placeholder function for GET /sapi/v1/eth-staking/eth/history/stakingHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/eth-staking/history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "eth-staking/eth/history/stakingHistory", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/staking/stakingRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_staking_staking_record(self, **params):
"""
Placeholder function for GET /sapi/v1/staking/stakingRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "staking/stakingRecord", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/rebate/recentRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/fee/Query-Spot-Commission-Rebate-Recent-Record](https://developers.binance.com/docs/binance_link/exchange-link/fee/Query-Spot-Commission-Rebate-Recent-Record)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_rebate_recent_record(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/rebate/recentRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/fee/Query-Spot-Commission-Rebate-Recent-Record
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/rebate/recentRecord", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/loan/vip/collateral/account.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/vip\_loan/user-information/Check-Locked-Value-of-VIP-Collateral-Account](https://developers.binance.com/docs/vip_loan/user-information/Check-Locked-Value-of-VIP-Collateral-Account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_vip_collateral_account(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/vip/collateral/account.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/vip_loan/user-information/Check-Locked-Value-of-VIP-Collateral-Account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/vip/collateral/account", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/algo/spot/openOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/algo/spot-algo/Query-Current-Algo-Open-Orders](https://developers.binance.com/docs/algo/spot-algo/Query-Current-Algo-Open-Orders)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_algo_spot_open_orders(self, **params):
"""
Placeholder function for GET /sapi/v1/algo/spot/openOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/algo/spot-algo/Query-Current-Algo-Open-Orders
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "algo/spot/openOrders", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/loan/repay.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_loan_repay(self, **params):
"""
Placeholder function for POST /sapi/v1/loan/repay.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/repay", signed=True, data=params, version=1)
```
Placeholder function for GET /dapi/v1/fundingInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Info](https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Info)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_coin_v1_get_funding_info(self, **params):
"""
Placeholder function for GET /dapi/v1/fundingInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/rest-api/Get-Funding-Info
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_coin_api("get", "fundingInfo", signed=False, data=params, version=1)
```
Placeholder function for GET /sapi/v1/margin/leverageBracket.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/margin\_trading/market-data/Query-Liability-Coin-Leverage-Bracket-in-Cross-Margin-Pro-Mode](https://developers.binance.com/docs/margin_trading/market-data/Query-Liability-Coin-Leverage-Bracket-in-Cross-Margin-Pro-Mode)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_margin_leverage_bracket(self, **params):
"""
Placeholder function for GET /sapi/v1/margin/leverageBracket.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/margin_trading/market-data/Query-Liability-Coin-Leverage-Bracket-in-Cross-Margin-Pro-Mode
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "margin/leverageBracket", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/portfolio/collateralRate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/portfolio-margin-pro/market-data/Portfolio-Margin-Pro-Tiered-Collateral-Rate](https://developers.binance.com/docs/derivatives/portfolio-margin-pro/market-data/Portfolio-Margin-Pro-Tiered-Collateral-Rate)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_portfolio_collateral_rate(self, **params):
"""
Placeholder function for GET /sapi/v2/portfolio/collateralRate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/portfolio-margin-pro/market-data/Portfolio-Margin-Pro-Tiered-Collateral-Rate
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "portfolio/collateralRate", signed=True, data=params, version=2)
```
Placeholder function for POST /sapi/v2/loan/flexible/adjust/ltv.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/trade/Flexible-Loan-Adjust-LTV](https://developers.binance.com/docs/crypto_loan/flexible-rate/trade/Flexible-Loan-Adjust-LTV)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_post_loan_flexible_adjust_ltv(self, **params):
"""
Placeholder function for POST /sapi/v2/loan/flexible/adjust/ltv.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/trade/Flexible-Loan-Adjust-LTV
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/flexible/adjust/ltv", signed=True, data=params, version=2)
```
Placeholder function for GET /sapi/v1/convert/orderStatus.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/convert/trade/Order-Status](https://developers.binance.com/docs/convert/trade/Order-Status)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_convert_order_status(self, **params):
"""
Placeholder function for GET /sapi/v1/convert/orderStatus.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/convert/trade/Order-Status
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "convert/orderStatus", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Get-IPRestriction-for-Sub-Account-Api-Key](https://developers.binance.com/docs/binance_link/exchange-link/account/Get-IPRestriction-for-Sub-Account-Api-Key)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account_api_ip_restriction(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Get-IPRestriction-for-Sub-Account-Api-Key
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccountApi/ipRestriction", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/dci/product/subscribe.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/dual\_investment/trade](https://developers.binance.com/docs/dual_investment/trade)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_dci_product_subscribe(self, **params):
"""
Placeholder function for POST /sapi/v1/dci/product/subscribe.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/dual_investment/trade
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "dci/product/subscribe", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/income/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Transaction-History-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Transaction-History-Download-Link-by-Id)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_income_asyn_id(self, **params):
"""
Placeholder function for GET /fapi/v1/income/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Transaction-History-Download-Link-by-Id
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "income/asyn/id", signed=True, data=params, version=1)
```
Placeholder function for POST /eapi/v1/countdownCancelAll.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Set-Auto-Cancel-All-Open-Orders-Config](https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Set-Auto-Cancel-All-Open-Orders-Config)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def options_v1_post_countdown_cancel_all(self, **params):
"""
Placeholder function for POST /eapi/v1/countdownCancelAll.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Set-Auto-Cancel-All-Open-Orders-Config
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_options_api("post", "countdownCancelAll", signed=True, data=params)
```
Placeholder function for POST /sapi/v1/mining/hash-transfer/config/cancel.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Cancel-hashrate-resale-configuration](https://developers.binance.com/docs/mining/rest-api/Cancel-hashrate-resale-configuration)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_mining_hash_transfer_config_cancel(self, **params):
"""
Placeholder function for POST /sapi/v1/mining/hash-transfer/config/cancel.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Cancel-hashrate-resale-configuration
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "mining/hash-transfer/config/cancel", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/subAccount/depositHist.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset/Get-Sub-Account-Deposit-History](https://developers.binance.com/docs/binance_link/exchange-link/asset/Get-Sub-Account-Deposit-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account_deposit_hist(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccount/depositHist.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset/Get-Sub-Account-Deposit-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccount/depositHist", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/mining/payment/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Earnings-List](https://developers.binance.com/docs/mining/rest-api/Earnings-List)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_payment_list(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/payment/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Earnings-List
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/payment/list", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/pmAccountInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/portfolio-margin-endpoints](https://developers.binance.com/docs/derivatives/usds-margined-futures/portfolio-margin-endpoints)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_pm_account_info(self, **params):
"""
Placeholder function for GET /fapi/v1/pmAccountInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/portfolio-margin-endpoints
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "pmAccountInfo", signed=True, data=params, version=1)
```
Placeholder function for GET /dapi/v1/adlQuantile.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-ADL-Quantile-Estimation](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-ADL-Quantile-Estimation)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_coin_v1_get_adl_quantile(self, **params):
"""
Placeholder function for GET /dapi/v1/adlQuantile.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Position-ADL-Quantile-Estimation
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_coin_api("get", "adlQuantile", signed=True, data=params, version=1)
```
Placeholder function for GET /eapi/v1/income/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/option/account/Get-Option-Transaction-History-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/option/account/Get-Option-Transaction-History-Download-Link-by-Id)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def options_v1_get_income_asyn_id(self, **params):
"""
Placeholder function for GET /eapi/v1/income/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/option/account/Get-Option-Transaction-History-Download-Link-by-Id
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_options_api("get", "income/asyn/id", signed=True, data=params)
```
Placeholder function for POST /api/v3/cancelReplace.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_post_cancel_replace(self, **params):
"""
Placeholder function for POST /api/v3/cancelReplace.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("post", "cancelReplace", signed=True, data=params, version="v3")
```
Placeholder function for POST /sapi/v1/account/enableFastWithdrawSwitch.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/account/enable-fast-withdraw-switch](https://developers.binance.com/docs/wallet/account/enable-fast-withdraw-switch)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_account_enable_fast_withdraw_switch(self, **params):
"""
Placeholder function for POST /sapi/v1/account/enableFastWithdrawSwitch.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/account/enable-fast-withdraw-switch
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "account/enableFastWithdrawSwitch", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/transfer/futures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset/Sub-Account-Transfer-Futures](https://developers.binance.com/docs/binance_link/exchange-link/asset/Sub-Account-Transfer-Futures)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_transfer_futures(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/transfer/futures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset/Sub-Account-Transfer-Futures
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/transfer/futures", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/sol-staking/sol/stake.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/staking](https://developers.binance.com/docs/staking/sol-staking/staking)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_sol_staking_sol_stake(self, **params):
"""
Placeholder function for POST /sapi/v1/sol-staking/sol/stake.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/staking
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "sol-staking/sol/stake", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/loan/borrow.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_loan_borrow(self, **params):
"""
Placeholder function for POST /sapi/v1/loan/borrow.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/borrow", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/managed-subaccount/info.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Query-Managed-Sub-account-List](https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-List)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_managed_subaccount_info(self, **params):
"""
Placeholder function for GET /sapi/v1/managed-subaccount/info.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-List
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "managed-subaccount/info", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/lending/auto-invest/plan/edit-status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_lending_auto_invest_plan_edit_status(self, **params):
"""
Placeholder function for POST /sapi/v1/lending/auto-invest/plan/edit-status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "lending/auto-invest/plan/edit-status", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sol-staking/sol/history/unclaimedRewards.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/history/Get-Unclaimed-rewards](https://developers.binance.com/docs/staking/sol-staking/history/Get-Unclaimed-rewards)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sol_staking_sol_history_unclaimed_rewards(self, **params):
"""
Placeholder function for GET /sapi/v1/sol-staking/sol/history/unclaimedRewards.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/history/Get-Unclaimed-rewards
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sol-staking/sol/history/unclaimedRewards", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/asset/convert-transfer/queryByPage.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_asset_convert_transfer_query_by_page(self, **params):
"""
Placeholder function for POST /sapi/v1/asset/convert-transfer/queryByPage.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "asset/convert-transfer/queryByPage", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sol-staking/sol/history/boostRewardsHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/history/Get-Boost-rewards-History](https://developers.binance.com/docs/staking/sol-staking/history/Get-Boost-rewards-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sol_staking_sol_history_boost_rewards_history(self, **params):
"""
Placeholder function for GET /sapi/v1/sol-staking/sol/history/boostRewardsHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/history/Get-Boost-rewards-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sol-staking/sol/history/boostRewardsHistory", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/one-off/status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_one_off_status(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/one-off/status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/one-off/status", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccount.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account](https://developers.binance.com/docs/binance_link/exchange-link/account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccount.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccount", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/asset/cloud-mining-payment-and-refund-history](https://developers.binance.com/docs/wallet/asset/cloud-mining-payment-and-refund-history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_asset_ledger_transfer_cloud_mining_query_by_page(self, **params):
"""
Placeholder function for GET /sapi/v1/asset/ledger-transfer/cloud-mining/queryByPage.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/asset/cloud-mining-payment-and-refund-history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "asset/ledger-transfer/cloud-mining/queryByPage", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/mining/pub/coinList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Acquiring-CoinName](https://developers.binance.com/docs/mining/rest-api/Acquiring-CoinName)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_pub_coin_list(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/pub/coinList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Acquiring-CoinName
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/pub/coinList", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/loan/flexible/repay/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/user-information/Get-Flexible-Loan-Repayment-History](https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Get-Flexible-Loan-Repayment-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_loan_flexible_repay_history(self, **params):
"""
Placeholder function for GET /sapi/v2/loan/flexible/repay/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Get-Flexible-Loan-Repayment-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/flexible/repay/history", signed=True, data=params, version=2)
```
Placeholder function for POST /api/v3/sor/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_post_sor_order(self, **params):
"""
Placeholder function for POST /api/v3/sor/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("post", "sor/order", signed=True, data=params, version="v3")
```
Placeholder function for POST /sapi/v1/capital/deposit/credit-apply.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/capital/one-click-arrival-deposite-apply](https://developers.binance.com/docs/wallet/capital/one-click-arrival-deposite-apply)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_capital_deposit_credit_apply(self, **params):
"""
Placeholder function for POST /sapi/v1/capital/deposit/credit-apply.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/capital/one-click-arrival-deposite-apply
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "capital/deposit/credit-apply", signed=True, data=params, version=1)
```
Placeholder function for PUT /fapi/v1/batchOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_put_batch_order(self, **params):
"""
Placeholder function for PUT /fapi/v1/batchOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("put", "batchOrder", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/mining/statistics/user/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Account-List](https://developers.binance.com/docs/mining/rest-api/Account-List)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_statistics_user_list(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/statistics/user/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Account-List
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/statistics/user/list", signed=True, data=params, version=1)
```
Placeholder function for POST /fapi/v1/batchOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_post_batch_order(self, **params):
"""
Placeholder function for POST /fapi/v1/batchOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("post", "batchOrder", signed=True, data=params, version=1)
```
Placeholder function for GET /api/v3/ticker/tradingDay.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_get_ticker_trading_day(self, **params):
"""
Placeholder function for GET /api/v3/ticker/tradingDay.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("get", "ticker/tradingDay", signed=False, data=params, version="v3")
```
Placeholder function for GET /sapi/v1/mining/worker/detail.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Request-for-Detail-Miner-List](https://developers.binance.com/docs/mining/rest-api/Request-for-Detail-Miner-List)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_worker_detail(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/worker/detail.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Request-for-Detail-Miner-List
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/worker/detail", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/managed-subaccount/fetch-future-asset.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Query-Managed-Sub-account-Futures-Asset-Details](https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Futures-Asset-Details)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_managed_subaccount_fetch_future_asset(self, **params):
"""
Placeholder function for GET /sapi/v1/managed-subaccount/fetch-future-asset.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Futures-Asset-Details
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "managed-subaccount/fetch-future-asset", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/margin/rateLimit/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/margin\_trading/trade/Query-Current-Margin-Order-Count-Usage](https://developers.binance.com/docs/margin_trading/trade/Query-Current-Margin-Order-Count-Usage)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_margin_rate_limit_order(self, **params):
"""
Placeholder function for GET /sapi/v1/margin/rateLimit/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/margin_trading/trade/Query-Current-Margin-Order-Count-Usage
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "margin/rateLimit/order", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/localentity/vasp.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/travel-rule/onboarded-vasp-list](https://developers.binance.com/docs/wallet/travel-rule/onboarded-vasp-list)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_localentity_vasp(self, **params):
"""
Placeholder function for GET /sapi/v1/localentity/vasp.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/travel-rule/onboarded-vasp-list
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "localentity/vasp", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sol-staking/sol/history/rateHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/history/Get-BNSOL-Rate-History](https://developers.binance.com/docs/staking/sol-staking/history/Get-BNSOL-Rate-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sol_staking_sol_history_rate_history(self, **params):
"""
Placeholder function for GET /sapi/v1/sol-staking/sol/history/rateHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/history/Get-BNSOL-Rate-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sol-staking/sol/history/rateHistory", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_api_ip_restriction(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi/ipRestriction", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/transfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset/Query-Sub-Account-Transfer-History-Spot](https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Transfer-History-Spot)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_transfer(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/transfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Transfer-History-Spot
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/transfer", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sol-staking/account.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/account](https://developers.binance.com/docs/staking/sol-staking/account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sol_staking_account(self, **params):
"""
Placeholder function for GET /sapi/v1/sol-staking/account.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sol-staking/account", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/account/info.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/account](https://developers.binance.com/docs/wallet/account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_account_info(self, **params):
"""
Placeholder function for GET /sapi/v1/account/info.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "account/info", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/portfolio/repay-futures-switch.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Change-Auto-repay-futures-Status](https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Change-Auto-repay-futures-Status)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_portfolio_repay_futures_switch(self, **params):
"""
Placeholder function for POST /sapi/v1/portfolio/repay-futures-switch.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Change-Auto-repay-futures-Status
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "portfolio/repay-futures-switch", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/loan/vip/borrow.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_loan_vip_borrow(self, **params):
"""
Placeholder function for POST /sapi/v1/loan/vip/borrow.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/vip/borrow", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/loan/flexible/ltv/adjustment/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/user-information](https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_loan_flexible_ltv_adjustment_history(self, **params):
"""
Placeholder function for GET /sapi/v2/loan/flexible/ltv/adjustment/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/flexible/ltv/adjustment/history", signed=True, data=params, version=2)
```
Placeholder function for DELETE /eapi/v1/allOpenOrdersByUnderlying.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/option/trade/Cancel-All-Option-Orders-By-Underlying](https://developers.binance.com/docs/derivatives/option/trade/Cancel-All-Option-Orders-By-Underlying)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def options_v1_delete_all_open_orders_by_underlying(self, **params):
"""
Placeholder function for DELETE /eapi/v1/allOpenOrdersByUnderlying.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/option/trade/Cancel-All-Option-Orders-By-Underlying
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_options_api("delete", "allOpenOrdersByUnderlying", signed=True, data=params)
```
Placeholder function for GET /sapi/v1/broker/subAccount/futuresSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account_futures_summary(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccount/futuresSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccount/futuresSummary", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/subAccount/spotSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset/Query-Sub-Account-Spot-Asset-Info](https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Spot-Asset-Info)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account_spot_summary(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccount/spotSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Spot-Asset-Info
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccount/spotSummary", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/sub-account/blvt/enable.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_sub_account_blvt_enable(self, **params):
"""
Placeholder function for POST /sapi/v1/sub-account/blvt/enable.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "sub-account/blvt/enable", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/algo/spot/historicalOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/algo/spot-algo/Query-Historical-Algo-Orders](https://developers.binance.com/docs/algo/spot-algo/Query-Historical-Algo-Orders)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_algo_spot_historical_orders(self, **params):
"""
Placeholder function for GET /sapi/v1/algo/spot/historicalOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/algo/spot-algo/Query-Historical-Algo-Orders
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "algo/spot/historicalOrders", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/loan/vip/repay/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/vip\_loan/user-information/Get-VIP-Loan-Repayment-History](https://developers.binance.com/docs/vip_loan/user-information/Get-VIP-Loan-Repayment-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_vip_repay_history(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/vip/repay/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/vip_loan/user-information/Get-VIP-Loan-Repayment-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/vip/repay/history", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/loan/borrow/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/stable-rate/user-information](https://developers.binance.com/docs/crypto_loan/stable-rate/user-information)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_borrow_history(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/borrow/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/stable-rate/user-information
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/borrow/history", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/lending/auto-invest/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_lending_auto_invest_redeem(self, **params):
"""
Placeholder function for POST /sapi/v1/lending/auto-invest/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "lending/auto-invest/redeem", signed=True, data=params, version=1)
```
Placeholder function for GET /dapi/v1/income/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Transaction-History](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Transaction-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_coin_v1_get_income_asyn(self, **params):
"""
Placeholder function for GET /dapi/v1/income/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Transaction-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_coin_api("get", "income/asyn", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/managed-subaccount/deposit.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account](https://developers.binance.com/docs/sub_account/managed-sub-account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_managed_subaccount_deposit(self, **params):
"""
Placeholder function for POST /sapi/v1/managed-subaccount/deposit.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "managed-subaccount/deposit", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/lending/daily/purchase.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_lending_daily_purchase(self, **params):
"""
Placeholder function for POST /sapi/v1/lending/daily/purchase.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "lending/daily/purchase", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/trade/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Trade-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Trade-Download-Link-by-Id)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_trade_asyn_id(self, **params):
"""
Placeholder function for GET /fapi/v1/trade/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Trade-Download-Link-by-Id
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "trade/asyn/id", signed=True, data=params, version=1)
```
Placeholder function for DELETE /sapi/v1/sub-account/subAccountApi/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/api-management/Delete-IP-List-For-a-Sub-account-API-Key](https://developers.binance.com/docs/sub_account/api-management/Delete-IP-List-For-a-Sub-account-API-Key)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_delete_sub_account_sub_account_api_ip_restriction_ip_list(self, **params):
"""
Placeholder function for DELETE /sapi/v1/sub-account/subAccountApi/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/api-management/Delete-IP-List-For-a-Sub-account-API-Key
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("delete", "sub-account/subAccountApi/ipRestriction/ipList", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/copyTrading/futures/userStatus.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/copy\_trading/future-copy-trading](https://developers.binance.com/docs/copy_trading/future-copy-trading)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_copy_trading_futures_user_status(self, **params):
"""
Placeholder function for GET /sapi/v1/copyTrading/futures/userStatus.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/copy_trading/future-copy-trading
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "copyTrading/futures/userStatus", signed=True, data=params, version=1)
```
Placeholder function for GET /eapi/v1/marginAccount.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/option/market-maker-endpoints](https://developers.binance.com/docs/derivatives/option/market-maker-endpoints)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def options_v1_get_margin_account(self, **params):
"""
Placeholder function for GET /eapi/v1/marginAccount.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/option/market-maker-endpoints
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_options_api("get", "marginAccount", signed=True, data=params)
```
Get config for MMP.
[https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Get-Market-Maker-Protection-Config](https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Get-Market-Maker-Protection-Config)
:param underlying: required
:type underlying: str
:param recvWindow: optional
:type recvWindow: int
```python
def options_get_market_maker_protection_config(self, **params):
"""
Get config for MMP.
https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Get-Market-Maker-Protection-Config
:param underlying: required
:type underlying: str
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("get", "mmp", signed=True, data=params)
```
Set config for MMP.
[https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Set-Market-Maker-Protection-Config](https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Set-Market-Maker-Protection-Config)
:param underlying: required
:type underlying: str
:param windowTimeInMilliseconds: required
:type windowTimeInMilliseconds: int
:param frozenTimeInMilliseconds: required
:type frozenTimeInMilliseconds: int
:param qtyLimit: required
:type qtyLimit: decimal
:param deltaLimit: required
:type deltaLimit: decimal
:param recvWindow: optional
:type recvWindow: int
```python
def options_post_market_maker_protection_config(self, **params):
"""
Set config for MMP.
https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Set-Market-Maker-Protection-Config
:param underlying: required
:type underlying: str
:param windowTimeInMilliseconds: required
:type windowTimeInMilliseconds: int
:param frozenTimeInMilliseconds: required
:type frozenTimeInMilliseconds: int
:param qtyLimit: required
:type qtyLimit: decimal
:param deltaLimit: required
:type deltaLimit: decimal
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("post", "mmpSet", signed=True, data=params)
```
Reset MMP, start MMP order again.
[https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Reset-Market-Maker-Protection-Config](https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Reset-Market-Maker-Protection-Config)
:param underlying: required
:type underlying: str
:param recvWindow: optional
:type recvWindow: int
```python
def options_reset_market_maker_protection_config(self, **params):
"""
Reset MMP, start MMP order again.
https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Reset-Market-Maker-Protection-Config
:param underlying: required
:type underlying: str
:param recvWindow: optional
:type recvWindow: int
"""
return self._request_options_api("post", "mmpReset", signed=True, data=params)
```
Placeholder function for POST /sapi/v1/localentity/withdraw/apply.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/travel-rule/withdraw](https://developers.binance.com/docs/wallet/travel-rule/withdraw)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_localentity_withdraw_apply(self, **params):
"""
Placeholder function for POST /sapi/v1/localentity/withdraw/apply.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/travel-rule/withdraw
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "localentity/withdraw/apply", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/asset/wallet/balance.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/asset/query-user-wallet-balance](https://developers.binance.com/docs/wallet/asset/query-user-wallet-balance)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_asset_wallet_balance(self, **params):
"""
Placeholder function for GET /sapi/v1/asset/wallet/balance.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/asset/query-user-wallet-balance
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "asset/wallet/balance", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/transfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset](https://developers.binance.com/docs/binance_link/exchange-link/asset)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_transfer(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/transfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/transfer", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/lending/customizedFixed/purchase.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_lending_customized_fixed_purchase(self, **params):
"""
Placeholder function for POST /sapi/v1/lending/customizedFixed/purchase.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "lending/customizedFixed/purchase", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/algo/futures/newOrderTwap.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/algo/future-algo/Time-Weighted-Average-Price-New-Order](https://developers.binance.com/docs/algo/future-algo/Time-Weighted-Average-Price-New-Order)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_algo_futures_new_order_twap(self, **params):
"""
Placeholder function for POST /sapi/v1/algo/futures/newOrderTwap.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/algo/future-algo/Time-Weighted-Average-Price-New-Order
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "algo/futures/newOrderTwap", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v2/eth-staking/eth/stake.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/eth-staking/staking](https://developers.binance.com/docs/staking/eth-staking/staking)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_post_eth_staking_eth_stake(self, **params):
"""
Placeholder function for POST /sapi/v2/eth-staking/eth/stake.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/eth-staking/staking
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "eth-staking/eth/stake", signed=True, data=params, version=2)
```
Placeholder function for POST /sapi/v1/loan/flexible/repay/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_loan_flexible_repay_history(self, **params):
"""
Placeholder function for POST /sapi/v1/loan/flexible/repay/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/flexible/repay/history", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/index/info.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_index_info(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/index/info.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/index/info", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sol-staking/sol/history/redemptionHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/history/Get-SOL-redemption-history](https://developers.binance.com/docs/staking/sol-staking/history/Get-SOL-redemption-history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sol_staking_sol_history_redemption_history(self, **params):
"""
Placeholder function for GET /sapi/v1/sol-staking/sol/history/redemptionHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/history/Get-SOL-redemption-history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sol-staking/sol/history/redemptionHistory", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/rebate/futures/recentRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/fee/Query-Futures-Commission-Rebate-Record](https://developers.binance.com/docs/binance_link/exchange-link/fee/Query-Futures-Commission-Rebate-Record)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_rebate_futures_recent_record(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/rebate/futures/recentRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/fee/Query-Futures-Commission-Rebate-Record
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/rebate/futures/recentRecord", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v3/broker/subAccount/futuresSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset/Query-Sub-Account-Futures-Asset-Info](https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Futures-Asset-Info)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v3_get_broker_sub_account_futures_summary(self, **params):
"""
Placeholder function for GET /sapi/v3/broker/subAccount/futuresSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Futures-Asset-Info
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccount/futuresSummary", signed=True, data=params, version=3)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/target-asset/roi/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_target_asset_roi_list(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/target-asset/roi/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/target-asset/roi/list", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/universalTransfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset/Query-Universal-Transfer-History](https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Universal-Transfer-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_universal_transfer(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/universalTransfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Universal-Transfer-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/universalTransfer", signed=True, data=params, version=1)
```
Placeholder function for PUT /fapi/v1/batchOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Multiple-Orders](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Multiple-Orders)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_put_batch_orders(self, **params):
"""
Placeholder function for PUT /fapi/v1/batchOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Modify-Multiple-Orders
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("put", "batchOrders", signed=True, data=params, version=1)
```
Placeholder function for POST /eapi/v1/countdownCancelAllHeartBeat.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Auto-Cancel-All-Open-Orders-Heartbeat](https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Auto-Cancel-All-Open-Orders-Heartbeat)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def options_v1_post_countdown_cancel_all_heart_beat(self, **params):
"""
Placeholder function for POST /eapi/v1/countdownCancelAllHeartBeat.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/option/market-maker-endpoints/Auto-Cancel-All-Open-Orders-Heartbeat
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_options_api("post", "countdownCancelAllHeartBeat", signed=True, data=params)
```
Placeholder function for GET /sapi/v1/loan/collateral/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_collateral_data(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/collateral/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/collateral/data", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/loan/repay/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/stable-rate/user-information/Get-Loan-Repayment-History](https://developers.binance.com/docs/crypto_loan/stable-rate/user-information/Get-Loan-Repayment-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_repay_history(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/repay/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/stable-rate/user-information/Get-Loan-Repayment-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/repay/history", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/convert/limit/placeOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/convert/trade/Place-Order](https://developers.binance.com/docs/convert/trade/Place-Order)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_convert_limit_place_order(self, **params):
"""
Placeholder function for POST /sapi/v1/convert/limit/placeOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/convert/trade/Place-Order
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "convert/limit/placeOrder", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/convert/exchangeInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/convert](https://developers.binance.com/docs/derivatives/usds-margined-futures/convert)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_convert_exchange_info(self, **params):
"""
Placeholder function for GET /fapi/v1/convert/exchangeInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/convert
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "convert/exchangeInfo", signed=False, data=params, version=1)
```
Placeholder function for GET /api/v3/allOrderList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_get_all_order_list(self, **params):
"""
Placeholder function for GET /api/v3/allOrderList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("get", "allOrderList", signed=True, data=params, version="v3")
```
Placeholder function for DELETE /sapi/v1/broker/subAccountApi/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Delete-IPRestriction-for-Sub-Account-Api-Key](https://developers.binance.com/docs/binance_link/exchange-link/account/Delete-IPRestriction-for-Sub-Account-Api-Key)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_delete_broker_sub_account_api_ip_restriction_ip_list(self, **params):
"""
Placeholder function for DELETE /sapi/v1/broker/subAccountApi/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Delete-IPRestriction-for-Sub-Account-Api-Key
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("delete", "broker/subAccountApi/ipRestriction/ipList", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/sub-account/virtualSubAccount.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/account-management](https://developers.binance.com/docs/sub_account/account-management)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_sub_account_virtual_sub_account(self, **params):
"""
Placeholder function for POST /sapi/v1/sub-account/virtualSubAccount.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/account-management
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "sub-account/virtualSubAccount", signed=True, data=params, version=1)
```
Placeholder function for PUT /sapi/v1/localentity/deposit/provide-info.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/travel-rule/deposit-provide-info](https://developers.binance.com/docs/wallet/travel-rule/deposit-provide-info)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_put_localentity_deposit_provide_info(self, **params):
"""
Placeholder function for PUT /sapi/v1/localentity/deposit/provide-info.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/travel-rule/deposit-provide-info
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("put", "localentity/deposit/provide-info", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/portfolio/mint.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Mint-BFUSD-Portfolio-Margin](https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Mint-BFUSD-Portfolio-Margin)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_portfolio_mint(self, **params):
"""
Placeholder function for POST /sapi/v1/portfolio/mint.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Mint-BFUSD-Portfolio-Margin
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "portfolio/mint", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/orderAmendment.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Get-Order-Modify-History](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Get-Order-Modify-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_order_amendment(self, **params):
"""
Placeholder function for GET /fapi/v1/orderAmendment.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Get-Order-Modify-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "orderAmendment", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/sol-staking/sol/claim.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/staking/Claim-Boost-rewards](https://developers.binance.com/docs/staking/sol-staking/staking/Claim-Boost-rewards)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_sol_staking_sol_claim(self, **params):
"""
Placeholder function for POST /sapi/v1/sol-staking/sol/claim.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/staking/Claim-Boost-rewards
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "sol-staking/sol/claim", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/lending/daily/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_lending_daily_redeem(self, **params):
"""
Placeholder function for POST /sapi/v1/lending/daily/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "lending/daily/redeem", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/mining/hash-transfer/config.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-Request](https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-Request)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_mining_hash_transfer_config(self, **params):
"""
Placeholder function for POST /sapi/v1/mining/hash-transfer/config.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Hashrate-Resale-Request
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "mining/hash-transfer/config", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/rebalance/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_rebalance_history(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/rebalance/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/rebalance/history", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/loan/repay/collateral/rate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_repay_collateral_rate(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/repay/collateral/rate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/repay/collateral/rate", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/income/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Transaction-History](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Transaction-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_income_asyn(self, **params):
"""
Placeholder function for GET /fapi/v1/income/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Download-Id-For-Futures-Transaction-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "income/asyn", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/mining/payment/uid.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Mining-Account-Earning](https://developers.binance.com/docs/mining/rest-api/Mining-Account-Earning)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_payment_uid(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/payment/uid.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Mining-Account-Earning
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/payment/uid", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/loan/flexible/borrow/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/user-information/Get-Flexible-Loan-Borrow-History](https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Get-Flexible-Loan-Borrow-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_loan_flexible_borrow_history(self, **params):
"""
Placeholder function for GET /sapi/v2/loan/flexible/borrow/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Get-Flexible-Loan-Borrow-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/flexible/borrow/history", signed=True, data=params, version=2)
```
Placeholder function for GET /sapi/v1/capital/contract/convertible-coins.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_capital_contract_convertible_coins(self, **params):
"""
Placeholder function for GET /sapi/v1/capital/contract/convertible-coins.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "capital/contract/convertible-coins", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccountApi/permission/vanillaOptions.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_api_permission_vanilla_options(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccountApi/permission/vanillaOptions.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi/permission/vanillaOptions", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/redeem/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/travel-rule/withdraw-history](https://developers.binance.com/docs/wallet/travel-rule/withdraw-history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_redeem_history(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/redeem/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/travel-rule/withdraw-history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/redeem/history", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/localentity/withdraw/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/travel-rule/withdraw-history-v2](https://developers.binance.com/docs/wallet/travel-rule/withdraw-history-v2)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_localentity_withdraw_history(self, **params):
"""
Placeholder function for GET /sapi/v2/localentity/withdraw/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/travel-rule/withdraw-history-v2
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "localentity/withdraw/history", signed=True, data=params, version=2)
```
Placeholder function for GET /sapi/v1/eth-staking/eth/history/redemptionHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/eth-staking/history/Get-ETH-redemption-history](https://developers.binance.com/docs/staking/eth-staking/history/Get-ETH-redemption-history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_eth_staking_eth_history_redemption_history(self, **params):
"""
Placeholder function for GET /sapi/v1/eth-staking/eth/history/redemptionHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/eth-staking/history/Get-ETH-redemption-history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "eth-staking/eth/history/redemptionHistory", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/feeBurn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-BNB-Burn-Status](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-BNB-Burn-Status)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_fee_burn(self, **params):
"""
Placeholder function for GET /fapi/v1/feeBurn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-BNB-Burn-Status
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "feeBurn", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/index/user-summary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_index_user_summary(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/index/user-summary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/index/user-summary", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v2/loan/flexible/borrow.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/trade](https://developers.binance.com/docs/crypto_loan/flexible-rate/trade)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_post_loan_flexible_borrow(self, **params):
"""
Placeholder function for POST /sapi/v2/loan/flexible/borrow.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/trade
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/flexible/borrow", signed=True, data=params, version=2)
```
Placeholder function for POST /sapi/v1/loan/vip/repay.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/vip\_loan/trade/VIP-Loan-Repay](https://developers.binance.com/docs/vip_loan/trade/VIP-Loan-Repay)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_loan_vip_repay(self, **params):
"""
Placeholder function for POST /sapi/v1/loan/vip/repay.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/vip_loan/trade/VIP-Loan-Repay
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/vip/repay", signed=True, data=params, version=1)
```
Placeholder function for GET /dapi/v1/commissionRate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/User-Commission-Rate](https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/User-Commission-Rate)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_coin_v1_get_commission_rate(self, **params):
"""
Placeholder function for GET /dapi/v1/commissionRate.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/coin-margined-futures/account/rest-api/User-Commission-Rate
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_coin_api("get", "commissionRate", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/convert/assetInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/convert/market-data/Query-order-quantity-precision-per-asset](https://developers.binance.com/docs/convert/market-data/Query-order-quantity-precision-per-asset)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_convert_asset_info(self, **params):
"""
Placeholder function for GET /sapi/v1/convert/assetInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/convert/market-data/Query-order-quantity-precision-per-asset
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "convert/assetInfo", signed=True, data=params, version=1)
```
Placeholder function for POST /api/v3/sor/order/test.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_post_sor_order_test(self, **params):
"""
Placeholder function for POST /api/v3/sor/order/test.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("post", "sor/order/test", signed=True, data=params, version="v3")
```
Placeholder function for POST /sapi/v1/broker/universalTransfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset/Universal-Transfer](https://developers.binance.com/docs/binance_link/exchange-link/asset/Universal-Transfer)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_universal_transfer(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/universalTransfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset/Universal-Transfer
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/universalTransfer", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/account/disableFastWithdrawSwitch.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/account/disable-fast-withdraw-switch](https://developers.binance.com/docs/wallet/account/disable-fast-withdraw-switch)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_account_disable_fast_withdraw_switch(self, **params):
"""
Placeholder function for POST /sapi/v1/account/disableFastWithdrawSwitch.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/account/disable-fast-withdraw-switch
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "account/disableFastWithdrawSwitch", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/assetIndex.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Multi-Assets-Mode-Asset-Index](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Multi-Assets-Mode-Asset-Index)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_asset_index(self, **params):
"""
Placeholder function for GET /fapi/v1/assetIndex.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Multi-Assets-Mode-Asset-Index
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "assetIndex", signed=False, data=params, version=1)
```
Placeholder function for GET /sapi/v1/account/apiRestrictions/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_account_api_restrictions_ip_restriction(self, **params):
"""
Placeholder function for GET /sapi/v1/account/apiRestrictions/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "account/apiRestrictions/ipRestriction", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccount/bnbBurn/spot.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Enable-Or-Disable-BNB-Burn-for-Sub-Account-Spot-Margin](https://developers.binance.com/docs/binance_link/exchange-link/account/Enable-Or-Disable-BNB-Burn-for-Sub-Account-Spot-Margin)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_bnb_burn_spot(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccount/bnbBurn/spot.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Enable-Or-Disable-BNB-Burn-for-Sub-Account-Spot-Margin
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccount/bnbBurn/spot", signed=True, data=params, version=1)
```
Placeholder function for PUT /dapi/v1/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Order](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Order)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_coin_v1_put_order(self, **params):
"""
Placeholder function for PUT /dapi/v1/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Order
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_coin_api("put", "order", signed=True, data=params, version=1)
```
Placeholder function for PUT /dapi/v1/batchOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Multiple-Orders](https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Multiple-Orders)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_coin_v1_put_batch_orders(self, **params):
"""
Placeholder function for PUT /dapi/v1/batchOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/coin-margined-futures/trade/rest-api/Modify-Multiple-Orders
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_coin_api("put", "batchOrders", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/margin/delist-schedule.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_margin_delist_schedule(self, **params):
"""
Placeholder function for GET /sapi/v1/margin/delist-schedule.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "margin/delist-schedule", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccountApi/permission/universalTransfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Enable-Universal-Transfer-Permission-For-SubAccount-Api-Key](https://developers.binance.com/docs/binance_link/exchange-link/account/Enable-Universal-Transfer-Permission-For-SubAccount-Api-Key)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_api_permission_universal_transfer(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccountApi/permission/universalTransfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Enable-Universal-Transfer-Permission-For-SubAccount-Api-Key
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi/permission/universalTransfer", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/loan/ltv/adjustment/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/stable-rate/user-information/Get-Loan-LTV-Adjustment-History](https://developers.binance.com/docs/crypto_loan/stable-rate/user-information/Get-Loan-LTV-Adjustment-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_ltv_adjustment_history(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/ltv/adjustment/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/stable-rate/user-information/Get-Loan-LTV-Adjustment-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/ltv/adjustment/history", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/localentity/withdraw/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_localentity_withdraw_history(self, **params):
"""
Placeholder function for GET /sapi/v1/localentity/withdraw/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "localentity/withdraw/history", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v2/sub-account/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/api-management/Add-IP-Restriction-for-Sub-Account-API-key](https://developers.binance.com/docs/sub_account/api-management/Add-IP-Restriction-for-Sub-Account-API-key)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_post_sub_account_sub_account_api_ip_restriction(self, **params):
"""
Placeholder function for POST /sapi/v2/sub-account/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/api-management/Add-IP-Restriction-for-Sub-Account-API-key
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "sub-account/subAccountApi/ipRestriction", signed=True, data=params, version=2)
```
Placeholder function for GET /fapi/v1/rateLimit/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Query-Rate-Limit](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Query-Rate-Limit)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_rate_limit_order(self, **params):
"""
Placeholder function for GET /fapi/v1/rateLimit/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Query-Rate-Limit
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "rateLimit/order", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/subAccountApi/commission/futures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/fee/Query-Sub-Account-UM-Futures-Commission](https://developers.binance.com/docs/binance_link/exchange-link/fee/Query-Sub-Account-UM-Futures-Commission)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account_api_commission_futures(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccountApi/commission/futures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/fee/Query-Sub-Account-UM-Futures-Commission
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccountApi/commission/futures", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sol-staking/sol/history/stakingHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/history](https://developers.binance.com/docs/staking/sol-staking/history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sol_staking_sol_history_staking_history(self, **params):
"""
Placeholder function for GET /sapi/v1/sol-staking/sol/history/stakingHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sol-staking/sol/history/stakingHistory", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/openOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Current-Open-Order](https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Current-Open-Order)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_open_order(self, **params):
"""
Placeholder function for GET /fapi/v1/openOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Query-Current-Open-Order
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "openOrder", signed=True, data=params, version=1)
```
Placeholder function for DELETE /sapi/v1/algo/spot/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/algo/spot-algo/Cancel-Algo-Order](https://developers.binance.com/docs/algo/spot-algo/Cancel-Algo-Order)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_delete_algo_spot_order(self, **params):
"""
Placeholder function for DELETE /sapi/v1/algo/spot/order.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/algo/spot-algo/Cancel-Algo-Order
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("delete", "algo/spot/order", signed=True, data=params, version=1)
```
Placeholder function for DELETE /sapi/v1/account/apiRestrictions/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_delete_account_api_restrictions_ip_restriction_ip_list(self, **params):
"""
Placeholder function for DELETE /sapi/v1/account/apiRestrictions/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("delete", "account/apiRestrictions/ipRestriction/ipList", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/capital/contract/convertible-coins.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_capital_contract_convertible_coins(self, **params):
"""
Placeholder function for POST /sapi/v1/capital/contract/convertible-coins.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "capital/contract/convertible-coins", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/managed-subaccount/marginAsset.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Query-Managed-Sub-account-Margin-Asset-Details](https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Margin-Asset-Details)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_managed_subaccount_margin_asset(self, **params):
"""
Placeholder function for GET /sapi/v1/managed-subaccount/marginAsset.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Margin-Asset-Details
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "managed-subaccount/marginAsset", signed=True, data=params, version=1)
```
Placeholder function for DELETE /api/v3/orderList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_delete_order_list(self, **params):
"""
Placeholder function for DELETE /api/v3/orderList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("delete", "orderList", signed=True, data=params, version="v3")
```
Placeholder function for POST /sapi/v1/sub-account/subAccountApi/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_sub_account_sub_account_api_ip_restriction_ip_list(self, **params):
"""
Placeholder function for POST /sapi/v1/sub-account/subAccountApi/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "sub-account/subAccountApi/ipRestriction/ipList", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccountApi/commission.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/fee](https://developers.binance.com/docs/binance_link/exchange-link/fee)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_api_commission(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccountApi/commission.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/fee
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi/commission", signed=True, data=params, version=1)
```
Placeholder function for POST /fapi/v1/feeBurn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Toggle-BNB-Burn-On-Futures-Trade](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Toggle-BNB-Burn-On-Futures-Trade)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_post_fee_burn(self, **params):
"""
Placeholder function for POST /fapi/v1/feeBurn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Toggle-BNB-Burn-On-Futures-Trade
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("post", "feeBurn", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/subAccount/marginSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/asset/Query-Sub-Account-Margin-Asset-Info](https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Margin-Asset-Info)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account_margin_summary(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccount/marginSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/asset/Query-Sub-Account-Margin-Asset-Info
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccount/marginSummary", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/plan/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_plan_list(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/plan/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/plan/list", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/loan/vip/loanable/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/vip\_loan/market-data/Get-Loanable-Assets-Data](https://developers.binance.com/docs/vip_loan/market-data/Get-Loanable-Assets-Data)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_vip_loanable_data(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/vip/loanable/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/vip_loan/market-data/Get-Loanable-Assets-Data
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/vip/loanable/data", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/loan/flexible/collateral/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/market-data](https://developers.binance.com/docs/crypto_loan/flexible-rate/market-data)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_loan_flexible_collateral_data(self, **params):
"""
Placeholder function for GET /sapi/v2/loan/flexible/collateral/data.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/market-data
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/flexible/collateral/data", signed=True, data=params, version=2)
```
Placeholder function for DELETE /sapi/v1/broker/subAccountApi.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Delete-Sub-Account-Api-Key](https://developers.binance.com/docs/binance_link/exchange-link/account/Delete-Sub-Account-Api-Key)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_delete_broker_sub_account_api(self, **params):
"""
Placeholder function for DELETE /sapi/v1/broker/subAccountApi.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Delete-Sub-Account-Api-Key
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("delete", "broker/subAccountApi", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sol-staking/sol/history/bnsolRewardsHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/history/Get-BNSOL-rewards-history](https://developers.binance.com/docs/staking/sol-staking/history/Get-BNSOL-rewards-history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sol_staking_sol_history_bnsol_rewards_history(self, **params):
"""
Placeholder function for GET /sapi/v1/sol-staking/sol/history/bnsolRewardsHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/history/Get-BNSOL-rewards-history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sol-staking/sol/history/bnsolRewardsHistory", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/convert/limit/queryOpenOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/convert/trade/Query-Order](https://developers.binance.com/docs/convert/trade/Query-Order)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_convert_limit_query_open_orders(self, **params):
"""
Placeholder function for GET /sapi/v1/convert/limit/queryOpenOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/convert/trade/Query-Order
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "convert/limit/queryOpenOrders", signed=True, data=params, version=1)
```
Placeholder function for GET /api/v3/account/commission.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_get_account_commission(self, **params):
"""
Placeholder function for GET /api/v3/account/commission.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("get", "account/commission", signed=True, data=params, version="v3")
```
Placeholder function for GET /sapi/v1/managed-subaccount/query-trans-log.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Sub](https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Sub)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_managed_subaccount_query_trans_log(self, **params):
"""
Placeholder function for GET /sapi/v1/managed-subaccount/query-trans-log.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Sub
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "managed-subaccount/query-trans-log", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v2/broker/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Update-IP-Restriction-for-Sub-Account-API-key-For-Master-Account](https://developers.binance.com/docs/binance_link/exchange-link/account/Update-IP-Restriction-for-Sub-Account-API-key-For-Master-Account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_post_broker_sub_account_api_ip_restriction(self, **params):
"""
Placeholder function for POST /sapi/v2/broker/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Update-IP-Restriction-for-Sub-Account-API-key-For-Master-Account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi/ipRestriction", signed=True, data=params, version=2)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/all/asset.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_all_asset(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/all/asset.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/all/asset", signed=True, data=params, version=1)
```
Placeholder function for POST /fapi/v1/convert/acceptQuote.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Accept-Quote](https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Accept-Quote)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_post_convert_accept_quote(self, **params):
"""
Placeholder function for POST /fapi/v1/convert/acceptQuote.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Accept-Quote
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("post", "convert/acceptQuote", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/spot/delist-schedule.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/asset/spot-delist-schedule](https://developers.binance.com/docs/wallet/asset/spot-delist-schedule)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_spot_delist_schedule(self, **params):
"""
Placeholder function for GET /sapi/v1/spot/delist-schedule.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/asset/spot-delist-schedule
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "spot/delist-schedule", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/account/apiRestrictions/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_account_api_restrictions_ip_restriction(self, **params):
"""
Placeholder function for POST /sapi/v1/account/apiRestrictions/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "account/apiRestrictions/ipRestriction", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/dci/product/accounts.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/dual\_investment/trade/Check-Dual-Investment-accounts](https://developers.binance.com/docs/dual_investment/trade/Check-Dual-Investment-accounts)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_dci_product_accounts(self, **params):
"""
Placeholder function for GET /sapi/v1/dci/product/accounts.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/dual_investment/trade/Check-Dual-Investment-accounts
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "dci/product/accounts", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sub-account/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/api-management](https://developers.binance.com/docs/sub_account/api-management)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sub_account_sub_account_api_ip_restriction(self, **params):
"""
Placeholder function for GET /sapi/v1/sub-account/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/api-management
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sub-account/subAccountApi/ipRestriction", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sub-account/transaction-statistics.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/account-management/Query-Sub-account-Transaction-Statistics](https://developers.binance.com/docs/sub_account/account-management/Query-Sub-account-Transaction-Statistics)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sub_account_transaction_statistics(self, **params):
"""
Placeholder function for GET /sapi/v1/sub-account/transaction-statistics.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/account-management/Query-Sub-account-Transaction-Statistics
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sub-account/transaction-statistics", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/managed-subaccount/deposit/address.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Get-Managed-Sub-account-Deposit-Address](https://developers.binance.com/docs/sub_account/managed-sub-account/Get-Managed-Sub-account-Deposit-Address)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_managed_subaccount_deposit_address(self, **params):
"""
Placeholder function for GET /sapi/v1/managed-subaccount/deposit/address.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Get-Managed-Sub-account-Deposit-Address
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "managed-subaccount/deposit/address", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/portfolio/account.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Get-Classic-Portfolio-Margin-Account-Info-V2](https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Get-Classic-Portfolio-Margin-Account-Info-V2)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_portfolio_account(self, **params):
"""
Placeholder function for GET /sapi/v2/portfolio/account.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Get-Classic-Portfolio-Margin-Account-Info-V2
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "portfolio/account", signed=True, data=params, version=2)
```
Placeholder function for GET /sapi/v1/simple-earn/locked/history/redemptionRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/simple\_earn/history/Get-Locked-Redemption-Record](https://developers.binance.com/docs/simple_earn/history/Get-Locked-Redemption-Record)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_simple_earn_locked_history_redemption_record(self, **params):
"""
Placeholder function for GET /sapi/v1/simple-earn/locked/history/redemptionRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/simple_earn/history/Get-Locked-Redemption-Record
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "simple-earn/locked/history/redemptionRecord", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/order/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Order-History-Download-Link-by-Id](https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Order-History-Download-Link-by-Id)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_order_asyn_id(self, **params):
"""
Placeholder function for GET /fapi/v1/order/asyn/id.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Futures-Order-History-Download-Link-by-Id
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "order/asyn/id", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/managed-subaccount/withdraw.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Withdrawl-Assets-From-The-Managed-Sub-account](https://developers.binance.com/docs/sub_account/managed-sub-account/Withdrawl-Assets-From-The-Managed-Sub-account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_managed_subaccount_withdraw(self, **params):
"""
Placeholder function for POST /sapi/v1/managed-subaccount/withdraw.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Withdrawl-Assets-From-The-Managed-Sub-account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "managed-subaccount/withdraw", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/localentity/deposit/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/wallet/travel-rule/deposit-history](https://developers.binance.com/docs/wallet/travel-rule/deposit-history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_localentity_deposit_history(self, **params):
"""
Placeholder function for GET /sapi/v1/localentity/deposit/history.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/wallet/travel-rule/deposit-history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "localentity/deposit/history", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/eth-staking/wbeth/wrap.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/eth-staking/staking/Wrap-BETH](https://developers.binance.com/docs/staking/eth-staking/staking/Wrap-BETH)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_eth_staking_wbeth_wrap(self, **params):
"""
Placeholder function for POST /sapi/v1/eth-staking/wbeth/wrap.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/eth-staking/staking/Wrap-BETH
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "eth-staking/wbeth/wrap", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/simple-earn/locked/setRedeemOption.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/simple\_earn/earn/Set-Locked-Redeem-Option](https://developers.binance.com/docs/simple_earn/earn/Set-Locked-Redeem-Option)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_simple_earn_locked_set_redeem_option(self, **params):
"""
Placeholder function for POST /sapi/v1/simple-earn/locked/setRedeemOption.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/simple_earn/earn/Set-Locked-Redeem-Option
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "simple-earn/locked/setRedeemOption", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccountApi/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_api_ip_restriction_ip_list(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccountApi/ipRestriction/ipList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi/ipRestriction/ipList", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/broker/subAccountApi/commission/futures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/fee/Change-Sub-Account-UM-Futures-Commission](https://developers.binance.com/docs/binance_link/exchange-link/fee/Change-Sub-Account-UM-Futures-Commission)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_broker_sub_account_api_commission_futures(self, **params):
"""
Placeholder function for POST /sapi/v1/broker/subAccountApi/commission/futures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/fee/Change-Sub-Account-UM-Futures-Commission
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "broker/subAccountApi/commission/futures", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/lending/auto-invest/history/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_history_list(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/history/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/history/list", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/loan/customize/margin\_call.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_loan_customize_margin_call(self, **params):
"""
Placeholder function for POST /sapi/v1/loan/customize/margin_call.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/customize/margin_call", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/subAccount/bnbBurn/status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Get-BNB-Burn-Status-for-Sub-Account](https://developers.binance.com/docs/binance_link/exchange-link/account/Get-BNB-Burn-Status-for-Sub-Account)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account_bnb_burn_status(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccount/bnbBurn/status.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Get-BNB-Burn-Status-for-Sub-Account
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccount/bnbBurn/status", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/managed-subaccount/accountSnapshot.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Query-Managed-Sub-account-Snapshot](https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Snapshot)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_managed_subaccount_account_snapshot(self, **params):
"""
Placeholder function for GET /sapi/v1/managed-subaccount/accountSnapshot.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Snapshot
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "managed-subaccount/accountSnapshot", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/asset/convert-transfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_asset_convert_transfer(self, **params):
"""
Placeholder function for POST /sapi/v1/asset/convert-transfer.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "asset/convert-transfer", signed=True, data=params, version=1)
```
Placeholder function for GET /eapi/v1/income/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/option/account/Get-Download-Id-For-Option-Transaction-History](https://developers.binance.com/docs/derivatives/option/account/Get-Download-Id-For-Option-Transaction-History)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def options_v1_get_income_asyn(self, **params):
"""
Placeholder function for GET /eapi/v1/income/asyn.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/option/account/Get-Download-Id-For-Option-Transaction-History
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_options_api("get", "income/asyn", signed=True, data=params)
```
Placeholder function for GET /sapi/v1/broker/subAccountApi/commission/coinFutures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/fee/Query-Sub-Account-CM-Futures-Commission](https://developers.binance.com/docs/binance_link/exchange-link/fee/Query-Sub-Account-CM-Futures-Commission)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account_api_commission_coin_futures(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccountApi/commission/coinFutures.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/fee/Query-Sub-Account-CM-Futures-Commission
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccountApi/commission/coinFutures", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/broker/subAccount/futuresSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_broker_sub_account_futures_summary(self, **params):
"""
Placeholder function for GET /sapi/v2/broker/subAccount/futuresSummary.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccount/futuresSummary", signed=True, data=params, version=2)
```
Placeholder function for GET /sapi/v1/loan/ongoing/orders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_loan_ongoing_orders(self, **params):
"""
Placeholder function for GET /sapi/v1/loan/ongoing/orders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/ongoing/orders", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v2/loan/flexible/ongoing/orders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/crypto\_loan/flexible-rate/user-information/Get-Flexible-Loan-Ongoing-Orders](https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Get-Flexible-Loan-Ongoing-Orders)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v2_get_loan_flexible_ongoing_orders(self, **params):
"""
Placeholder function for GET /sapi/v2/loan/flexible/ongoing/orders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/crypto_loan/flexible-rate/user-information/Get-Flexible-Loan-Ongoing-Orders
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "loan/flexible/ongoing/orders", signed=True, data=params, version=2)
```
Placeholder function for POST /sapi/v1/algo/futures/newOrderVp.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/algo/future-algo](https://developers.binance.com/docs/algo/future-algo)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_algo_futures_new_order_vp(self, **params):
"""
Placeholder function for POST /sapi/v1/algo/futures/newOrderVp.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/algo/future-algo
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "algo/futures/newOrderVp", signed=True, data=params, version=1)
```
Placeholder function for POST /fapi/v1/convert/getQuote.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Send-quote-request](https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Send-quote-request)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_post_convert_get_quote(self, **params):
"""
Placeholder function for POST /fapi/v1/convert/getQuote.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Send-quote-request
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("post", "convert/getQuote", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/algo/spot/subOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/algo/spot-algo/Query-Sub-Orders](https://developers.binance.com/docs/algo/spot-algo/Query-Sub-Orders)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_algo_spot_sub_orders(self, **params):
"""
Placeholder function for GET /sapi/v1/algo/spot/subOrders.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/algo/spot-algo/Query-Sub-Orders
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "algo/spot/subOrders", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/portfolio/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Redeem-BFUSD-Portfolio-Margin](https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Redeem-BFUSD-Portfolio-Margin)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_portfolio_redeem(self, **params):
"""
Placeholder function for POST /sapi/v1/portfolio/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/portfolio-margin-pro/account/Redeem-BFUSD-Portfolio-Margin
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "portfolio/redeem", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/lending/auto-invest/plan/add.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_lending_auto_invest_plan_add(self, **params):
"""
Placeholder function for POST /sapi/v1/lending/auto-invest/plan/add.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "lending/auto-invest/plan/add", signed=True, data=params, version=1)
```
Placeholder function for GET /api/v3/orderList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def v3_get_order_list(self, **params):
"""
Placeholder function for GET /api/v3/orderList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_api("get", "orderList", signed=True, data=params, version="v3")
```
Placeholder function for GET /sapi/v1/lending/auto-invest/source-asset/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_lending_auto_invest_source_asset_list(self, **params):
"""
Placeholder function for GET /sapi/v1/lending/auto-invest/source-asset/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "lending/auto-invest/source-asset/list", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/margin/allOrderList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/margin\_trading/trade/Query-Margin-Account-All-OCO](https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-All-OCO)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_margin_all_order_list(self, **params):
"""
Placeholder function for GET /sapi/v1/margin/allOrderList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/margin_trading/trade/Query-Margin-Account-All-OCO
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "margin/allOrderList", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/eth-staking/eth/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/eth-staking/staking/Redeem-ETH](https://developers.binance.com/docs/staking/eth-staking/staking/Redeem-ETH)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_eth_staking_eth_redeem(self, **params):
"""
Placeholder function for POST /sapi/v1/eth-staking/eth/redeem.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/eth-staking/staking/Redeem-ETH
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "eth-staking/eth/redeem", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/rebate/historicalRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_rebate_historical_record(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/rebate/historicalRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/rebate/historicalRecord", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/simple-earn/locked/history/subscriptionRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/simple\_earn/history/Get-Locked-Subscription-Record](https://developers.binance.com/docs/simple_earn/history/Get-Locked-Subscription-Record)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_simple_earn_locked_history_subscription_record(self, **params):
"""
Placeholder function for GET /sapi/v1/simple-earn/locked/history/subscriptionRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/simple_earn/history/Get-Locked-Subscription-Record
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "simple-earn/locked/history/subscriptionRecord", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/managed-subaccount/asset.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Query-Managed-Sub-account-Asset-Details](https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Asset-Details)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_managed_subaccount_asset(self, **params):
"""
Placeholder function for GET /sapi/v1/managed-subaccount/asset.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-account-Asset-Details
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "managed-subaccount/asset", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/sol-staking/sol/quota.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/sol-staking/account/Get-SOL-staking-quota-details](https://developers.binance.com/docs/staking/sol-staking/account/Get-SOL-staking-quota-details)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_sol_staking_sol_quota(self, **params):
"""
Placeholder function for GET /sapi/v1/sol-staking/sol/quota.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/sol-staking/account/Get-SOL-staking-quota-details
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "sol-staking/sol/quota", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/loan/vip/renew.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_loan_vip_renew(self, **params):
"""
Placeholder function for POST /sapi/v1/loan/vip/renew.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "loan/vip/renew", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/managed-subaccount/queryTransLogForTradeParent.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/sub\_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Master](https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Master)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_managed_subaccount_query_trans_log_for_trade_parent(self, **params):
"""
Placeholder function for GET /sapi/v1/managed-subaccount/queryTransLogForTradeParent.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/sub_account/managed-sub-account/Query-Managed-Sub-Account-Transfer-Log-Trading-Team-Master
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "managed-subaccount/queryTransLogForTradeParent", signed=True, data=params, version=1)
```
Placeholder function for POST /sapi/v1/sub-account/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_post_sub_account_sub_account_api_ip_restriction(self, **params):
"""
Placeholder function for POST /sapi/v1/sub-account/subAccountApi/ipRestriction.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("post", "sub-account/subAccountApi/ipRestriction", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/simple-earn/flexible/history/redemptionRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/simple\_earn/history/Get-Flexible-Redemption-Record](https://developers.binance.com/docs/simple_earn/history/Get-Flexible-Redemption-Record)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_simple_earn_flexible_history_redemption_record(self, **params):
"""
Placeholder function for GET /sapi/v1/simple-earn/flexible/history/redemptionRecord.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/simple_earn/history/Get-Flexible-Redemption-Record
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "simple-earn/flexible/history/redemptionRecord", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/broker/subAccountApi.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/binance\_link/exchange-link/account/Query-Sub-Account-Api-Key](https://developers.binance.com/docs/binance_link/exchange-link/account/Query-Sub-Account-Api-Key)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_broker_sub_account_api(self, **params):
"""
Placeholder function for GET /sapi/v1/broker/subAccountApi.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/binance_link/exchange-link/account/Query-Sub-Account-Api-Key
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "broker/subAccountApi", signed=True, data=params, version=1)
```
Placeholder function for GET /eapi/v1/exerciseHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/option/market-data/Historical-Exercise-Records](https://developers.binance.com/docs/derivatives/option/market-data/Historical-Exercise-Records)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def options_v1_get_exercise_history(self, **params):
"""
Placeholder function for GET /eapi/v1/exerciseHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/option/market-data/Historical-Exercise-Records
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_options_api("get", "exerciseHistory", signed=False, data=params)
```
Get present open interest specific underlying asset on specific expiration date.
[https://developers.binance.com/docs/derivatives/option/market-data/Open-Interest](https://developers.binance.com/docs/derivatives/option/market-data/Open-Interest)
:param params: parameters required by the endpoint
:type params: dict
:param underlyingAsset: required
:type underlyingAsset: str
:param expiration: required (e.g '221225')
:type expiration: str
```python
def options_open_interest(self, **params):
"""Get present open interest specific underlying asset on specific expiration date.
https://developers.binance.com/docs/derivatives/option/market-data/Open-Interest
:param params: parameters required by the endpoint
:type params: dict
:param underlyingAsset: required
:type underlyingAsset: str
:param expiration: required (e.g '221225')
:type expiration: str
"""
return self._request_options_api("get", "openInterest", data=params)
```
Placeholder function for GET /sapi/v1/convert/exchangeInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/convert/market-data](https://developers.binance.com/docs/convert/market-data)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_convert_exchange_info(self, **params):
"""
Placeholder function for GET /sapi/v1/convert/exchangeInfo.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/convert/market-data
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "convert/exchangeInfo", signed=False, data=params, version=1)
```
Placeholder function for DELETE /fapi/v1/batchOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_delete_batch_order(self, **params):
"""
Placeholder function for DELETE /fapi/v1/batchOrder.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("delete", "batchOrder", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/eth-staking/eth/history/wbethRewardsHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/staking/eth-staking/history/Get-WBETH-rewards-history](https://developers.binance.com/docs/staking/eth-staking/history/Get-WBETH-rewards-history)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_eth_staking_eth_history_wbeth_rewards_history(self, **params):
"""
Placeholder function for GET /sapi/v1/eth-staking/eth/history/wbethRewardsHistory.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/staking/eth-staking/history/Get-WBETH-rewards-history
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "eth-staking/eth/history/wbethRewardsHistory", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/mining/pub/algoList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api](https://developers.binance.com/docs/mining/rest-api)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_pub_algo_list(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/pub/algoList.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/pub/algoList", signed=True, data=params, version=1)
```
Placeholder function for GET /eapi/v1/blockTrades.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/option/market-data/Recent-Block-Trade-List](https://developers.binance.com/docs/derivatives/option/market-data/Recent-Block-Trade-List)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def options_v1_get_block_trades(self, **params):
"""
Placeholder function for GET /eapi/v1/blockTrades.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/option/market-data/Recent-Block-Trade-List
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_options_api("get", "blockTrades", signed=False, data=params)
```
Placeholder function for GET /sapi/v1/copyTrading/futures/leadSymbol.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/copy\_trading/future-copy-trading/Get-Futures-Lead-Trading-Symbol-Whitelist](https://developers.binance.com/docs/copy_trading/future-copy-trading/Get-Futures-Lead-Trading-Symbol-Whitelist)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_copy_trading_futures_lead_symbol(self, **params):
"""
Placeholder function for GET /sapi/v1/copyTrading/futures/leadSymbol.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/copy_trading/future-copy-trading/Get-Futures-Lead-Trading-Symbol-Whitelist
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "copyTrading/futures/leadSymbol", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/mining/worker/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/mining/rest-api/Request-for-Miner-List](https://developers.binance.com/docs/mining/rest-api/Request-for-Miner-List)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_mining_worker_list(self, **params):
"""
Placeholder function for GET /sapi/v1/mining/worker/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/mining/rest-api/Request-for-Miner-List
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "mining/worker/list", signed=True, data=params, version=1)
```
Placeholder function for GET /sapi/v1/dci/product/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/dual\_investment/market-data](https://developers.binance.com/docs/dual_investment/market-data)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def margin_v1_get_dci_product_list(self, **params):
"""
Placeholder function for GET /sapi/v1/dci/product/list.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/dual_investment/market-data
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_margin_api("get", "dci/product/list", signed=True, data=params, version=1)
```
Placeholder function for GET /fapi/v1/convert/orderStatus.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Order-Status](https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Order-Status)
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
```python
def futures_v1_get_convert_order_status(self, **params):
"""
Placeholder function for GET /fapi/v1/convert/orderStatus.
Note: This function was auto-generated. Any issue please open an issue on GitHub.
https://developers.binance.com/docs/derivatives/usds-margined-futures/convert/Order-Status
:param params: parameters required by the endpoint
:type params: dict
:returns: API response
"""
return self._request_futures_api("get", "convert/orderStatus", signed=True, data=params, version=1)
```
# client (/docs/api/client)
# ContractType (/docs/api/enums/ContractType)
Attributes [#attributes]
# FuturesType (/docs/api/enums/FuturesType)
Attributes [#attributes]
# HistoricalKlinesType (/docs/api/enums/HistoricalKlinesType)
Attributes [#attributes]
# enums (/docs/api/enums)
# BinanceAPIException (/docs/api/exceptions/BinanceAPIException)
Attributes [#attributes]
Functions [#functions]
```python
def __init__(self, response, status_code, text):
self.code = 0
try:
json_res = json.loads(text)
except ValueError:
self.message = "Invalid JSON error message from Binance: {}".format(
response.text
)
else:
self.code = json_res.get("code")
self.message = json_res.get("msg")
self.status_code = status_code
self.response = response
self.request = getattr(response, "request", None)
```
```python
def __str__(self): # pragma: no cover
return "APIError(code=%s): %s" % (self.code, self.message)
```
# BinanceOrderException (/docs/api/exceptions/BinanceOrderException)
Attributes [#attributes]
Functions [#functions]
```python
def __init__(self, code, message):
self.code = code
self.message = message
```
```python
def __str__(self):
return "BinanceOrderException(code=%s): %s" % (self.code, self.message)
```
# BinanceOrderInactiveSymbolException (/docs/api/exceptions/BinanceOrderInactiveSymbolException)
Functions [#functions]
```python
def __init__(self, value):
message = "Attempting to trade an inactive symbol %s" % value
super().__init__(-1013, message)
```
# BinanceOrderMinAmountException (/docs/api/exceptions/BinanceOrderMinAmountException)
Functions [#functions]
```python
def __init__(self, value):
message = "Amount must be a multiple of %s" % value
super().__init__(-1013, message)
```
# BinanceOrderMinPriceException (/docs/api/exceptions/BinanceOrderMinPriceException)
Functions [#functions]
```python
def __init__(self, value):
message = "Price must be at least %s" % value
super().__init__(-1013, message)
```
# BinanceOrderMinTotalException (/docs/api/exceptions/BinanceOrderMinTotalException)
Functions [#functions]
```python
def __init__(self, value):
message = "Total must be at least %s" % value
super().__init__(-1013, message)
```
# BinanceOrderUnknownSymbolException (/docs/api/exceptions/BinanceOrderUnknownSymbolException)
Functions [#functions]
```python
def __init__(self, value):
message = "Unknown symbol %s" % value
super().__init__(-1013, message)
```
# BinanceRegionException (/docs/api/exceptions/BinanceRegionException)
Raised when using a region-specific endpoint with incompatible client.
Attributes [#attributes]
Functions [#functions]
```python
def __init__(
self, required_tld: str, actual_tld: str, endpoint_name: str = "endpoint"
):
self.required_tld = required_tld
self.actual_tld = actual_tld
self.endpoint_name = endpoint_name
self.message = (
f"{endpoint_name} is only available on binance.{required_tld}, "
f"but client is configured for binance.{actual_tld}"
)
super().__init__(self.message)
```
```python
def __str__(self):
return f"BinanceRegionException: {self.message}"
```
# BinanceRequestException (/docs/api/exceptions/BinanceRequestException)
Attributes [#attributes]
Functions [#functions]
```python
def __init__(self, message):
self.message = message
```
```python
def __str__(self):
return "BinanceRequestException: %s" % self.message
```
# BinanceWebsocketClosed (/docs/api/exceptions/BinanceWebsocketClosed)
Raised when websocket connection is closed.
# BinanceWebsocketQueueOverflow (/docs/api/exceptions/BinanceWebsocketQueueOverflow)
Raised when the websocket message queue exceeds its maximum size.
# BinanceWebsocketUnableToConnect (/docs/api/exceptions/BinanceWebsocketUnableToConnect)
# NotImplementedException (/docs/api/exceptions/NotImplementedException)
Functions [#functions]
```python
def __init__(self, value):
message = f"Not implemented: {value}"
super().__init__(message)
```
# ReadLoopClosed (/docs/api/exceptions/ReadLoopClosed)
Raised when trying to read from read loop but already closed
# UnknownDateFormat (/docs/api/exceptions/UnknownDateFormat)
# exceptions (/docs/api/exceptions)
# helpers (/docs/api/helpers)
Convert UTC date to milliseconds
If using offset strings add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"
See dateparse docs for formats [http://dateparser.readthedocs.io/en/latest/](http://dateparser.readthedocs.io/en/latest/)
:param date\_str: date in readable format, i.e. "January 01, 2018", "11 hours ago UTC", "now UTC"
```python
def date_to_milliseconds(date_str: str) -> int:
"""Convert UTC date to milliseconds
If using offset strings add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"
See dateparse docs for formats http://dateparser.readthedocs.io/en/latest/
:param date_str: date in readable format, i.e. "January 01, 2018", "11 hours ago UTC", "now UTC"
"""
# get epoch value in UTC
epoch: datetime = datetime.fromtimestamp(0,timezone.utc)
# parse our date string
d: Optional[datetime] = dateparser.parse(date_str, settings={"TIMEZONE": "UTC"})
if not d:
raise UnknownDateFormat(date_str)
# if the date is not timezone aware apply UTC timezone
if d.tzinfo is None or d.tzinfo.utcoffset(d) is None:
d = d.replace(tzinfo=pytz.utc)
# return the difference in time
return int((d - epoch).total_seconds() * 1000.0)
```
Convert a Binance interval string to milliseconds
:param interval: Binance interval string, e.g.: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w
:return:
int value of interval in milliseconds
None if interval prefix is not a decimal integer
None if interval suffix is not one of m, h, d, w
```python
def interval_to_milliseconds(interval: str) -> Optional[int]:
"""Convert a Binance interval string to milliseconds
:param interval: Binance interval string, e.g.: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w
:return:
int value of interval in milliseconds
None if interval prefix is not a decimal integer
None if interval suffix is not one of m, h, d, w
"""
seconds_per_unit: Dict[str, int] = {
"s": 1,
"m": 60,
"h": 60 * 60,
"d": 24 * 60 * 60,
"w": 7 * 24 * 60 * 60,
}
try:
return int(interval[:-1]) * seconds_per_unit[interval[-1]] * 1000
except (ValueError, KeyError):
return None
```
Rounds a given quantity to a specific step size
:param quantity: required
:param step\_size: required
:return: decimal
```python
def round_step_size(
quantity: Union[float, Decimal], step_size: Union[float, Decimal]
) -> float:
"""Rounds a given quantity to a specific step size
:param quantity: required
:param step_size: required
:return: decimal
"""
quantity = Decimal(str(quantity))
return float(quantity - quantity % Decimal(str(step_size)))
```
```python
def convert_ts_str(ts_str):
if ts_str is None:
return ts_str
if isinstance(ts_str, int):
return ts_str
return date_to_milliseconds(ts_str)
```
```python
def convert_list_to_json_array(l):
if l is None:
return l
res = json.dumps(l)
return res.replace(" ", "")
```
check if there is an event loop in the current thread, if not create one
inspired by [https://stackoverflow.com/questions/46727787/runtimeerror-there-is-no-current-event-loop-in-thread-in-async-apscheduler](https://stackoverflow.com/questions/46727787/runtimeerror-there-is-no-current-event-loop-in-thread-in-async-apscheduler)
```python
def get_loop():
"""check if there is an event loop in the current thread, if not create one
inspired by https://stackoverflow.com/questions/46727787/runtimeerror-there-is-no-current-event-loop-in-thread-in-async-apscheduler
"""
try:
loop = asyncio.get_event_loop()
return loop
except RuntimeError as e:
if str(e).startswith("There is no current event loop in thread"):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop
else:
raise
```
# ws (/docs/api/ws)
# WSListenerState (/docs/api/ws/constants/WSListenerState)
Attributes [#attributes]
# constants (/docs/api/ws/constants)
# BaseDepthCacheManager (/docs/api/ws/depthcache/BaseDepthCacheManager)
Attributes [#attributes]
Functions [#functions]
Create a DepthCacheManager instance
:param client: Binance API client
:type client: binance.Client
:param loop:
:type loop:
:param symbol: Symbol to create depth cache for
:type symbol: string
:param refresh\_interval: Optional number of seconds between cache refresh, use 0 or None to disable
:type refresh\_interval: int
:param bm: Optional BinanceSocketManager
:type bm: BinanceSocketManager
:param limit: Optional number of orders to get from orderbook
:type limit: int
:param conv\_type: Optional type to represent price, and amount, default is float.
:type conv\_type: function.
```python
def __init__(
self,
client,
symbol,
loop=None,
refresh_interval: Optional[int] = DEFAULT_REFRESH,
bm=None,
limit=10,
conv_type=float,
):
"""Create a DepthCacheManager instance
:param client: Binance API client
:type client: binance.Client
:param loop:
:type loop:
:param symbol: Symbol to create depth cache for
:type symbol: string
:param refresh_interval: Optional number of seconds between cache refresh, use 0 or None to disable
:type refresh_interval: int
:param bm: Optional BinanceSocketManager
:type bm: BinanceSocketManager
:param limit: Optional number of orders to get from orderbook
:type limit: int
:param conv_type: Optional type to represent price, and amount, default is float.
:type conv_type: function.
"""
self._client = client
self._depth_cache = None
self._loop = loop or get_loop()
self._symbol = symbol
self._limit = limit
self._last_update_id = None
self._bm = bm or BinanceSocketManager(self._client)
self._refresh_interval = refresh_interval
self._conn_key = None
self._conv_type = conv_type
self._log = logging.getLogger(__name__)
```
```python
async def __aenter__(self):
await asyncio.gather(self._init_cache(), self._start_socket())
await self._socket.__aenter__()
return self
```
```python
async def __aexit__(self, *args, **kwargs):
self._log.debug(f"Exiting depth cache manager for {self._symbol}")
await self._socket.__aexit__(*args, **kwargs)
```
```python
async def recv(self):
dc = None
while not dc:
try:
res = await asyncio.wait_for(self._socket.recv(), timeout=self.TIMEOUT)
self._log.debug(f"Received message: {res}")
except Exception as e:
self._log.warning(f"Exception recieving message: {e.__class__.__name__} (e) ")
else:
dc = await self._depth_event(res)
return dc
```
Initialise the depth cache calling REST endpoint
:return:
```python
async def _init_cache(self):
"""Initialise the depth cache calling REST endpoint
:return:
"""
self._log.debug(f"Initialising depth cache for {self._symbol}")
# initialise or clear depth cache
self._depth_cache = DepthCache(self._symbol, conv_type=self._conv_type)
# set a time to refresh the depth cache
if self._refresh_interval:
self._refresh_time = int(time.time()) + self._refresh_interval
```
Start the depth cache socket
:return:
```python
async def _start_socket(self):
"""Start the depth cache socket
:return:
"""
self._socket = self._get_socket()
```
```python
def _get_socket(self):
raise NotImplementedError
```
Handle a depth event
:param msg:
:return:
```python
async def _depth_event(self, msg):
"""Handle a depth event
:param msg:
:return:
"""
self._log.debug(f"Received depth event: {msg}")
if not msg:
return None
if "e" in msg and msg["e"] == "error":
# notify user by return msg with error
self._log.error(f"Error in depth event restarting cache: {msg}")
return msg
return await self._process_depth_message(msg)
```
Process a depth event message.
:param msg: Depth event message.
:return:
```python
async def _process_depth_message(self, msg):
"""Process a depth event message.
:param msg: Depth event message.
:return:
"""
# add any bid or ask values
self._apply_orders(msg)
# call the callback with the updated depth cache
res = self._depth_cache
# after processing event see if we need to refresh the depth cache
if self._refresh_interval and int(time.time()) > self._refresh_time:
await self._init_cache()
return res
```
```python
def _apply_orders(self, msg):
assert self._depth_cache
for bid in msg.get("b", []) + msg.get("bids", []):
self._depth_cache.add_bid(bid)
for ask in msg.get("a", []) + msg.get("asks", []):
self._depth_cache.add_ask(ask)
# keeping update time
self._depth_cache.update_time = msg.get("E") or msg.get("lastUpdateId")
```
Get the current depth cache
:return: DepthCache object
```python
def get_depth_cache(self):
"""Get the current depth cache
:return: DepthCache object
"""
return self._depth_cache
```
Close the open socket for this manager
:return:
```python
async def close(self):
"""Close the open socket for this manager
:return:
"""
self._depth_cache = None
```
Get the symbol
:return: symbol
```python
def get_symbol(self):
"""Get the symbol
:return: symbol
"""
return self._symbol
```
# DepthCache (/docs/api/ws/depthcache/DepthCache)
Attributes [#attributes]
Functions [#functions]
Initialise the DepthCache
:param symbol: Symbol to create depth cache for
:type symbol: string
:param conv\_type: Optional type to represent price, and amount, default is float.
:type conv\_type: function.
```python
def __init__(self, symbol, conv_type: Callable = float):
"""Initialise the DepthCache
:param symbol: Symbol to create depth cache for
:type symbol: string
:param conv_type: Optional type to represent price, and amount, default is float.
:type conv_type: function.
"""
self.symbol = symbol
self._bids = {}
self._asks = {}
self.update_time = None
self.conv_type: Callable = conv_type
self._log = logging.getLogger(__name__)
```
Add a bid to the cache
:param bid:
:return:
```python
def add_bid(self, bid):
"""Add a bid to the cache
:param bid:
:return:
"""
self._bids[bid[0]] = self.conv_type(bid[1])
if bid[1] == "0.00000000":
del self._bids[bid[0]]
```
Add an ask to the cache
:param ask:
:return:
```python
def add_ask(self, ask):
"""Add an ask to the cache
:param ask:
:return:
"""
self._asks[ask[0]] = self.conv_type(ask[1])
if ask[1] == "0.00000000":
del self._asks[ask[0]]
```
Get the current bids
:return: list of bids with price and quantity as conv\_type
.. code-block:: python
\[
\[
0.0001946, # Price
45.0 # Quantity
],
\[
0.00019459,
2384.0
],
\[
0.00019158,
5219.0
],
\[
0.00019157,
1180.0
],
\[
0.00019082,
287.0
]
]
```python
def get_bids(self):
"""Get the current bids
:return: list of bids with price and quantity as conv_type
.. code-block:: python
[
[
0.0001946, # Price
45.0 # Quantity
],
[
0.00019459,
2384.0
],
[
0.00019158,
5219.0
],
[
0.00019157,
1180.0
],
[
0.00019082,
287.0
]
]
"""
return DepthCache.sort_depth(self._bids, reverse=True, conv_type=self.conv_type)
```
Get the current asks
:return: list of asks with price and quantity as conv\_type.
.. code-block:: python
\[
\[
0.0001955, # Price
57.0' # Quantity
],
\[
0.00019699,
778.0
],
\[
0.000197,
64.0
],
\[
0.00019709,
1130.0
],
\[
0.0001971,
385.0
]
]
```python
def get_asks(self):
"""Get the current asks
:return: list of asks with price and quantity as conv_type.
.. code-block:: python
[
[
0.0001955, # Price
57.0' # Quantity
],
[
0.00019699,
778.0
],
[
0.000197,
64.0
],
[
0.00019709,
1130.0
],
[
0.0001971,
385.0
]
]
"""
return DepthCache.sort_depth(
self._asks, reverse=False, conv_type=self.conv_type
)
```
Sort bids or asks by price
```python
@staticmethod
def sort_depth(vals, reverse=False, conv_type: Callable = float):
"""Sort bids or asks by price"""
if isinstance(vals, dict):
lst = [
[conv_type(price), conv_type(quantity)]
for price, quantity in vals.items()
]
elif isinstance(vals, list):
lst = [[conv_type(price), conv_type(quantity)] for price, quantity in vals]
else:
raise ValueError(f"Unknown order book depth data type: {type(vals)}")
lst = sorted(lst, key=itemgetter(0), reverse=reverse)
return lst
```
# DepthCacheManager (/docs/api/ws/depthcache/DepthCacheManager)
Functions [#functions]
Initialise the DepthCacheManager
:param client: Binance API client
:type client: binance.Client
:param loop: asyncio loop
:param symbol: Symbol to create depth cache for
:type symbol: string
:param refresh\_interval: Optional number of seconds between cache refresh, use 0 or None to disable
:type refresh\_interval: int
:param limit: Optional number of orders to get from orderbook
:type limit: int
:param conv\_type: Optional type to represent price, and amount, default is float.
:type conv\_type: function.
:param ws\_interval: Optional interval for updates on websocket, default None. If not set, updates happen every second. Must be 0, None (1s) or 100 (100ms).
:type ws\_interval: int
```python
def __init__(
self,
client,
symbol,
loop=None,
refresh_interval: Optional[int] = None,
bm=None,
limit=500,
conv_type=float,
ws_interval=None,
):
"""Initialise the DepthCacheManager
:param client: Binance API client
:type client: binance.Client
:param loop: asyncio loop
:param symbol: Symbol to create depth cache for
:type symbol: string
:param refresh_interval: Optional number of seconds between cache refresh, use 0 or None to disable
:type refresh_interval: int
:param limit: Optional number of orders to get from orderbook
:type limit: int
:param conv_type: Optional type to represent price, and amount, default is float.
:type conv_type: function.
:param ws_interval: Optional interval for updates on websocket, default None. If not set, updates happen every second. Must be 0, None (1s) or 100 (100ms).
:type ws_interval: int
"""
super().__init__(client, symbol, loop, refresh_interval, bm, limit, conv_type)
self._ws_interval = ws_interval
```
Initialise the depth cache calling REST endpoint
:return:
```python
async def _init_cache(self):
"""Initialise the depth cache calling REST endpoint
:return:
"""
self._last_update_id = None
self._depth_message_buffer = []
res = await self._client.get_order_book(symbol=self._symbol, limit=self._limit)
# initialise or clear depth cache
await super()._init_cache()
# process bid and asks from the order book
self._apply_orders(res)
assert self._depth_cache
for bid in res["bids"]:
self._depth_cache.add_bid(bid)
for ask in res["asks"]:
self._depth_cache.add_ask(ask)
# set first update id
self._last_update_id = res["lastUpdateId"]
# Apply any updates from the websocket
for msg in self._depth_message_buffer:
await self._process_depth_message(msg)
# clear the depth buffer
self._depth_message_buffer = []
```
Start the depth cache socket
:return:
```python
async def _start_socket(self):
"""Start the depth cache socket
:return:
"""
if not getattr(self, "_depth_message_buffer", None):
self._depth_message_buffer = []
await super()._start_socket()
```
```python
def _get_socket(self):
return self._bm.depth_socket(self._symbol, interval=self._ws_interval)
```
Process a depth event message.
:param msg: Depth event message.
:return:
```python
async def _process_depth_message(self, msg):
"""Process a depth event message.
:param msg: Depth event message.
:return:
"""
if self._last_update_id is None:
# Initial depth snapshot fetch not yet performed, buffer messages
self._depth_message_buffer.append(msg)
return
if msg["u"] <= self._last_update_id:
# ignore any updates before the initial update id
return
elif msg["U"] != self._last_update_id + 1:
# if not buffered check we get sequential updates
# otherwise init cache again
await self._init_cache()
# add any bid or ask values
self._apply_orders(msg)
# call the callback with the updated depth cache
res = self._depth_cache
self._last_update_id = msg["u"]
# after processing event see if we need to refresh the depth cache
if self._refresh_interval and int(time.time()) > self._refresh_time:
await self._init_cache()
return res
```
# FuturesDepthCacheManager (/docs/api/ws/depthcache/FuturesDepthCacheManager)
Functions [#functions]
Process a depth event message.
:param msg: Depth event message.
:return:
```python
async def _process_depth_message(self, msg):
"""Process a depth event message.
:param msg: Depth event message.
:return:
"""
msg = msg.get("data")
return await super()._process_depth_message(msg)
```
```python
def _apply_orders(self, msg):
assert self._depth_cache
self._depth_cache._bids = msg.get("b", [])
self._depth_cache._asks = msg.get("a", [])
# keeping update time
self._depth_cache.update_time = msg.get("E") or msg.get("lastUpdateId")
```
```python
def _get_socket(self):
sock = self._bm.futures_depth_socket(self._symbol)
return sock
```
# OptionsDepthCacheManager (/docs/api/ws/depthcache/OptionsDepthCacheManager)
Functions [#functions]
```python
def _get_socket(self):
return self._bm.options_depth_socket(self._symbol)
```
# ThreadedDepthCacheManager (/docs/api/ws/depthcache/ThreadedDepthCacheManager)
Functions [#functions]
```python
def __init__(
self,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
requests_params: Optional[Dict[str, str]] = None,
tld: str = "com",
testnet: bool = False,
):
super().__init__(api_key, api_secret, requests_params, tld, testnet)
```
```python
def _start_depth_cache(
self,
dcm_class,
callback: Callable,
symbol: str,
refresh_interval=None,
bm=None,
limit=10,
conv_type=float,
**kwargs,
) -> str:
while not self._client:
time.sleep(0.01)
dcm = dcm_class(
client=self._client,
symbol=symbol,
loop=self._loop,
refresh_interval=refresh_interval,
bm=bm,
limit=limit,
conv_type=conv_type,
**kwargs,
)
path = symbol.lower() + "@depth" + str(limit)
self._socket_running[path] = True
self._loop.call_soon(
asyncio.create_task, self.start_listener(dcm, path, callback)
)
return path
```
```python
def start_depth_cache(
self,
callback: Callable,
symbol: str,
refresh_interval=None,
bm=None,
limit=10,
conv_type=float,
ws_interval=0,
) -> str:
return self._start_depth_cache(
dcm_class=DepthCacheManager,
callback=callback,
symbol=symbol,
refresh_interval=refresh_interval,
bm=bm,
limit=limit,
conv_type=conv_type,
ws_interval=ws_interval,
)
```
```python
def start_futures_depth_socket(
self,
callback: Callable,
symbol: str,
refresh_interval=None,
bm=None,
limit=10,
conv_type=float,
) -> str:
return self._start_depth_cache(
dcm_class=FuturesDepthCacheManager,
callback=callback,
symbol=symbol,
refresh_interval=refresh_interval,
bm=bm,
limit=limit,
conv_type=conv_type,
)
```
```python
def start_options_depth_socket(
self,
callback: Callable,
symbol: str,
refresh_interval=None,
bm=None,
limit=10,
conv_type=float,
) -> str:
return self._start_depth_cache(
dcm_class=OptionsDepthCacheManager,
callback=callback,
symbol=symbol,
refresh_interval=refresh_interval,
bm=bm,
limit=limit,
conv_type=conv_type,
)
```
# depthcache (/docs/api/ws/depthcache)
# KeepAliveWebsocket (/docs/api/ws/keepalive_websocket/KeepAliveWebsocket)
Functions [#functions]
```python
def __init__(
self,
client: AsyncClient,
url,
keepalive_type,
prefix="ws/",
is_binary=False,
exit_coro=None,
user_timeout=None,
**kwargs,
):
super().__init__(
path=None,
url=url,
prefix=prefix,
is_binary=is_binary,
exit_coro=exit_coro,
**kwargs,
)
self._keepalive_type = keepalive_type
self._client = client
self._user_timeout = user_timeout or KEEPALIVE_TIMEOUT
self._timer = None
self._subscription_id = None
self._listen_key = None # Used for non spot stream types
self._uses_ws_api_subscription = False # True when using ws_api
self._listen_token_expiration = (
None # Expiration time for listenToken-based subscriptions
)
```
```python
async def __aexit__(self, *args, **kwargs):
if self._timer:
self._timer.cancel()
self._timer = None
# Clean up subscription if it exists
if self._subscription_id is not None:
# Unregister the queue from ws_api before unsubscribing
if hasattr(self._client, "ws_api") and self._client.ws_api:
self._client.ws_api.unregister_subscription_queue(self._subscription_id)
await self._unsubscribe_from_user_data_stream()
if self._uses_ws_api_subscription:
# For ws_api subscriptions, we don't manage the connection
return
if not self._path:
return
await super().__aexit__(*args, **kwargs)
```
```python
def _build_path(self):
self._path = self._listen_key
time_unit = getattr(self._client, "TIME_UNIT", None)
if time_unit:
self._path = f"{self._listen_key}?timeUnit={time_unit}"
```
```python
async def _before_connect(self):
if self._keepalive_type == "user":
# Subscribe via ws_api and register our own queue for events
self._subscription_id = await self._subscribe_to_user_data_stream()
if self._subscription_id is None:
raise ValueError(
"Failed to subscribe to user data stream: no subscription ID returned"
)
self._uses_ws_api_subscription = True
# Register our queue with ws_api so events get routed to us
self._client.ws_api.register_subscription_queue(
self._subscription_id, self._queue
)
self._path = f"user_subscription:{self._subscription_id}"
return
if self._keepalive_type == "margin":
# Subscribe to cross-margin via ws_api
self._subscription_id = await self._subscribe_to_margin_data_stream()
if self._subscription_id is None:
raise ValueError(
"Failed to subscribe to margin data stream: no subscription ID returned"
)
self._uses_ws_api_subscription = True
# Register our queue with ws_api so events get routed to us
self._client.ws_api.register_subscription_queue(
self._subscription_id, self._queue
)
self._path = f"margin_subscription:{self._subscription_id}"
return
# Check if this is isolated margin (when keepalive_type is a symbol string)
if self._keepalive_type not in [
"user",
"margin",
"futures",
"coin_futures",
"portfolio_margin",
]:
# This is isolated margin with symbol as keepalive_type
self._subscription_id = (
await self._subscribe_to_isolated_margin_data_stream(
self._keepalive_type
)
)
if self._subscription_id is None:
raise ValueError(
f"Failed to subscribe to isolated margin data stream for {self._keepalive_type}: no subscription ID returned"
)
self._uses_ws_api_subscription = True
# Register our queue with ws_api so events get routed to us
self._client.ws_api.register_subscription_queue(
self._subscription_id, self._queue
)
self._path = f"isolated_margin_subscription:{self._subscription_id}"
return
if not self._listen_key:
self._listen_key = await self._get_listen_key()
self._build_path()
```
Override connect to handle ws\_api subscriptions differently.
```python
async def connect(self):
"""Override connect to handle ws_api subscriptions differently."""
# Check if this keepalive type uses ws_api subscription
if self._keepalive_type in ["user", "margin"] or self._keepalive_type not in [
"futures",
"coin_futures",
"portfolio_margin",
]:
# For sockets using ws_api subscription:
# - Subscribe via ws_api (done in _before_connect)
# - Don't create our own websocket connection
# - Don't start a read loop (ws_api handles reading)
await self._before_connect()
# Check if ws_api subscription was actually used
if self._uses_ws_api_subscription:
await self._after_connect()
return
# For other keepalive types, use normal connection logic
await super().connect()
```
Override recv to work without a read loop for ws\_api subscriptions.
```python
async def recv(self):
"""Override recv to work without a read loop for ws_api subscriptions."""
if self._uses_ws_api_subscription:
# For ws_api subscriptions, just read from queue
res = None
while not res:
try:
res = await asyncio.wait_for(
self._queue.get(), timeout=self.TIMEOUT
)
except asyncio.TimeoutError:
self._log.debug(f"no message in {self.TIMEOUT} seconds")
return res
return await super().recv()
```
```python
async def _after_connect(self):
if self._timer is None:
self._start_socket_timer()
```
```python
def _start_socket_timer(self):
self._timer = self._loop.call_later(
self._user_timeout, lambda: asyncio.create_task(self._keepalive_socket())
)
```
Subscribe to user data stream using WebSocket API
```python
async def _subscribe_to_user_data_stream(self):
"""Subscribe to user data stream using WebSocket API"""
params = {
"id": str(uuid.uuid4()),
}
response = await self._client._ws_api_request(
"userDataStream.subscribe.signature", signed=True, params=params
)
return response.get("subscriptionId")
```
Subscribe to cross-margin data stream using WebSocket API with listenToken
```python
async def _subscribe_to_margin_data_stream(self):
"""Subscribe to cross-margin data stream using WebSocket API with listenToken"""
# Create listenToken for cross-margin
token_response = await self._client.margin_create_listen_token(
is_isolated=False
)
listen_token = token_response["token"]
self._listen_token_expiration = token_response.get("expirationTime")
# Subscribe using listenToken
params = {
"id": str(uuid.uuid4()),
"listenToken": listen_token,
}
response = await self._client._ws_api_request(
"userDataStream.subscribe.listenToken", signed=False, params=params
)
return response.get("subscriptionId")
```
Subscribe to isolated margin data stream using WebSocket API with listenToken
```python
async def _subscribe_to_isolated_margin_data_stream(self, symbol: str):
"""Subscribe to isolated margin data stream using WebSocket API with listenToken"""
# Create listenToken for isolated margin
token_response = await self._client.margin_create_listen_token(
symbol=symbol, is_isolated=True
)
listen_token = token_response["token"]
self._listen_token_expiration = token_response.get("expirationTime")
# Subscribe using listenToken
params = {
"id": str(uuid.uuid4()),
"listenToken": listen_token,
}
response = await self._client._ws_api_request(
"userDataStream.subscribe.listenToken", signed=False, params=params
)
return response.get("subscriptionId")
```
Unsubscribe from user data stream using WebSocket API
```python
async def _unsubscribe_from_user_data_stream(self):
"""Unsubscribe from user data stream using WebSocket API"""
if self._subscription_id is not None:
params = {
"id": str(uuid.uuid4()),
"subscriptionId": self._subscription_id,
}
await self._client._ws_api_request(
"userDataStream.unsubscribe", signed=False, params=params
)
self._subscription_id = None
```
```python
async def _get_listen_key(self):
if self._keepalive_type == "user":
listen_key = await self._client.stream_get_listen_key()
elif self._keepalive_type == "margin": # cross-margin
listen_key = await self._client.margin_stream_get_listen_key()
elif self._keepalive_type == "futures":
listen_key = await self._client.futures_stream_get_listen_key()
elif self._keepalive_type == "coin_futures":
listen_key = await self._client.futures_coin_stream_get_listen_key()
elif self._keepalive_type == "portfolio_margin":
listen_key = await self._client.papi_stream_get_listen_key()
else: # isolated margin
# Passing symbol for isolated margin
listen_key = await self._client.isolated_margin_stream_get_listen_key(
self._keepalive_type
)
return listen_key
```
```python
async def _keepalive_socket(self):
try:
# Skip keepalive for ws_api subscriptions (user, margin, isolated margin)
if self._uses_ws_api_subscription:
return
listen_key = await self._get_listen_key()
if listen_key != self._listen_key:
self._log.debug("listen key changed: reconnect")
self._listen_key = listen_key
self._build_path()
self._reconnect()
else:
self._log.debug("listen key same: keepalive")
if self._keepalive_type == "margin": # cross-margin
await self._client.margin_stream_keepalive(self._listen_key)
elif self._keepalive_type == "futures":
await self._client.futures_stream_keepalive(self._listen_key)
elif self._keepalive_type == "coin_futures":
await self._client.futures_coin_stream_keepalive(self._listen_key)
elif self._keepalive_type == "portfolio_margin":
await self._client.papi_stream_keepalive(self._listen_key)
else: # isolated margin
# Passing symbol for isolated margin
await self._client.isolated_margin_stream_keepalive(
self._keepalive_type, self._listen_key
)
except Exception as e:
self._log.error(f"error in keepalive_socket: {e}")
finally:
if self._timer is not None:
self._start_socket_timer()
else:
self._log.info("skip timer restart - web socket is exiting")
```
# keepalive_websocket (/docs/api/ws/keepalive_websocket)
# ReconnectingWebsocket (/docs/api/ws/reconnecting_websocket/ReconnectingWebsocket)
Attributes [#attributes]
Functions [#functions]
```python
def __init__(
self,
url: str,
path: Optional[str] = None,
prefix: str = "ws/",
is_binary: bool = False,
exit_coro=None,
https_proxy: Optional[str] = None,
max_queue_size: int = 100,
**kwargs,
):
self._loop = get_loop()
self._log = logging.getLogger(__name__)
self._path = path
self._url = url
self._exit_coro = exit_coro
self._prefix = prefix
self._reconnects = 0
self._is_binary = is_binary
self._conn = None
self._socket = None
self.ws: Optional[ws.WebSocketClientProtocol] = None # type: ignore
self.ws_state = WSListenerState.INITIALISING
self._queue = asyncio.Queue()
self._handle_read_loop = None
self._https_proxy = https_proxy
self._ws_kwargs = kwargs
self.max_queue_size = max_queue_size
```
```python
def json_dumps(self, msg) -> str:
if orjson:
return orjson.dumps(msg).decode("utf-8")
return json.dumps(msg)
```
```python
def json_loads(self, msg):
if orjson:
return orjson.loads(msg)
return json.loads(msg)
```
```python
async def __aenter__(self):
await self.connect()
return self
```
```python
async def close(self):
await self.__aexit__(None, None, None)
```
```python
async def __aexit__(self, exc_type, exc_val, exc_tb):
self._log.debug(f"Closing Websocket {self._url}{self._prefix}{self._path}")
if self._handle_read_loop:
await self._kill_read_loop()
if self._exit_coro:
await self._exit_coro(self._path)
if self.ws:
await self.ws.close()
if self._conn and hasattr(self._conn, "protocol"):
await self._conn.__aexit__(exc_type, exc_val, exc_tb)
self.ws = None
```
```python
async def connect(self):
self._log.debug("Establishing new WebSocket connection")
self.ws_state = WSListenerState.RECONNECTING
await self._before_connect()
ws_url = (
f"{self._url}{getattr(self, '_prefix', '')}{getattr(self, '_path', '')}"
)
# handle https_proxy
if self._https_proxy:
if not Proxy or not proxy_connect:
raise ImportError(
"websockets_proxy is not installed, please install it to use a websockets proxy (pip install websockets_proxy)"
)
proxy = Proxy.from_url(self._https_proxy) # type: ignore
self._conn = proxy_connect(
ws_url, close_timeout=0.1, proxy=proxy, **self._ws_kwargs
) # type: ignore
else:
self._conn = ws.connect(ws_url, close_timeout=0.1, **self._ws_kwargs) # type: ignore
try:
self.ws = await self._conn.__aenter__()
except Exception as e: # noqa
self._log.error(f"Failed to connect to websocket: {e}")
self.ws_state = WSListenerState.RECONNECTING
raise e
self.ws_state = WSListenerState.STREAMING
self._reconnects = 0
await self._after_connect()
if not self._handle_read_loop:
self._handle_read_loop = self._loop.call_soon_threadsafe(
asyncio.create_task, self._read_loop()
)
```
```python
async def _kill_read_loop(self):
self.ws_state = WSListenerState.EXITING
while self._handle_read_loop:
await sleep(0.1)
self._log.debug("Finished killing read_loop")
```
```python
async def _before_connect(self):
pass
```
```python
async def _after_connect(self):
pass
```
```python
def _handle_message(self, evt):
if self._is_binary:
try:
evt = gzip.decompress(evt)
except (ValueError, OSError) as e:
self._log.error(f"Failed to decompress message: {(e)}")
raise
except Exception as e:
self._log.error(f"Unexpected decompression error: {(e)}")
raise
try:
return self.json_loads(evt)
except ValueError as e:
self._log.error(f"JSON Value Error parsing message: Error: {(e)}")
raise
except TypeError as e:
self._log.error(f"JSON Type Error parsing message. Error: {(e)}")
raise
except Exception as e:
self._log.error(f"Unexpected error parsing message. Error: {(e)}")
raise
```
```python
async def _read_loop(self):
try:
while True:
try:
while self.ws_state == WSListenerState.RECONNECTING:
await self._run_reconnect()
if self.ws_state == WSListenerState.EXITING:
self._log.debug(
f"_read_loop {self._path} break for {self.ws_state}"
)
break
elif self.ws.state == ws.protocol.State.CLOSING: # type: ignore
await asyncio.sleep(0.1)
continue
elif self.ws.state == ws.protocol.State.CLOSED: # type: ignore
self._reconnect()
raise BinanceWebsocketClosed(
"Connection closed. Reconnecting..."
)
elif self.ws_state == WSListenerState.STREAMING:
assert self.ws
res = await asyncio.wait_for(
self.ws.recv(), timeout=self.TIMEOUT
)
res = self._handle_message(res)
self._log.debug(f"Received message: {res}")
if res:
if self._queue.qsize() < self.max_queue_size:
await self._queue.put(res)
else:
raise BinanceWebsocketQueueOverflow(
f"Message queue size {self._queue.qsize()} exceeded maximum {self.max_queue_size}"
)
except asyncio.TimeoutError:
self._log.debug(f"no message in {self.TIMEOUT} seconds")
# _no_message_received_reconnect
except asyncio.CancelledError as e:
self._log.debug(f"_read_loop cancelled error {e}")
await self._queue.put({
"e": "error",
"type": f"{e.__class__.__name__}",
"m": f"{e}",
})
break
except (
asyncio.IncompleteReadError,
gaierror,
ConnectionClosedError,
ConnectionClosedOK,
BinanceWebsocketClosed,
) as e:
# reports errors and continue loop
self._log.error(f"{e.__class__.__name__} ({e})")
await self._queue.put({
"e": "error",
"type": f"{e.__class__.__name__}",
"m": f"{e}",
})
except (
BinanceWebsocketUnableToConnect,
BinanceWebsocketQueueOverflow,
Exception,
) as e:
# reports errors and break the loop
self._log.error(f"Unknown exception: {e.__class__.__name__} ({e})")
await self._queue.put({
"e": "error",
"type": e.__class__.__name__,
"m": f"{e}",
})
break
except Exception as e:
self._log.error(f"Unknown exception: {e.__class__.__name__} ({e})")
finally:
self._handle_read_loop = None # Signal the coro is stopped
self._reconnects = 0
```
```python
async def _run_reconnect(self):
await self.before_reconnect()
if self._reconnects < self.MAX_RECONNECTS:
reconnect_wait = self._get_reconnect_wait(self._reconnects)
self._log.debug(
f"websocket reconnecting. {self.MAX_RECONNECTS - self._reconnects} reconnects left - "
f"waiting {reconnect_wait}"
)
await asyncio.sleep(reconnect_wait)
try:
await self.connect()
except Exception as e:
pass
else:
self._log.error(f"Max reconnections {self.MAX_RECONNECTS} reached:")
# Signal the error
raise BinanceWebsocketUnableToConnect
```
```python
async def recv(self):
res = None
while not res:
if not self._handle_read_loop:
raise ReadLoopClosed(
"Read loop has been closed, please reset the websocket connection and listen to the message error."
)
try:
res = await asyncio.wait_for(self._queue.get(), timeout=self.TIMEOUT)
except asyncio.TimeoutError:
self._log.debug(f"no message in {self.TIMEOUT} seconds")
return res
```
```python
async def _wait_for_reconnect(self):
while (
self.ws_state != WSListenerState.STREAMING
and self.ws_state != WSListenerState.EXITING
):
await sleep(0.1)
```
```python
def _get_reconnect_wait(self, attempts: int) -> int:
expo = 2**attempts
return round(random() * min(self.MAX_RECONNECT_SECONDS, expo - 1) + 1)
```
```python
async def before_reconnect(self):
if self.ws:
self.ws = None
if self._conn and hasattr(self._conn, "protocol"):
await self._conn.__aexit__(None, None, None)
self._reconnects += 1
```
```python
def _reconnect(self):
self.ws_state = WSListenerState.RECONNECTING
```
# reconnecting_websocket (/docs/api/ws/reconnecting_websocket)
# BinanceSocketManager (/docs/api/ws/streams/BinanceSocketManager)
Attributes [#attributes]
Functions [#functions]
Initialise the BinanceSocketManager
:param client: Binance API client
:type client: binance.AsyncClient
:param user\_timeout: Timeout for user socket in seconds
:param max\_queue\_size: Max size of the websocket queue, defaults to 100
:type max\_queue\_size: int
:param verbose: Enable verbose logging for WebSocket connections
:type verbose: bool
```python
def __init__(
self,
client: AsyncClient,
user_timeout=KEEPALIVE_TIMEOUT,
max_queue_size: int = 100,
verbose: bool = False,
):
"""Initialise the BinanceSocketManager
:param client: Binance API client
:type client: binance.AsyncClient
:param user_timeout: Timeout for user socket in seconds
:param max_queue_size: Max size of the websocket queue, defaults to 100
:type max_queue_size: int
:param verbose: Enable verbose logging for WebSocket connections
:type verbose: bool
"""
self.STREAM_URL = self.STREAM_URL.format(client.tld)
self.FSTREAM_URL = self.FSTREAM_URL.format(client.tld)
self.DSTREAM_URL = self.DSTREAM_URL.format(client.tld)
self.OPTIONS_URL = self.OPTIONS_URL.format(client.tld)
self._conns = {}
self._loop = get_loop()
self._client = client
self._user_timeout = user_timeout
self.testnet = self._client.testnet
self.demo = self._client.demo
self._max_queue_size = max_queue_size
self.verbose = verbose
self.ws_kwargs = {}
if verbose:
logging.getLogger('binance.ws').setLevel(logging.DEBUG)
```
```python
def _get_stream_url(self, stream_url: Optional[str] = None):
if stream_url:
return stream_url
stream_url = self.STREAM_URL
if self.testnet:
stream_url = self.STREAM_TESTNET_URL
elif self.demo:
stream_url = self.STREAM_DEMO_URL
return stream_url
```
```python
def _get_socket(
self,
path: str,
stream_url: Optional[str] = None,
prefix: str = "ws/",
is_binary: bool = False,
socket_type: BinanceSocketType = BinanceSocketType.SPOT,
) -> ReconnectingWebsocket:
conn_id = f"{socket_type}_{path}"
time_unit = getattr(self._client, "TIME_UNIT", None)
if time_unit:
path = f"{path}?timeUnit={time_unit}"
if conn_id not in self._conns:
self._conns[conn_id] = ReconnectingWebsocket(
path=path,
url=self._get_stream_url(stream_url),
prefix=prefix,
exit_coro=lambda p: self._exit_socket(f"{socket_type}_{p}"),
is_binary=is_binary,
https_proxy=self._client.https_proxy,
max_queue_size=self._max_queue_size,
**self.ws_kwargs,
)
return self._conns[conn_id]
```
```python
def _get_account_socket(
self,
path: str,
stream_url: Optional[str] = None,
prefix: str = "ws/",
is_binary: bool = False,
) -> KeepAliveWebsocket:
conn_id = f"{BinanceSocketType.ACCOUNT}_{path}"
if conn_id not in self._conns:
self._conns[conn_id] = KeepAliveWebsocket(
client=self._client,
url=self._get_stream_url(stream_url),
keepalive_type=path,
prefix=prefix,
exit_coro=lambda p: self._exit_socket(conn_id),
is_binary=is_binary,
user_timeout=self._user_timeout,
https_proxy=self._client.https_proxy,
max_queue_size=self._max_queue_size,
**self.ws_kwargs,
)
return self._conns[conn_id]
```
```python
def _get_futures_socket(
self, path: str, futures_type: FuturesType, prefix: str = "stream?streams="
):
socket_type: BinanceSocketType = BinanceSocketType.USD_M_FUTURES
if futures_type == FuturesType.USD_M:
stream_url = self.FSTREAM_URL
if self.testnet:
stream_url = self.FSTREAM_TESTNET_URL
elif self.demo:
stream_url = self.FSTREAM_DEMO_URL
else:
stream_url = self.DSTREAM_URL
if self.testnet:
stream_url = self.DSTREAM_TESTNET_URL
elif self.demo:
stream_url = self.DSTREAM_DEMO_URL
return self._get_socket(path, stream_url, prefix, socket_type=socket_type)
```
```python
def _get_options_socket(self, path: str, prefix: str = "ws/"):
stream_url = self.OPTIONS_URL
return self._get_socket(
path,
stream_url,
prefix,
is_binary=False,
socket_type=BinanceSocketType.OPTIONS,
)
```
```python
async def _exit_socket(self, path: str):
await self._stop_socket(path)
```
Start a websocket for symbol market depth returning either a diff or a partial book
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#partial-book-depth-streams](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#partial-book-depth-streams)
:param symbol: required
:type symbol: str
:param depth: optional Number of depth entries to return, default None. If passed returns a partial book instead of a diff
:type depth: str
:param interval: optional interval for updates, default None. If not set, updates happen every second. Must be 0, None (1s) or 100 (100ms)
:type interval: int
:returns: connection key string if successful, False otherwise
Partial Message Format
.. code-block:: python
\{
"lastUpdateId": 160, # Last update ID
"bids": \[ # Bids to be updated
\[
"0.0024", # price level to be updated
"10", # quantity
\[] # ignore
]
],
"asks": \[ # Asks to be updated
\[
"0.0026", # price level to be updated
"100", # quantity
\[] # ignore
]
]
}
Diff Message Format
.. code-block:: python
\{
"e": "depthUpdate", # Event type
"E": 123456789, # Event time
"s": "BNBBTC", # Symbol
"U": 157, # First update ID in event
"u": 160, # Final update ID in event
"b": \[ # Bids to be updated
\[
"0.0024", # price level to be updated
"10", # quantity
\[] # ignore
]
],
"a": \[ # Asks to be updated
\[
"0.0026", # price level to be updated
"100", # quantity
\[] # ignore
]
]
}
```python
def depth_socket(
self, symbol: str, depth: Optional[str] = None, interval: Optional[int] = None
):
"""Start a websocket for symbol market depth returning either a diff or a partial book
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#partial-book-depth-streams
:param symbol: required
:type symbol: str
:param depth: optional Number of depth entries to return, default None. If passed returns a partial book instead of a diff
:type depth: str
:param interval: optional interval for updates, default None. If not set, updates happen every second. Must be 0, None (1s) or 100 (100ms)
:type interval: int
:returns: connection key string if successful, False otherwise
Partial Message Format
.. code-block:: python
{
"lastUpdateId": 160, # Last update ID
"bids": [ # Bids to be updated
[
"0.0024", # price level to be updated
"10", # quantity
[] # ignore
]
],
"asks": [ # Asks to be updated
[
"0.0026", # price level to be updated
"100", # quantity
[] # ignore
]
]
}
Diff Message Format
.. code-block:: python
{
"e": "depthUpdate", # Event type
"E": 123456789, # Event time
"s": "BNBBTC", # Symbol
"U": 157, # First update ID in event
"u": 160, # Final update ID in event
"b": [ # Bids to be updated
[
"0.0024", # price level to be updated
"10", # quantity
[] # ignore
]
],
"a": [ # Asks to be updated
[
"0.0026", # price level to be updated
"100", # quantity
[] # ignore
]
]
}
"""
socket_name = symbol.lower() + "@depth"
if depth and depth != "1":
socket_name = f"{socket_name}{depth}"
if interval:
if interval in [0, 100]:
socket_name = f"{socket_name}@{interval}ms"
else:
raise ValueError(
"Websocket interval value not allowed. Allowed values are [0, 100]"
)
return self._get_socket(socket_name)
```
Start a websocket for symbol kline data
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#klinecandlestick-streams](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#klinecandlestick-streams)
:param symbol: required
:type symbol: str
:param interval: Kline interval, default KLINE\_INTERVAL\_1MINUTE
:type interval: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"e": "kline", # event type
"E": 1499404907056, # event time
"s": "ETHBTC", # symbol
"k": \{
"t": 1499404860000, # start time of this bar
"T": 1499404919999, # end time of this bar
"s": "ETHBTC", # symbol
"i": "1m", # interval
"f": 77462, # first trade id
"L": 77465, # last trade id
"o": "0.10278577", # open
"c": "0.10278645", # close
"h": "0.10278712", # high
"l": "0.10278518", # low
"v": "17.47929838", # volume
"n": 4, # number of trades
"x": false, # whether this bar is final
"q": "1.79662878", # quote volume
"V": "2.34879839", # volume of active buy
"Q": "0.24142166", # quote volume of active buy
"B": "13279784.01349473" # can be ignored
}
}
```python
def kline_socket(self, symbol: str, interval=AsyncClient.KLINE_INTERVAL_1MINUTE):
"""Start a websocket for symbol kline data
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#klinecandlestick-streams
:param symbol: required
:type symbol: str
:param interval: Kline interval, default KLINE_INTERVAL_1MINUTE
:type interval: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"e": "kline", # event type
"E": 1499404907056, # event time
"s": "ETHBTC", # symbol
"k": {
"t": 1499404860000, # start time of this bar
"T": 1499404919999, # end time of this bar
"s": "ETHBTC", # symbol
"i": "1m", # interval
"f": 77462, # first trade id
"L": 77465, # last trade id
"o": "0.10278577", # open
"c": "0.10278645", # close
"h": "0.10278712", # high
"l": "0.10278518", # low
"v": "17.47929838", # volume
"n": 4, # number of trades
"x": false, # whether this bar is final
"q": "1.79662878", # quote volume
"V": "2.34879839", # volume of active buy
"Q": "0.24142166", # quote volume of active buy
"B": "13279784.01349473" # can be ignored
}
}
"""
path = f"{symbol.lower()}@kline_{interval}"
return self._get_socket(path)
```
Start a websocket for symbol kline data for the perpeual futures stream
[https://binance-docs.github.io/apidocs/futures/en/#continuous-contract-kline-candlestick-streams](https://binance-docs.github.io/apidocs/futures/en/#continuous-contract-kline-candlestick-streams)
:param symbol: required
:type symbol: str
:param interval: Kline interval, default KLINE\_INTERVAL\_1MINUTE
:type interval: str
:param futures\_type: use USD-M or COIN-M futures default USD-M
:param contract\_type: use PERPETUAL or CURRENT\_QUARTER or NEXT\_QUARTER default PERPETUAL
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"e":"continuous\_kline", // Event type
"E":1607443058651, // Event time
"ps":"BTCUSDT", // Pair
"ct":"PERPETUAL" // Contract type
"k":\{
"t":1607443020000, // Kline start time
"T":1607443079999, // Kline close time
"i":"1m", // Interval
"f":116467658886, // First trade ID
"L":116468012423, // Last trade ID
"o":"18787.00", // Open price
"c":"18804.04", // Close price
"h":"18804.04", // High price
"l":"18786.54", // Low price
"v":"197.664", // volume
"n": 543, // Number of trades
"x":false, // Is this kline closed?
"q":"3715253.19494", // Quote asset volume
"V":"184.769", // Taker buy volume
"Q":"3472925.84746", //Taker buy quote asset volume
"B":"0" // Ignore
}
}
\*\@continuousKline*\
```python
def kline_futures_socket(
self,
symbol: str,
interval=AsyncClient.KLINE_INTERVAL_1MINUTE,
futures_type: FuturesType = FuturesType.USD_M,
contract_type: ContractType = ContractType.PERPETUAL,
):
"""Start a websocket for symbol kline data for the perpeual futures stream
https://binance-docs.github.io/apidocs/futures/en/#continuous-contract-kline-candlestick-streams
:param symbol: required
:type symbol: str
:param interval: Kline interval, default KLINE_INTERVAL_1MINUTE
:type interval: str
:param futures_type: use USD-M or COIN-M futures default USD-M
:param contract_type: use PERPETUAL or CURRENT_QUARTER or NEXT_QUARTER default PERPETUAL
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"e":"continuous_kline", // Event type
"E":1607443058651, // Event time
"ps":"BTCUSDT", // Pair
"ct":"PERPETUAL" // Contract type
"k":{
"t":1607443020000, // Kline start time
"T":1607443079999, // Kline close time
"i":"1m", // Interval
"f":116467658886, // First trade ID
"L":116468012423, // Last trade ID
"o":"18787.00", // Open price
"c":"18804.04", // Close price
"h":"18804.04", // High price
"l":"18786.54", // Low price
"v":"197.664", // volume
"n": 543, // Number of trades
"x":false, // Is this kline closed?
"q":"3715253.19494", // Quote asset volume
"V":"184.769", // Taker buy volume
"Q":"3472925.84746", //Taker buy quote asset volume
"B":"0" // Ignore
}
}
_@continuousKline_
"""
path = f"{symbol.lower()}_{contract_type.value}@continuousKline_{interval}"
return self._get_futures_socket(path, prefix="ws/", futures_type=futures_type)
```
Start a miniticker websocket for all trades
This is not in the official Binance api docs, but this is what
feeds the right column on a ticker page on Binance.
:param update\_time: time between callbacks in milliseconds, must be 1000 or greater
:type update\_time: int
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\[
\{
'e': '24hrMiniTicker', # Event type
'E': 1515906156273, # Event time
's': 'QTUMETH', # Symbol
'c': '0.03836900', # close
'o': '0.03953500', # open
'h': '0.04400000', # high
'l': '0.03756000', # low
'v': '147435.80000000', # volume
'q': '5903.84338533' # quote volume
}
]
```python
def miniticker_socket(self, update_time: int = 1000):
"""Start a miniticker websocket for all trades
This is not in the official Binance api docs, but this is what
feeds the right column on a ticker page on Binance.
:param update_time: time between callbacks in milliseconds, must be 1000 or greater
:type update_time: int
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
[
{
'e': '24hrMiniTicker', # Event type
'E': 1515906156273, # Event time
's': 'QTUMETH', # Symbol
'c': '0.03836900', # close
'o': '0.03953500', # open
'h': '0.04400000', # high
'l': '0.03756000', # low
'v': '147435.80000000', # volume
'q': '5903.84338533' # quote volume
}
]
"""
return self._get_socket(f"!miniTicker@arr@{update_time}ms")
```
Start a websocket for symbol trade data
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#trade-streams](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#trade-streams)
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"e": "trade", # Event type
"E": 123456789, # Event time
"s": "BNBBTC", # Symbol
"t": 12345, # Trade ID
"p": "0.001", # Price
"q": "100", # Quantity
"b": 88, # Buyer order Id
"a": 50, # Seller order Id
"T": 123456785, # Trade time
"m": true, # Is the buyer the market maker?
"M": true # Ignore.
}
```python
def trade_socket(self, symbol: str):
"""Start a websocket for symbol trade data
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#trade-streams
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"e": "trade", # Event type
"E": 123456789, # Event time
"s": "BNBBTC", # Symbol
"t": 12345, # Trade ID
"p": "0.001", # Price
"q": "100", # Quantity
"b": 88, # Buyer order Id
"a": 50, # Seller order Id
"T": 123456785, # Trade time
"m": true, # Is the buyer the market maker?
"M": true # Ignore.
}
"""
return self._get_socket(symbol.lower() + "@trade")
```
Start a websocket for symbol trade data
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#aggregate-trade-streams](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#aggregate-trade-streams)
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"e": "aggTrade", # event type
"E": 1499405254326, # event time
"s": "ETHBTC", # symbol
"a": 70232, # aggregated tradeid
"p": "0.10281118", # price
"q": "8.15632997", # quantity
"f": 77489, # first breakdown trade id
"l": 77489, # last breakdown trade id
"T": 1499405254324, # trade time
"m": false, # whether buyer is a maker
"M": true # can be ignored
}
```python
def aggtrade_socket(self, symbol: str):
"""Start a websocket for symbol trade data
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#aggregate-trade-streams
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"e": "aggTrade", # event type
"E": 1499405254326, # event time
"s": "ETHBTC", # symbol
"a": 70232, # aggregated tradeid
"p": "0.10281118", # price
"q": "8.15632997", # quantity
"f": 77489, # first breakdown trade id
"l": 77489, # last breakdown trade id
"T": 1499405254324, # trade time
"m": false, # whether buyer is a maker
"M": true # can be ignored
}
"""
return self._get_socket(symbol.lower() + "@aggTrade")
```
Start a websocket for aggregate symbol trade data for the futures stream
:param symbol: required
:param futures\_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"e": "aggTrade", // Event type
"E": 123456789, // Event time
"s": "BTCUSDT", // Symbol
"a": 5933014, // Aggregate trade ID
"p": "0.001", // Price
"q": "100", // Quantity
"f": 100, // First trade ID
"l": 105, // Last trade ID
"T": 123456785, // Trade time
"m": true, // Is the buyer the market maker?
}
```python
def aggtrade_futures_socket(
self, symbol: str, futures_type: FuturesType = FuturesType.USD_M
):
"""Start a websocket for aggregate symbol trade data for the futures stream
:param symbol: required
:param futures_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"e": "aggTrade", // Event type
"E": 123456789, // Event time
"s": "BTCUSDT", // Symbol
"a": 5933014, // Aggregate trade ID
"p": "0.001", // Price
"q": "100", // Quantity
"f": 100, // First trade ID
"l": 105, // Last trade ID
"T": 123456785, // Trade time
"m": true, // Is the buyer the market maker?
}
"""
return self._get_futures_socket(
symbol.lower() + "@aggTrade", futures_type=futures_type
)
```
Start a websocket for a symbol's miniTicker data
[https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream](https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream)
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"e": "24hrMiniTicker", // Event type
"E": 123456789, // Event time
"s": "BNBBTC", // Symbol
"c": "0.0025", // Close price
"o": "0.0010", // Open price
"h": "0.0025", // High price
"l": "0.0010", // Low price
"v": "10000", // Total traded base asset volume
"q": "18" // Total traded quote asset volume
}
```python
def symbol_miniticker_socket(self, symbol: str):
"""Start a websocket for a symbol's miniTicker data
https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-mini-ticker-stream
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"e": "24hrMiniTicker", // Event type
"E": 123456789, // Event time
"s": "BNBBTC", // Symbol
"c": "0.0025", // Close price
"o": "0.0010", // Open price
"h": "0.0025", // High price
"l": "0.0010", // Low price
"v": "10000", // Total traded base asset volume
"q": "18" // Total traded quote asset volume
}
"""
return self._get_socket(symbol.lower() + "@miniTicker")
```
Start a websocket for a symbol's ticker data
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#individual-symbol-ticker-streams](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#individual-symbol-ticker-streams)
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"e": "24hrTicker", # Event type
"E": 123456789, # Event time
"s": "BNBBTC", # Symbol
"p": "0.0015", # Price change
"P": "250.00", # Price change percent
"w": "0.0018", # Weighted average price
"x": "0.0009", # Previous day's close price
"c": "0.0025", # Current day's close price
"Q": "10", # Close trade's quantity
"b": "0.0024", # Best bid price
"B": "10", # Bid bid quantity
"a": "0.0026", # Best ask price
"A": "100", # Best ask quantity
"o": "0.0010", # Open price
"h": "0.0025", # High price
"l": "0.0010", # Low price
"v": "10000", # Total traded base asset volume
"q": "18", # Total traded quote asset volume
"O": 0, # Statistics open time
"C": 86400000, # Statistics close time
"F": 0, # First trade ID
"L": 18150, # Last trade Id
"n": 18151 # Total number of trades
}
```python
def symbol_ticker_socket(self, symbol: str):
"""Start a websocket for a symbol's ticker data
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#individual-symbol-ticker-streams
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"e": "24hrTicker", # Event type
"E": 123456789, # Event time
"s": "BNBBTC", # Symbol
"p": "0.0015", # Price change
"P": "250.00", # Price change percent
"w": "0.0018", # Weighted average price
"x": "0.0009", # Previous day's close price
"c": "0.0025", # Current day's close price
"Q": "10", # Close trade's quantity
"b": "0.0024", # Best bid price
"B": "10", # Bid bid quantity
"a": "0.0026", # Best ask price
"A": "100", # Best ask quantity
"o": "0.0010", # Open price
"h": "0.0025", # High price
"l": "0.0010", # Low price
"v": "10000", # Total traded base asset volume
"q": "18", # Total traded quote asset volume
"O": 0, # Statistics open time
"C": 86400000, # Statistics close time
"F": 0, # First trade ID
"L": 18150, # Last trade Id
"n": 18151 # Total number of trades
}
"""
return self._get_socket(symbol.lower() + "@ticker")
```
Start a websocket for all ticker data
By default all markets are included in an array.
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-market-tickers-stream](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-market-tickers-stream)
:param coro: callback function to handle messages
:type coro: function
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\[
\{
'F': 278610,
'o': '0.07393000',
's': 'BCCBTC',
'C': 1509622420916,
'b': '0.07800800',
'l': '0.07160300',
'h': '0.08199900',
'L': 287722,
'P': '6.694',
'Q': '0.10000000',
'q': '1202.67106335',
'p': '0.00494900',
'O': 1509536020916,
'a': '0.07887800',
'n': 9113,
'B': '1.00000000',
'c': '0.07887900',
'x': '0.07399600',
'w': '0.07639068',
'A': '2.41900000',
'v': '15743.68900000'
}
]
```python
def ticker_socket(self):
"""Start a websocket for all ticker data
By default all markets are included in an array.
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-market-tickers-stream
:param coro: callback function to handle messages
:type coro: function
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
[
{
'F': 278610,
'o': '0.07393000',
's': 'BCCBTC',
'C': 1509622420916,
'b': '0.07800800',
'l': '0.07160300',
'h': '0.08199900',
'L': 287722,
'P': '6.694',
'Q': '0.10000000',
'q': '1202.67106335',
'p': '0.00494900',
'O': 1509536020916,
'a': '0.07887800',
'n': 9113,
'B': '1.00000000',
'c': '0.07887900',
'x': '0.07399600',
'w': '0.07639068',
'A': '2.41900000',
'v': '15743.68900000'
}
]
"""
return self._get_socket("!ticker@arr")
```
Start a websocket for all ticker data
By default all markets are included in an array.
[https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams](https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams)
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\[
\{
"e": "24hrTicker", // Event type
"E": 123456789, // Event time
"s": "BTCUSDT", // Symbol
"p": "0.0015", // Price change
"P": "250.00", // Price change percent
"w": "0.0018", // Weighted average price
"c": "0.0025", // Last price
"Q": "10", // Last quantity
"o": "0.0010", // Open price
"h": "0.0025", // High price
"l": "0.0010", // Low price
"v": "10000", // Total traded base asset volume
"q": "18", // Total traded quote asset volume
"O": 0, // Statistics open time
"C": 86400000, // Statistics close time
"F": 0, // First trade ID
"L": 18150, // Last trade Id
"n": 18151 // Total number of trades
}
]
```python
def futures_ticker_socket(self):
"""Start a websocket for all ticker data
By default all markets are included in an array.
https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
[
{
"e": "24hrTicker", // Event type
"E": 123456789, // Event time
"s": "BTCUSDT", // Symbol
"p": "0.0015", // Price change
"P": "250.00", // Price change percent
"w": "0.0018", // Weighted average price
"c": "0.0025", // Last price
"Q": "10", // Last quantity
"o": "0.0010", // Open price
"h": "0.0025", // High price
"l": "0.0010", // Low price
"v": "10000", // Total traded base asset volume
"q": "18", // Total traded quote asset volume
"O": 0, // Statistics open time
"C": 86400000, // Statistics close time
"F": 0, // First trade ID
"L": 18150, // Last trade Id
"n": 18151 // Total number of trades
}
]
"""
return self._get_futures_socket("!ticker@arr", FuturesType.USD_M)
```
Start a websocket for all ticker data
By default all markets are included in an array.
[https://binance-docs.github.io/apidocs/delivery/en/#all-market-tickers-streams](https://binance-docs.github.io/apidocs/delivery/en/#all-market-tickers-streams)
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\[
\{
"e": "24hrTicker", // Event type
"E": 123456789, // Event time
"s": "BTCUSDT", // Symbol
"p": "0.0015", // Price change
"P": "250.00", // Price change percent
"w": "0.0018", // Weighted average price
"c": "0.0025", // Last price
"Q": "10", // Last quantity
"o": "0.0010", // Open price
"h": "0.0025", // High price
"l": "0.0010", // Low price
"v": "10000", // Total traded base asset volume
"q": "18", // Total traded quote asset volume
"O": 0, // Statistics open time
"C": 86400000, // Statistics close time
"F": 0, // First trade ID
"L": 18150, // Last trade Id
"n": 18151 // Total number of trades
}
]
```python
def futures_coin_ticker_socket(self):
"""Start a websocket for all ticker data
By default all markets are included in an array.
https://binance-docs.github.io/apidocs/delivery/en/#all-market-tickers-streams
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
[
{
"e": "24hrTicker", // Event type
"E": 123456789, // Event time
"s": "BTCUSDT", // Symbol
"p": "0.0015", // Price change
"P": "250.00", // Price change percent
"w": "0.0018", // Weighted average price
"c": "0.0025", // Last price
"Q": "10", // Last quantity
"o": "0.0010", // Open price
"h": "0.0025", // High price
"l": "0.0010", // Low price
"v": "10000", // Total traded base asset volume
"q": "18", // Total traded quote asset volume
"O": 0, // Statistics open time
"C": 86400000, // Statistics close time
"F": 0, // First trade ID
"L": 18150, // Last trade Id
"n": 18151 // Total number of trades
}
]
"""
return self._get_futures_socket("!ticker@arr", FuturesType.COIN_M)
```
Start a websocket for a symbol's futures mark price
[https://binance-docs.github.io/apidocs/delivery/en/#index-price-stream](https://binance-docs.github.io/apidocs/delivery/en/#index-price-stream)
:param symbol: required
:param fast: use faster or 1s default
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"e": "indexPriceUpdate", // Event type
"E": 1591261236000, // Event time
"i": "BTCUSD", // Pair
"p": "9636.57860000", // Index Price
}
```python
def index_price_socket(self, symbol: str, fast: bool = True):
"""Start a websocket for a symbol's futures mark price
https://binance-docs.github.io/apidocs/delivery/en/#index-price-stream
:param symbol: required
:param fast: use faster or 1s default
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"e": "indexPriceUpdate", // Event type
"E": 1591261236000, // Event time
"i": "BTCUSD", // Pair
"p": "9636.57860000", // Index Price
}
"""
stream_name = "@indexPrice@1s" if fast else "@indexPrice"
return self._get_futures_socket(
symbol.lower() + stream_name, futures_type=FuturesType.COIN_M
)
```
Start a websocket for a symbol's futures mark price
[https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream](https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream)
:param symbol: required
:param fast: use faster or 1s default
:param futures\_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"e": "markPriceUpdate", // Event type
"E": 1562305380000, // Event time
"s": "BTCUSDT", // Symbol
"p": "11185.87786614", // Mark price
"r": "0.00030000", // Funding rate
"T": 1562306400000 // Next funding time
}
```python
def symbol_mark_price_socket(
self,
symbol: str,
fast: bool = True,
futures_type: FuturesType = FuturesType.USD_M,
):
"""Start a websocket for a symbol's futures mark price
https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream
:param symbol: required
:param fast: use faster or 1s default
:param futures_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"e": "markPriceUpdate", // Event type
"E": 1562305380000, // Event time
"s": "BTCUSDT", // Symbol
"p": "11185.87786614", // Mark price
"r": "0.00030000", // Funding rate
"T": 1562306400000 // Next funding time
}
"""
stream_name = "@markPrice@1s" if fast else "@markPrice"
return self._get_futures_socket(
symbol.lower() + stream_name, futures_type=futures_type
)
```
Start a websocket for all futures mark price data
By default all symbols are included in an array.
[https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream-for-all-market](https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream-for-all-market)
:param fast: use faster or 1s default
:param futures\_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\[
\{
"e": "markPriceUpdate", // Event type
"E": 1562305380000, // Event time
"s": "BTCUSDT", // Symbol
"p": "11185.87786614", // Mark price
"r": "0.00030000", // Funding rate
"T": 1562306400000 // Next funding time
}
]
```python
def all_mark_price_socket(
self, fast: bool = True, futures_type: FuturesType = FuturesType.USD_M
):
"""Start a websocket for all futures mark price data
By default all symbols are included in an array.
https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream-for-all-market
:param fast: use faster or 1s default
:param futures_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
[
{
"e": "markPriceUpdate", // Event type
"E": 1562305380000, // Event time
"s": "BTCUSDT", // Symbol
"p": "11185.87786614", // Mark price
"r": "0.00030000", // Funding rate
"T": 1562306400000 // Next funding time
}
]
"""
stream_name = "!markPrice@arr@1s" if fast else "!markPrice@arr"
return self._get_futures_socket(stream_name, futures_type=futures_type)
```
Start a websocket for a symbol's ticker data
By default all markets are included in an array.
[https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-book-ticker-streams](https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-book-ticker-streams)
:param symbol: required
:param futures\_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
.. code-block:: python
\[
\{
"u":400900217, // order book updateId
"s":"BNBUSDT", // symbol
"b":"25.35190000", // best bid price
"B":"31.21000000", // best bid qty
"a":"25.36520000", // best ask price
"A":"40.66000000" // best ask qty
}
]
```python
def symbol_ticker_futures_socket(
self, symbol: str, futures_type: FuturesType = FuturesType.USD_M
):
"""Start a websocket for a symbol's ticker data
By default all markets are included in an array.
https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-book-ticker-streams
:param symbol: required
:param futures_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
.. code-block:: python
[
{
"u":400900217, // order book updateId
"s":"BNBUSDT", // symbol
"b":"25.35190000", // best bid price
"B":"31.21000000", // best bid qty
"a":"25.36520000", // best ask price
"A":"40.66000000" // best ask qty
}
]
"""
return self._get_futures_socket(
symbol.lower() + "@bookTicker", futures_type=futures_type
)
```
Start a futures websocket for a single symbol's ticker data
[https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-ticker-streams](https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-ticker-streams)
:param symbol: required
:type symbol: str
:param futures\_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
.. code-block:: python
\{
"e": "24hrTicker", // Event type
"E": 123456789, // Event time
"s": "BTCUSDT", // Symbol
"p": "0.0015", // Price change
}
```python
def individual_symbol_ticker_futures_socket(
self, symbol: str, futures_type: FuturesType = FuturesType.USD_M
):
"""Start a futures websocket for a single symbol's ticker data
https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-ticker-streams
:param symbol: required
:type symbol: str
:param futures_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
.. code-block:: python
{
"e": "24hrTicker", // Event type
"E": 123456789, // Event time
"s": "BTCUSDT", // Symbol
"p": "0.0015", // Price change
}
"""
return self._get_futures_socket(
symbol.lower() + "@ticker", futures_type=futures_type
)
```
Start a websocket for all ticker data
By default all markets are included in an array.
[https://binance-docs.github.io/apidocs/futures/en/#all-book-tickers-stream](https://binance-docs.github.io/apidocs/futures/en/#all-book-tickers-stream)
[https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams](https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams)
:param channel: optional channel type, default '!bookTicker', but '!ticker\@arr' is also available
:param: futures\_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\[
\{
"u":400900217, // order book updateId
"s":"BNBUSDT", // symbol
"b":"25.35190000", // best bid price
"B":"31.21000000", // best bid qty
"a":"25.36520000", // best ask price
"A":"40.66000000" // best ask qty
}
]
```python
def all_ticker_futures_socket(
self,
channel: str = "!bookTicker",
futures_type: FuturesType = FuturesType.USD_M,
):
"""Start a websocket for all ticker data
By default all markets are included in an array.
https://binance-docs.github.io/apidocs/futures/en/#all-book-tickers-stream
https://binance-docs.github.io/apidocs/futures/en/#all-market-tickers-streams
:param channel: optional channel type, default '!bookTicker', but '!ticker@arr' is also available
:param: futures_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
[
{
"u":400900217, // order book updateId
"s":"BNBUSDT", // symbol
"b":"25.35190000", // best bid price
"B":"31.21000000", // best bid qty
"a":"25.36520000", // best ask price
"A":"40.66000000" // best ask qty
}
]
"""
return self._get_futures_socket(channel, futures_type=futures_type)
```
Start a websocket for the best bid or ask's price or quantity for a specified symbol.
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#individual-symbol-book-ticker-streams](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#individual-symbol-book-ticker-streams)
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
"u":400900217, // order book updateId
"s":"BNBUSDT", // symbol
"b":"25.35190000", // best bid price
"B":"31.21000000", // best bid qty
"a":"25.36520000", // best ask price
"A":"40.66000000" // best ask qty
}
```python
def symbol_book_ticker_socket(self, symbol: str):
"""Start a websocket for the best bid or ask's price or quantity for a specified symbol.
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#individual-symbol-book-ticker-streams
:param symbol: required
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
"u":400900217, // order book updateId
"s":"BNBUSDT", // symbol
"b":"25.35190000", // best bid price
"B":"31.21000000", // best bid qty
"a":"25.36520000", // best ask price
"A":"40.66000000" // best ask qty
}
"""
return self._get_socket(symbol.lower() + "@bookTicker")
```
Start a websocket for the best bid or ask's price or quantity for all symbols.
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-book-tickers-stream](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-book-tickers-stream)
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
\{
// Same as \@bookTicker payload
}
```python
def book_ticker_socket(self):
"""Start a websocket for the best bid or ask's price or quantity for all symbols.
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#all-book-tickers-stream
:returns: connection key string if successful, False otherwise
Message Format
.. code-block:: python
{
// Same as @bookTicker payload
}
"""
return self._get_socket("!bookTicker")
```
Start a multiplexed socket using a list of socket names.
User stream sockets can not be included.
Symbols in socket name must be lowercase i.e bnbbtc\@aggTrade, neobtc\@ticker
Combined stream events are wrapped as follows: \{"stream":"\","data":\}
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md)
:param streams: list of stream names in lower case
:type streams: list
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
```python
def multiplex_socket(self, streams: List[str]):
"""Start a multiplexed socket using a list of socket names.
User stream sockets can not be included.
Symbols in socket name must be lowercase i.e bnbbtc@aggTrade, neobtc@ticker
Combined stream events are wrapped as follows: {"stream":"","data":}
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md
:param streams: list of stream names in lower case
:type streams: list
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
"""
path = f"streams={'/'.join(streams)}"
return self._get_socket(path, prefix="stream?")
```
Start a multiplexed socket using a list of socket names.
[https://developers.binance.com/docs/derivatives/option/websocket-market-streams](https://developers.binance.com/docs/derivatives/option/websocket-market-streams)
```python
def options_multiplex_socket(self, streams: List[str]):
"""Start a multiplexed socket using a list of socket names.
https://developers.binance.com/docs/derivatives/option/websocket-market-streams
"""
stream_name = "/".join([s for s in streams])
stream_path = f"streams={stream_name}"
return self._get_options_socket(stream_path, prefix="stream?")
```
Start a multiplexed socket using a list of socket names.
User stream sockets can not be included.
Symbols in socket name must be lowercase i.e bnbbtc\@aggTrade, neobtc\@ticker
Combined stream events are wrapped as follows: \{"stream":"\","data":\}
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md](https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md)
:param streams: list of stream names in lower case
:param futures\_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
```python
def futures_multiplex_socket(
self, streams: List[str], futures_type: FuturesType = FuturesType.USD_M
):
"""Start a multiplexed socket using a list of socket names.
User stream sockets can not be included.
Symbols in socket name must be lowercase i.e bnbbtc@aggTrade, neobtc@ticker
Combined stream events are wrapped as follows: {"stream":"","data":}
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md
:param streams: list of stream names in lower case
:param futures_type: use USD-M or COIN-M futures default USD-M
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
"""
path = f"streams={'/'.join(streams)}"
return self._get_futures_socket(
path, prefix="stream?", futures_type=futures_type
)
```
Start a websocket for user data
[https://github.com/binance-exchange/binance-official-api-docs/blob/master/user-data-stream.md](https://github.com/binance-exchange/binance-official-api-docs/blob/master/user-data-stream.md)
[https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot](https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot)
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
```python
def user_socket(self):
"""Start a websocket for user data
https://github.com/binance-exchange/binance-official-api-docs/blob/master/user-data-stream.md
https://binance-docs.github.io/apidocs/spot/en/#listen-key-spot
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
"""
stream_url = self.STREAM_URL
if self.testnet:
stream_url = self.STREAM_TESTNET_URL
elif self.demo:
stream_url = self.STREAM_DEMO_URL
return self._get_account_socket("user", stream_url=stream_url)
```
Start a websocket for futures user data
[https://binance-docs.github.io/apidocs/futures/en/#user-data-streams](https://binance-docs.github.io/apidocs/futures/en/#user-data-streams)
:returns: connection key string if successful, False otherwise
Message Format - see Binanace API docs for all types
```python
def futures_user_socket(self):
"""Start a websocket for futures user data
https://binance-docs.github.io/apidocs/futures/en/#user-data-streams
:returns: connection key string if successful, False otherwise
Message Format - see Binanace API docs for all types
"""
stream_url = self.FSTREAM_URL
if self.testnet:
stream_url = self.FSTREAM_TESTNET_URL
elif self.demo:
stream_url = self.FSTREAM_DEMO_URL
return self._get_account_socket("futures", stream_url=stream_url)
```
Start a websocket for coin futures user data
[https://binance-docs.github.io/apidocs/delivery/en/#user-data-streams](https://binance-docs.github.io/apidocs/delivery/en/#user-data-streams)
:returns: connection key string if successful, False otherwise
Message Format - see Binanace API docs for all types
```python
def coin_futures_user_socket(self):
"""Start a websocket for coin futures user data
https://binance-docs.github.io/apidocs/delivery/en/#user-data-streams
:returns: connection key string if successful, False otherwise
Message Format - see Binanace API docs for all types
"""
return self._get_account_socket("coin_futures", stream_url=self.DSTREAM_URL)
```
Start a websocket for cross-margin data
[https://binance-docs.github.io/apidocs/spot/en/#listen-key-margin](https://binance-docs.github.io/apidocs/spot/en/#listen-key-margin)
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
```python
def margin_socket(self):
"""Start a websocket for cross-margin data
https://binance-docs.github.io/apidocs/spot/en/#listen-key-margin
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
"""
stream_url = self.STREAM_URL
if self.testnet:
stream_url = self.STREAM_TESTNET_URL
elif self.demo:
stream_url = self.STREAM_DEMO_URL
return self._get_account_socket("margin", stream_url=stream_url)
```
Start a websocket for futures data
[https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams](https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams)
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
```python
def futures_socket(self):
"""Start a websocket for futures data
https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
"""
stream_url = self.FSTREAM_URL
if self.testnet:
stream_url = self.FSTREAM_TESTNET_URL
elif self.demo:
stream_url = self.FSTREAM_DEMO_URL
return self._get_account_socket("futures", stream_url=stream_url)
```
Start a websocket for coin futures data
[https://binance-docs.github.io/apidocs/delivery/en/#websocket-market-streams](https://binance-docs.github.io/apidocs/delivery/en/#websocket-market-streams)
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
```python
def coin_futures_socket(self):
"""Start a websocket for coin futures data
https://binance-docs.github.io/apidocs/delivery/en/#websocket-market-streams
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
"""
stream_url = self.DSTREAM_URL
if self.testnet:
stream_url = self.DSTREAM_TESTNET_URL
elif self.demo:
stream_url = self.DSTREAM_DEMO_URL
return self._get_account_socket("coin_futures", stream_url=stream_url)
```
Start a websocket for portfolio margin user data
[https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams](https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams)
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
```python
def portfolio_margin_socket(self):
"""Start a websocket for portfolio margin user data
https://developers.binance.com/docs/derivatives/portfolio-margin/user-data-streams
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
"""
stream_url = self.FSTREAM_URL
if self.testnet:
stream_url = self.FSTREAM_TESTNET_URL
elif self.demo:
stream_url = self.FSTREAM_DEMO_URL
stream_url += "pm/"
return self._get_account_socket("portfolio_margin", stream_url=stream_url)
```
Start a websocket for isolated margin data
[https://binance-docs.github.io/apidocs/spot/en/#listen-key-isolated-margin](https://binance-docs.github.io/apidocs/spot/en/#listen-key-isolated-margin)
:param symbol: required - symbol for the isolated margin account
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
```python
def isolated_margin_socket(self, symbol: str):
"""Start a websocket for isolated margin data
https://binance-docs.github.io/apidocs/spot/en/#listen-key-isolated-margin
:param symbol: required - symbol for the isolated margin account
:type symbol: str
:returns: connection key string if successful, False otherwise
Message Format - see Binance API docs for all types
"""
stream_url = self.STREAM_URL
if self.testnet:
stream_url = self.STREAM_TESTNET_URL
elif self.demo:
stream_url = self.STREAM_DEMO_URL
return self._get_account_socket(symbol, stream_url=stream_url)
```
Subscribe to a 24-hour ticker info stream for options trading.
API Reference: [https://developers.binance.com/docs/derivatives/option/websocket-market-streams/24-hour-TICKER](https://developers.binance.com/docs/derivatives/option/websocket-market-streams/24-hour-TICKER)
Stream provides real-time 24hr ticker information for all symbols. Only symbols whose ticker info
changed will be sent. Updates every 1000ms.
:param symbol: The option symbol to subscribe to (e.g. "BTC-220930-18000-C")
:type symbol: str
```python
def options_ticker_socket(self, symbol: str):
"""Subscribe to a 24-hour ticker info stream for options trading.
API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/24-hour-TICKER
Stream provides real-time 24hr ticker information for all symbols. Only symbols whose ticker info
changed will be sent. Updates every 1000ms.
:param symbol: The option symbol to subscribe to (e.g. "BTC-220930-18000-C")
:type symbol: str
"""
return self._get_options_socket(symbol.upper() + "@ticker")
```
Subscribe to a 24-hour ticker info stream by underlying asset and expiration date.
API Reference: [https://developers.binance.com/docs/derivatives/option/websocket-market-streams/24-hour-TICKER-by-underlying-asset-and-expiration-data](https://developers.binance.com/docs/derivatives/option/websocket-market-streams/24-hour-TICKER-by-underlying-asset-and-expiration-data)
Stream provides real-time 24hr ticker information grouped by underlying asset and expiration date.
Updates every 1000ms.
:param symbol: The underlying asset (e.g., "ETH")
:type symbol: str
:param expiration\_date: The expiration date (e.g., "220930" for Sept 30, 2022)
:type expiration\_date: str
```python
def options_ticker_by_expiration_socket(self, symbol: str, expiration_date: str):
"""Subscribe to a 24-hour ticker info stream by underlying asset and expiration date.
API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/24-hour-TICKER-by-underlying-asset-and-expiration-data
Stream provides real-time 24hr ticker information grouped by underlying asset and expiration date.
Updates every 1000ms.
:param symbol: The underlying asset (e.g., "ETH")
:type symbol: str
:param expiration_date: The expiration date (e.g., "220930" for Sept 30, 2022)
:type expiration_date: str
"""
return self._get_options_socket(symbol.upper() + "@ticker@" + expiration_date)
```
Subscribe to a real-time trade information stream.
API Reference: [https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Trade-Streams](https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Trade-Streams)
Stream pushes raw trade information for a specific symbol or underlying asset.
Updates every 50ms.
:param symbol: The option symbol or underlying asset (e.g., "BTC-200630-9000-P" or "BTC")
:type symbol: str
```python
def options_recent_trades_socket(self, symbol: str):
"""Subscribe to a real-time trade information stream.
API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Trade-Streams
Stream pushes raw trade information for a specific symbol or underlying asset.
Updates every 50ms.
:param symbol: The option symbol or underlying asset (e.g., "BTC-200630-9000-P" or "BTC")
:type symbol: str
"""
return self._get_options_socket(symbol.upper() + "@trade")
```
Subscribe to a Kline/Candlestick data stream.
API Reference: [https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Kline-Candlestick-Streams](https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Kline-Candlestick-Streams)
Stream pushes updates to the current klines/candlestick every 1000ms (if existing).
Available intervals:
* Minutes: "1m", "3m", "5m", "15m", "30m"
* Hours: "1h", "2h", "4h", "6h", "12h"
* Days: "1d", "3d"
* Weeks: "1w"
:param symbol: The option symbol (e.g., "BTC-200630-9000-P")
:type symbol: str
:param interval: Kline interval, default KLINE\_INTERVAL\_1MINUTE
:type interval: str
```python
def options_kline_socket(
self, symbol: str, interval=AsyncClient.KLINE_INTERVAL_1MINUTE
):
"""Subscribe to a Kline/Candlestick data stream.
API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Kline-Candlestick-Streams
Stream pushes updates to the current klines/candlestick every 1000ms (if existing).
Available intervals:
- Minutes: "1m", "3m", "5m", "15m", "30m"
- Hours: "1h", "2h", "4h", "6h", "12h"
- Days: "1d", "3d"
- Weeks: "1w"
:param symbol: The option symbol (e.g., "BTC-200630-9000-P")
:type symbol: str
:param interval: Kline interval, default KLINE_INTERVAL_1MINUTE
:type interval: str
"""
return self._get_options_socket(symbol.upper() + "@kline_" + interval)
```
Subscribe to partial book depth stream for options trading.
API Reference: [https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Partial-Book-Depth-Streams](https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Partial-Book-Depth-Streams)
Stream provides top N bids and asks from the order book.
Default update speed is 500ms if not specified in the stream name.
:param symbol: The option symbol (e.g., "BTC-200630-9000-P")
:type symbol: str
:param depth: Number of price levels. Valid values: "10", "20", "50", "100"
:type depth: str
```python
def options_depth_socket(self, symbol: str, depth: str = "10"):
"""Subscribe to partial book depth stream for options trading.
API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Partial-Book-Depth-Streams
Stream provides top N bids and asks from the order book.
Default update speed is 500ms if not specified in the stream name.
:param symbol: The option symbol (e.g., "BTC-200630-9000-P")
:type symbol: str
:param depth: Number of price levels. Valid values: "10", "20", "50", "100"
:type depth: str
"""
return self._get_options_socket(symbol.upper() + "@depth" + str(depth))
```
Subscribe to a futures depth data stream
[https://binance-docs.github.io/apidocs/futures/en/#partial-book-depth-streams](https://binance-docs.github.io/apidocs/futures/en/#partial-book-depth-streams)
:param symbol: required
:type symbol: str
:param depth: optional Number of depth entries to return, default 10.
:type depth: str
:param futures\_type: use USD-M or COIN-M futures default USD-M
```python
def futures_depth_socket(self, symbol: str, depth: str = "10", futures_type=FuturesType.USD_M):
"""Subscribe to a futures depth data stream
https://binance-docs.github.io/apidocs/futures/en/#partial-book-depth-streams
:param symbol: required
:type symbol: str
:param depth: optional Number of depth entries to return, default 10.
:type depth: str
:param futures_type: use USD-M or COIN-M futures default USD-M
"""
return self._get_futures_socket(
symbol.lower() + "@depth" + str(depth), futures_type=futures_type
)
```
Subscribe to a futures RPI (Retail Price Improvement) depth data stream
RPI orders are included and aggregated in the stream. Crossed price levels are hidden.
Updates every 500ms.
[https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-market-streams/RPI-Order-Book](https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-market-streams/RPI-Order-Book)
:param symbol: required
:type symbol: str
:param futures\_type: use USD-M or COIN-M futures default USD-M
```python
def futures_rpi_depth_socket(self, symbol: str, futures_type=FuturesType.USD_M):
"""Subscribe to a futures RPI (Retail Price Improvement) depth data stream
RPI orders are included and aggregated in the stream. Crossed price levels are hidden.
Updates every 500ms.
https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/websocket-market-streams/RPI-Order-Book
:param symbol: required
:type symbol: str
:param futures_type: use USD-M or COIN-M futures default USD-M
"""
return self._get_futures_socket(
symbol.lower() + "@rpiDepth@500ms", futures_type=futures_type
)
```
Subscribe to a new symbol listing information stream.
Stream provides real-time notifications when new option symbols are listed.
Updates every 50ms.
Stream name: option\_pair
API Reference: [https://developers.binance.com/docs/derivatives/option/websocket-market-streams/New-Symbol-Info](https://developers.binance.com/docs/derivatives/option/websocket-market-streams/New-Symbol-Info)
Response fields include:
* Event type and timestamps
* Underlying index (e.g., 'BTCUSDT')
* Quotation asset (e.g., 'USDT')
* Trading pair name (e.g., 'BTC-221116-21000-C')
* Conversion ratio and minimum trade volume
* Option type (CALL/PUT)
* Strike price and expiration time
```python
def options_new_symbol_socket(self):
"""Subscribe to a new symbol listing information stream.
Stream provides real-time notifications when new option symbols are listed.
Updates every 50ms.
Stream name: option_pair
API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/New-Symbol-Info
Response fields include:
- Event type and timestamps
- Underlying index (e.g., 'BTCUSDT')
- Quotation asset (e.g., 'USDT')
- Trading pair name (e.g., 'BTC-221116-21000-C')
- Conversion ratio and minimum trade volume
- Option type (CALL/PUT)
- Strike price and expiration time
"""
return self._get_options_socket("option_pair")
```
Subscribe to an options open interest stream.
Stream provides open interest information for specific underlying asset on specific expiration date.
Updates every 60 seconds.
Stream name format: \@openInterest@\
API Reference: [https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Open-Interest](https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Open-Interest)
Response fields include:
* Event type and timestamps
* Option symbol (e.g., 'ETH-221125-2700-C')
* Open interest in contracts
* Open interest in USDT
:param symbol: The underlying asset (e.g., "ETH")
:type symbol: str
:param expiration\_date: The expiration date (e.g., "221125" for Nov 25, 2022)
:type expiration\_date: str
```python
def options_open_interest_socket(self, symbol: str, expiration_date: str):
"""Subscribe to an options open interest stream.
Stream provides open interest information for specific underlying asset on specific expiration date.
Updates every 60 seconds.
Stream name format: @openInterest@
API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Open-Interest
Response fields include:
- Event type and timestamps
- Option symbol (e.g., 'ETH-221125-2700-C')
- Open interest in contracts
- Open interest in USDT
:param symbol: The underlying asset (e.g., "ETH")
:type symbol: str
:param expiration_date: The expiration date (e.g., "221125" for Nov 25, 2022)
:type expiration_date: str
"""
return self._get_options_socket(symbol.upper() + "@openInterest@" + expiration_date)
```
Subscribe to an options mark price stream.
Stream provides mark price information for all option symbols on specific underlying asset.
Updates every 1000ms.
Stream name format: \@markPrice
API Reference: [https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Mark-Price](https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Mark-Price)
Response fields include:
* Event type and timestamps
* Option symbol (e.g., 'ETH-220930-1500-C')
* Option mark price
:param symbol: The underlying asset (e.g., "ETH")
:type symbol: str
```python
def options_mark_price_socket(self, symbol: str):
"""Subscribe to an options mark price stream.
Stream provides mark price information for all option symbols on specific underlying asset.
Updates every 1000ms.
Stream name format: @markPrice
API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Mark-Price
Response fields include:
- Event type and timestamps
- Option symbol (e.g., 'ETH-220930-1500-C')
- Option mark price
:param symbol: The underlying asset (e.g., "ETH")
:type symbol: str
"""
return self._get_options_socket(symbol.upper() + "@markPrice")
```
Subscribe to an options index price stream.
API Reference: [https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Index-Price-Streams](https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Index-Price-Streams)
Stream provides index price information for underlying assets (e.g., ETHUSDT).
Updates every 1000ms.
Response fields include:
* Event type and timestamps
* Underlying symbol (e.g., 'ETHUSDT')
* Index price
:param symbol: The underlying symbol (e.g., "ETHUSDT")
:type symbol: str
```python
def options_index_price_socket(self, symbol: str):
"""Subscribe to an options index price stream.
API Reference: https://developers.binance.com/docs/derivatives/option/websocket-market-streams/Index-Price-Streams
Stream provides index price information for underlying assets (e.g., ETHUSDT).
Updates every 1000ms.
Response fields include:
- Event type and timestamps
- Underlying symbol (e.g., 'ETHUSDT')
- Index price
:param symbol: The underlying symbol (e.g., "ETHUSDT")
:type symbol: str
"""
return self._get_options_socket(symbol.upper() + "@index")
```
Stop a websocket given the connection key
:param conn\_key: Socket connection key
:type conn\_key: string
:returns: None
```python
async def _stop_socket(self, conn_key):
"""Stop a websocket given the connection key
:param conn_key: Socket connection key
:type conn_key: string
:returns: None
"""
if conn_key not in self._conns:
return
del self._conns[conn_key]
```
# BinanceSocketType (/docs/api/ws/streams/BinanceSocketType)
Attributes [#attributes]
# ThreadedWebsocketManager (/docs/api/ws/streams/ThreadedWebsocketManager)
Functions [#functions]
```python
def __init__(
self,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
requests_params: Optional[Dict[str, Any]] = None,
tld: str = "com",
testnet: bool = False,
session_params: Optional[Dict[str, Any]] = None,
https_proxy: Optional[str] = None,
loop: Optional[asyncio.AbstractEventLoop] = None,
max_queue_size: int = 100,
):
super().__init__(
api_key,
api_secret,
requests_params,
tld,
testnet,
session_params,
https_proxy,
loop,
)
self._bsm: Optional[BinanceSocketManager] = None
self._max_queue_size = max_queue_size
```
```python
async def _before_socket_listener_start(self):
assert self._client
self._bsm = BinanceSocketManager(
client=self._client,
max_queue_size=self._max_queue_size
)
```
```python
def _start_async_socket(
self,
callback: Callable,
socket_name: str,
params: Dict[str, Any],
path: Optional[str] = None,
) -> str:
start_time = time.time()
while not self._bsm:
if time.time() - start_time > 5:
raise RuntimeError("Binance Socket Manager failed to initialize after 5 seconds")
time.sleep(0.1)
socket = getattr(self._bsm, socket_name)(**params)
socket_path: str = path or socket._path # noqa
self._socket_running[socket_path] = True
self._loop.call_soon_threadsafe(
asyncio.create_task, self.start_listener(socket, socket_path, callback)
)
return socket_path
```
```python
def start_depth_socket(
self,
callback: Callable,
symbol: str,
depth: Optional[str] = None,
interval: Optional[int] = None,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="depth_socket",
params={
"symbol": symbol,
"depth": depth,
"interval": interval,
},
)
```
```python
def start_kline_socket(
self,
callback: Callable,
symbol: str,
interval=AsyncClient.KLINE_INTERVAL_1MINUTE,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="kline_socket",
params={
"symbol": symbol,
"interval": interval,
},
)
```
```python
def start_kline_futures_socket(
self,
callback: Callable,
symbol: str,
interval=AsyncClient.KLINE_INTERVAL_1MINUTE,
futures_type: FuturesType = FuturesType.USD_M,
contract_type: ContractType = ContractType.PERPETUAL,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="kline_futures_socket",
params={
"symbol": symbol,
"interval": interval,
"futures_type": futures_type,
"contract_type": contract_type,
},
)
```
```python
def start_miniticker_socket(
self, callback: Callable, update_time: int = 1000
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="miniticker_socket",
params={
"update_time": update_time,
},
)
```
```python
def start_trade_socket(self, callback: Callable, symbol: str) -> str:
return self._start_async_socket(
callback=callback,
socket_name="trade_socket",
params={
"symbol": symbol,
},
)
```
```python
def start_aggtrade_socket(self, callback: Callable, symbol: str) -> str:
return self._start_async_socket(
callback=callback,
socket_name="aggtrade_socket",
params={
"symbol": symbol,
},
)
```
```python
def start_aggtrade_futures_socket(
self,
callback: Callable,
symbol: str,
futures_type: FuturesType = FuturesType.USD_M,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="aggtrade_futures_socket",
params={
"symbol": symbol,
"futures_type": futures_type,
},
)
```
```python
def start_symbol_miniticker_socket(self, callback: Callable, symbol: str) -> str:
return self._start_async_socket(
callback=callback,
socket_name="symbol_miniticker_socket",
params={
"symbol": symbol,
},
)
```
```python
def start_symbol_ticker_socket(self, callback: Callable, symbol: str) -> str:
return self._start_async_socket(
callback=callback,
socket_name="symbol_ticker_socket",
params={
"symbol": symbol,
},
)
```
```python
def start_ticker_socket(self, callback: Callable) -> str:
return self._start_async_socket(
callback=callback, socket_name="ticker_socket", params={}
)
```
```python
def start_index_price_socket(
self, callback: Callable, symbol: str, fast: bool = True
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="index_price_socket",
params={"symbol": symbol, "fast": fast},
)
```
```python
def start_symbol_mark_price_socket(
self,
callback: Callable,
symbol: str,
fast: bool = True,
futures_type: FuturesType = FuturesType.USD_M,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="symbol_mark_price_socket",
params={"symbol": symbol, "fast": fast, "futures_type": futures_type},
)
```
```python
def start_all_mark_price_socket(
self,
callback: Callable,
fast: bool = True,
futures_type: FuturesType = FuturesType.USD_M,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="all_mark_price_socket",
params={"fast": fast, "futures_type": futures_type},
)
```
```python
def start_symbol_ticker_futures_socket(
self,
callback: Callable,
symbol: str,
futures_type: FuturesType = FuturesType.USD_M,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="symbol_ticker_futures_socket",
params={"symbol": symbol, "futures_type": futures_type},
)
```
```python
def start_individual_symbol_ticker_futures_socket(
self,
callback: Callable,
symbol: str,
futures_type: FuturesType = FuturesType.USD_M,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="individual_symbol_ticker_futures_socket",
params={"symbol": symbol, "futures_type": futures_type},
)
```
```python
def start_all_ticker_futures_socket(
self, callback: Callable, futures_type: FuturesType = FuturesType.USD_M
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="all_ticker_futures_socket",
params={"futures_type": futures_type},
)
```
```python
def start_symbol_book_ticker_socket(self, callback: Callable, symbol: str) -> str:
return self._start_async_socket(
callback=callback,
socket_name="symbol_book_ticker_socket",
params={"symbol": symbol},
)
```
```python
def start_book_ticker_socket(self, callback: Callable) -> str:
return self._start_async_socket(
callback=callback, socket_name="book_ticker_socket", params={}
)
```
```python
def start_multiplex_socket(self, callback: Callable, streams: List[str]) -> str:
return self._start_async_socket(
callback=callback,
socket_name="multiplex_socket",
params={"streams": streams},
)
```
```python
def start_options_multiplex_socket(
self, callback: Callable, streams: List[str]
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="options_multiplex_socket",
params={"streams": streams},
)
```
```python
def start_futures_multiplex_socket(
self,
callback: Callable,
streams: List[str],
futures_type: FuturesType = FuturesType.USD_M,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="futures_multiplex_socket",
params={"streams": streams, "futures_type": futures_type},
)
```
```python
def start_user_socket(self, callback: Callable) -> str:
return self._start_async_socket(
callback=callback, socket_name="user_socket", params={}
)
```
```python
def start_futures_user_socket(self, callback: Callable) -> str:
return self._start_async_socket(
callback=callback, socket_name="futures_user_socket", params={}
)
```
```python
def start_coin_futures_user_socket(self, callback: Callable) -> str:
return self._start_async_socket(
callback=callback, socket_name="coin_futures_user_socket", params={}
)
```
```python
def start_margin_socket(self, callback: Callable) -> str:
return self._start_async_socket(
callback=callback, socket_name="margin_socket", params={}
)
```
```python
def start_futures_socket(self, callback: Callable) -> str:
return self._start_async_socket(
callback=callback, socket_name="futures_socket", params={}
)
```
```python
def start_coin_futures_socket(self, callback: Callable) -> str:
return self._start_async_socket(
callback=callback, socket_name="coin_futures_socket", params={}
)
```
```python
def start_isolated_margin_socket(self, callback: Callable, symbol: str) -> str:
return self._start_async_socket(
callback=callback,
socket_name="isolated_margin_socket",
params={"symbol": symbol},
)
```
```python
def start_options_ticker_socket(self, callback: Callable, symbol: str) -> str:
return self._start_async_socket(
callback=callback,
socket_name="options_ticker_socket",
params={"symbol": symbol},
)
```
```python
def start_options_ticker_by_expiration_socket(
self, callback: Callable, symbol: str, expiration_date: str
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="options_ticker_by_expiration_socket",
params={"symbol": symbol, "expiration_date": expiration_date},
)
```
```python
def start_options_recent_trades_socket(
self, callback: Callable, symbol: str
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="options_recent_trades_socket",
params={"symbol": symbol},
)
```
```python
def start_options_kline_socket(
self,
callback: Callable,
symbol: str,
interval=AsyncClient.KLINE_INTERVAL_1MINUTE,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="options_kline_socket",
params={"symbol": symbol, "interval": interval},
)
```
```python
def start_options_depth_socket(
self, callback: Callable, symbol: str, depth: str = "10"
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="options_depth_socket",
params={"symbol": symbol, "depth": depth},
)
```
```python
def start_futures_depth_socket(
self,
callback: Callable,
symbol: str,
depth: str = "10",
futures_type=FuturesType.USD_M,
) -> str:
return self._start_async_socket(
callback=callback,
socket_name="futures_depth_socket",
params={"symbol": symbol, "depth": depth, "futures_type": futures_type},
)
```
# streams (/docs/api/ws/streams)
# ThreadedApiManager (/docs/api/ws/threaded_stream/ThreadedApiManager)
Attributes [#attributes]
Functions [#functions]
Initialise the ThreadedApiManager
:param api\_key: Binance API key
:param api\_secret: Binance API secret
:param requests\_params: optional - Dictionary of requests params
:param tld: optional - Top level domain, default is 'com'
:param testnet: optional - Use testnet endpoint
:param session\_params: optional - Session params for aiohttp
:param https\_proxy: optional - Proxy URL
:param \_loop: optional - Event loop
:param verbose: Enable verbose logging for WebSocket connections
:type verbose: bool
```python
def __init__(
self,
api_key: Optional[str] = None,
api_secret: Optional[str] = None,
requests_params: Optional[Dict[str, Any]] = None,
tld: str = "com",
testnet: bool = False,
session_params: Optional[Dict[str, Any]] = None,
https_proxy: Optional[str] = None,
_loop: Optional[asyncio.AbstractEventLoop] = None,
verbose: bool = False,
):
"""Initialise the ThreadedApiManager
:param api_key: Binance API key
:param api_secret: Binance API secret
:param requests_params: optional - Dictionary of requests params
:param tld: optional - Top level domain, default is 'com'
:param testnet: optional - Use testnet endpoint
:param session_params: optional - Session params for aiohttp
:param https_proxy: optional - Proxy URL
:param _loop: optional - Event loop
:param verbose: Enable verbose logging for WebSocket connections
:type verbose: bool
"""
super().__init__()
self._loop: asyncio.AbstractEventLoop = get_loop() if _loop is None else _loop
self._client: Optional[AsyncClient] = None
self._running: bool = True
self._socket_running: Dict[str, bool] = {}
self._log = logging.getLogger(__name__)
self.verbose = verbose
self._client_params = {
"api_key": api_key,
"api_secret": api_secret,
"requests_params": requests_params,
"tld": tld,
"testnet": testnet,
"session_params": session_params,
"https_proxy": https_proxy,
"verbose": verbose,
}
if verbose:
logging.getLogger('binance.ws').setLevel(logging.DEBUG)
```
```python
async def _before_socket_listener_start(self): ...
```
```python
async def socket_listener(self):
try:
self._client = await AsyncClient.create(loop=self._loop, **self._client_params)
await self._before_socket_listener_start()
except Exception as e:
self._log.error(f"Failed to create client: {e}")
self.stop()
while self._running:
await asyncio.sleep(0.2)
while self._socket_running:
await asyncio.sleep(0.2)
self._log.info("Socket listener stopped")
```
```python
async def start_listener(self, socket, path: str, callback):
async with socket as s:
while self._socket_running[path]:
try:
msg = await asyncio.wait_for(s.recv(), 3)
except asyncio.TimeoutError:
...
continue
except Exception as e:
self._log.error(f"Error receiving message: {e}")
msg = {
"e": "error",
"type": e.__class__.__name__,
"m": f"{e}",
}
if not msg:
continue # Handle both async and sync callbacks
if asyncio.iscoroutinefunction(callback):
asyncio.create_task(callback(msg))
else:
callback(msg)
del self._socket_running[path]
```
```python
def run(self):
self._loop.run_until_complete(self.socket_listener())
```
```python
def stop_socket(self, socket_name):
if socket_name in self._socket_running:
self._socket_running[socket_name] = False
```
```python
async def stop_client(self):
if not self._client:
return
await self._client.close_connection()
```
```python
def stop(self):
self._log.debug("Stopping ThreadedApiManager")
if not self._running:
return
self._running = False
if self._client and self._loop and not self._loop.is_closed():
try:
future = asyncio.run_coroutine_threadsafe(
self.stop_client(), self._loop
)
future.result(timeout=5) # Add timeout to prevent hanging
except Exception as e:
# Log the error but don't raise it
self._log.error(f"Error stopping client: {e}")
for socket_name in self._socket_running.keys():
self._socket_running[socket_name] = False
```
# threaded_stream (/docs/api/ws/threaded_stream)
# WebsocketAPI (/docs/api/ws/websocket_api/WebsocketAPI)
Attributes [#attributes]
Functions [#functions]
```python
def __init__(self, url: str, tld: str = "com", testnet: bool = False, https_proxy: Optional[str] = None):
self._tld = tld
self._testnet = testnet
self._responses: Dict[str, asyncio.Future] = {}
self._connection_lock: Optional[asyncio.Lock] = None
# Subscription queues for routing user data stream events
self._subscription_queues: Dict[str, asyncio.Queue] = {}
super().__init__(url=url, prefix="", path="", is_binary=False, https_proxy=https_proxy)
```
Register a queue to receive events for a specific subscription.
```python
def register_subscription_queue(self, subscription_id: str, queue: asyncio.Queue) -> None:
"""Register a queue to receive events for a specific subscription."""
self._subscription_queues[subscription_id] = queue
```
Unregister a subscription queue.
```python
def unregister_subscription_queue(self, subscription_id: str) -> None:
"""Unregister a subscription queue."""
self._subscription_queues.pop(subscription_id, None)
```
Override message handling to support request-response
```python
def _handle_message(self, msg):
"""Override message handling to support request-response"""
parsed_msg = super()._handle_message(msg)
self._log.debug(f"Received message: {parsed_msg}")
if parsed_msg is None:
return None
# Check if this is a subscription event (user data stream, etc.)
# These have 'subscriptionId' and 'event' fields instead of 'id'
if "subscriptionId" in parsed_msg and "event" in parsed_msg:
subscription_id = parsed_msg["subscriptionId"]
event = parsed_msg["event"]
# Route to the registered subscription queue if one exists
if subscription_id in self._subscription_queues:
queue = self._subscription_queues[subscription_id]
try:
queue.put_nowait(event)
except asyncio.QueueFull:
self._log.error(f"Subscription queue full for {subscription_id}, dropping event")
except Exception as e:
self._log.error(f"Error putting event in subscription queue for {subscription_id}: {e}")
return None # Don't put in main queue
else:
# No registered queue, return event for main queue (backward compat)
return event
req_id, exception = None, None
if "id" in parsed_msg:
req_id = parsed_msg["id"]
if "status" in parsed_msg:
if parsed_msg["status"] != 200:
exception = BinanceAPIException(
parsed_msg, parsed_msg["status"], self.json_dumps(parsed_msg["error"])
)
if req_id is not None and req_id in self._responses:
if exception is not None:
self._responses[req_id].set_exception(exception)
else:
self._responses[req_id].set_result(parsed_msg)
return None # Don't queue request-response messages
elif exception is not None:
raise exception
else:
self._log.warning(f"WS api receieved unknown message: {parsed_msg}")
return None
```
Ensure WebSocket connection is established and ready
This function will:
1. Check if connection exists and is streaming
2. Attempt to connect if not
3. Wait for connection to be ready
4. Handle reconnection if needed
```python
async def _ensure_ws_connection(self) -> None:
"""Ensure WebSocket connection is established and ready
This function will:
1. Check if connection exists and is streaming
2. Attempt to connect if not
3. Wait for connection to be ready
4. Handle reconnection if needed
"""
async with self.connection_lock:
try:
if (
self.ws is None
or (isinstance(self.ws, WebSocketClientProtocol) and self.ws.closed)
or self.ws_state != WSListenerState.STREAMING
):
await self.connect()
# Wait for connection to be ready
retries = 0
while (
self.ws_state != WSListenerState.STREAMING
and retries < self.MAX_RECONNECTS
):
if self.ws_state == WSListenerState.RECONNECTING:
self._log.info("Connection is reconnecting, waiting...")
await self._wait_for_reconnect()
elif self.ws is None or self.ws.closed:
self._log.info("Connection lost, reconnecting...")
await self.connect()
retries += 1
await asyncio.sleep(self.MIN_RECONNECT_WAIT)
if self.ws_state != WSListenerState.STREAMING:
raise BinanceWebsocketUnableToConnect(
f"Failed to establish connection after {retries} attempts"
)
self._log.debug("WebSocket connection established")
except Exception as e:
self._log.error(f"Error ensuring WebSocket connection: {e}")
raise BinanceWebsocketUnableToConnect(f"Connection failed: {str(e)}")
```
Send request and wait for response
```python
async def request(self, id: str, payload: dict) -> dict:
"""Send request and wait for response"""
await self._ensure_ws_connection()
# Create future for response
future = asyncio.Future()
self._responses[id] = future
try:
# Send request
if self.ws is None:
raise BinanceWebsocketUnableToConnect(
"Trying to send request while WebSocket is not connected"
)
await self.ws.send(self.json_dumps(payload))
# Wait for response
response = await asyncio.wait_for(future, timeout=self.TIMEOUT)
# Check for errors
if "error" in response:
raise BinanceWebsocketUnableToConnect(response["error"])
return response.get("result", response)
except asyncio.TimeoutError:
raise BinanceWebsocketUnableToConnect("Request timed out")
except Exception as e:
raise e
finally:
self._responses.pop(id, None)
```
Clean up responses before closing
```python
async def __aexit__(self, exc_type, exc_val, exc_tb):
"""Clean up responses before closing"""
response_ids = list(self._responses.keys()) # Create a copy of keys
for req_id in response_ids:
future = self._responses.pop(req_id) # Remove and get the future
if not future.done():
future.set_exception(
BinanceWebsocketUnableToConnect("WebSocket closing")
)
await super().__aexit__(exc_type, exc_val, exc_tb)
```
# websocket_api (/docs/api/ws/websocket_api)