Asynchronous Client

The asynchronous client allows you to interact with the BingX API in a non-blocking manner.

BingX API Async Client.

This module provides a high-level asynchronous client for interacting with the BingX API, including support for spot trading, swap perpetual contracts, standard futures, sub-accounts, and agent functionality. It also includes utilities for managing API keys, listen keys for user data streams, and caching mechanisms for improved performance.

The BingXAsyncClient class is the main entry point for interacting with the API. It initializes sub-clients for specific functionalities like spot trading, swap perpetual contracts, and more. Additionally, it provides methods for managing user data streams and querying API key permissions and restrictions.

# Initialize the client
client = BingXAsyncClient(api_key="your_api_key", api_secret="your_api_secret")

# Generate a listen key for user data stream
listen_key_response = await client.generate_listen_key()
print(listen_key_response)

# Query API key permissions
permissions = await client.query_api_key_permissions()
print(permissions)
Classes:

BingXAsyncClient: The main asynchronous client class for interacting with the BingX API.

Sub-Clients:
  • SpotAPI: Client for spot trading functionality.

  • SwapPerpetualAPI: Client for swap perpetual contracts.

  • StandardFuturesAPI: Client for standard futures trading.

  • SubAccountAPI: Client for managing sub-accounts.

  • AgentAPI: Client for agent-related functionality.

Caching:

The client supports caching through the BaseCache interface, which can be customized to use different caching backends (e.g., in-memory, Redis). Caching is particularly useful for reducing API calls and improving performance.

Note

Ensure that your API key and secret are kept secure. Avoid hardcoding them in your source code and use environment variables or secure vaults instead.

class bingx_py.asyncio.BingXAsyncClient(api_key, api_secret, demo_trading=False, cache=None, default_cache_ttl=300)[source]

Bases: BingXHttpClient

Asynchronous client for interacting with the BingX API.

Parameters:
  • api_key (str)

  • api_secret (str)

  • demo_trading (bool)

  • cache (BaseCache | BaseAsyncCache | None)

  • default_cache_ttl (int)

async delete_listen_key(listen_key)[source]

Delete a listen key.

Parameters:

listen_key (str) – The listen key to delete.

Returns:

None

Return type:

None

async extend_listen_key_validity(listen_key)[source]

Extend the validity period of a listen key.

Parameters:

listen_key (str) – The listen key to extend.

Returns:

None

Return type:

None

async generate_listen_key()[source]

Generate a listen key for user data stream.

Returns:

GenerateListenKeyResponse

Return type:

The response data.

async query_api_key_permissions(recv_window=None)[source]

Query user API key permissions.

Parameters:

recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryApiKeyPermissionsResponse

async query_api_key_restrictions(recv_window=None)[source]

Query user API key restrictions.

Parameters:

recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryApiKeyRestrictionsResponse

Spot Trading API for BingX.

This module provides a comprehensive API for interacting with BingX’s spot trading features. It includes functionalities for account management, market data retrieval, trade execution, and wallet operations.

Classes:
  • SpotAPI: Combines AccountAPI, MarketAPI, TradesAPI, and WalletAPI to provide a unified interface for managing spot trading on BingX.

class bingx_py.asyncio.spot.SpotAPI(client)[source]

Bases: AccountAPI, MarketAPI, TradesAPI, WalletAPI

API for managing spot trading on BingX.

This class combines functionalities from AccountAPI, MarketAPI, TradesAPI, and WalletAPI to provide a unified interface for managing spot trading, including account data, market data, trade execution, and wallet operations.

Parameters:

client (BingXHttpClient)

class bingx_py.asyncio.spot.account.AccountAPI(client)[source]

Bases: object

API for managing account on BingX.

Parameters:

client (BingXHttpClient)

async get_asset_overview(account_type=None, recv_window=None)[source]

Get asset overview.

Parameters:
  • account_type (Optional[AccountType]) – Account type. If left blank, all assets of the account will be checked by default. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

AssetOverviewResponse` The response data.

Return type:

AssetOverviewResponse

async get_main_account_internal_transfer_records(coin, transfer_client_id=None, start_time=None, end_time=None, offset=None, limit=None, recv_window=None)[source]

Get main account internal transfer records.

Parameters:
  • coin (str) – Transfer coin name.

  • transfer_client_id (Optional[str]) – Client’s self-defined internal transfer ID. Defaults to None.

  • start_time (Optional[int]) – Start time. Defaults to None.

  • end_time (Optional[int]) – End time. Defaults to None.

  • offset (Optional[int]) – Starting record number, default is 0. Defaults to None.

  • limit (Optional[int]) – Page size, default is 100, maximum is 1000. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

MainAccountInternalTransferRecordsResponse

async get_transfer_asset_records(transfer_type, tran_id=None, start_time=None, end_time=None, pagination=None, recv_window=None)[source]

Get asset transfer records.

Parameters:
  • transfer_type (TransferDirection) – Transfer type, (query by type or tranId).

  • tran_id (Optional[int]) – Transaction ID, (query by type or tranId). Defaults to None.

  • start_time (Optional[int]) – Starting time. Defaults to None.

  • end_time (Optional[int]) – End time. Defaults to None.

  • pagination (Optional[PaginationParams]) – Pagination parameters. Defaults to None.

  • recv_window (Optional[int]) – Execution window time, cannot be greater than 60000. Defaults to None.

Returns:

The response data.

Return type:

AssetTransferRecordsResponse

async query_assets(recv_window=None)[source]

Query assets.

Parameters:

recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryAssetsResponse

async transfer_asset(transfer_type, asset, amount, recv_window=None)[source]

Perform an asset transfer.

Parameters:
  • transfer_type (TransferDirection) – Transfer type.

  • asset (str) – Coin name, e.g., USDT.

  • amount (float) – Amount to transfer.

  • recv_window (Optional[int]) – Execution window time, cannot be greater than 60000. Defaults to None.

Returns:

The response data.

Return type:

AssetTransferResponse

class bingx_py.asyncio.spot.market.MarketAPI(client)[source]

Bases: object

API for managing market on BingX.

Parameters:

client (BingXHttpClient)

async get_24hr_ticker_price_change_statistics(symbol=None, recv_window=None)[source]

Get 24hr ticker price change statistics.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

Ticker24hrResponse

async get_historical_kline(symbol, interval, start_time=None, end_time=None, limit=None)[source]

Get historical K-line data.

Args: symbol (str): Trading pair, e.g., BTC-USDT. interval (str): Time interval. start_time (Optional[int]): Start time, unit: milliseconds. Defaults to None. end_time (Optional[int]): End time, unit: milliseconds. Defaults to None. limit (Optional[int]): Default value: 500, maximum value: 500. Defaults to None.

Returns: HistoricalKlineResponse: The response data.

Parameters:
  • symbol (str)

  • interval (str)

  • start_time (int | None)

  • end_time (int | None)

  • limit (int | None)

Return type:

HistoricalKlineResponse

async get_kline_data(symbol, interval, start_time=None, end_time=None, limit=None, recv_window=None)[source]

Get Kline/Candlestick data.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • interval (str) – Time interval, refer to field description.

  • start_time (Optional[int]) – Start time, unit: milliseconds. Defaults to None.

  • end_time (Optional[int]) – End time, unit: milliseconds. Defaults to None.

  • limit (Optional[int]) – Default value: 500, maximum value: 1440. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

KlineDataResponse

async get_old_trade_lookup(symbol, limit=None, from_id=None)[source]

Get old trade lookup.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • limit (Optional[int]) – Default 100, maximum 500. Defaults to None.

  • from_id (Optional[str]) – The last recorded trade ID. Defaults to None.

Returns:

The response data.

Return type:

OldTradeLookupResponse

async get_order_book(symbol, limit=None, recv_window=None)[source]

Get order book.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • limit (Optional[int]) – Default 20, max 1000. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

OrderBookResponse

async get_order_book_aggregation(symbol, depth, precision_type)[source]

Get order book aggregation.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC_USDT.

  • depth (int) – Query depth.

  • precision_type (str) – Precision type (step0, step1, step2, step3, step4, step5).

Returns:

The response data.

Return type:

OrderBookAggregationResponse

async get_recent_trades_list(symbol, limit=None, recv_window=None)[source]

Get recent trades list.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • limit (Optional[int]) – Default 100, max 500. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

RecentTradesListResponse

async get_spot_trading_symbols(symbol=None, recv_window=None)[source]

Get spot trading symbols.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SpotTradingSymbolsResponse

async get_symbol_order_book_ticker(symbol)[source]

Get symbol order book ticker.

Args: symbol (str): Trading pair, e.g., BTC_USDT.

Returns: SpotSymbolOrderBookTickerResponse: The response data.

Parameters:

symbol (str)

Return type:

SpotSymbolOrderBookTickerResponse

async get_symbol_price_ticker(symbol)[source]

Get symbol price ticker.

Args: symbol (str): Trading pair, e.g., BTC_USDT.

Returns: SymbolPriceTickerResponse: The response data.

Parameters:

symbol (str)

Return type:

SymbolPriceTickerResponse

class bingx_py.asyncio.spot.trades.TradesAPI(client)[source]

Bases: object

API for managing trades on BingX.

Parameters:

client (BingXHttpClient)

cancel_all_after(cancel_type, time_out)[source]

Cancel all orders after a specified time.

Parameters:
  • cancel_type (CancelAllAfterType) – Request type: ACTIVATE-Activate, CLOSE-Close.

  • time_out (int) – Activate countdown time (seconds), range: 10s-120s.

Returns:

The response data.

Return type:

SpotCancelAllAfterResponse

cancel_all_open_orders(symbol=None, recv_window=None)[source]

Cancel all open orders on a symbol.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. If not filled out, cancel all orders. Defaults to None.

  • recv_window (Optional[float]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SpotCancelAllOpenOrdersResponse

cancel_multiple_orders(symbol, order_ids, process=None, client_order_ids=None, recv_window=None)[source]

Cancel multiple orders.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • order_ids (str) – Order IDs, e.g., orderIds=id1,id2,id3.

  • process (Optional[int]) – 0 or 1, default 0. If process=1, will handle valid orderIds partially, and return invalid orderIds in fails list. If process=0, if one of orderIds invalid, will all fail. Defaults to None.

  • client_order_ids (Optional[str]) – Custom order IDs, e.g., clientOrderIDs=id1,id2,id3. Defaults to None.

  • recv_window (Optional[float]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SpotCancelMultipleOrdersResponse

cancel_oco_order(order_id=None, client_order_id=None, recv_window=None)[source]

Cancel an OCO order list.

Parameters:
  • order_id (Optional[str]) – The order ID of the limit order or the stop-limit order. Defaults to None.

  • client_order_id (Optional[str]) – The User-defined order ID of the limit order or the stop-limit order. Defaults to None.

  • recv_window (Optional[int]) – Request validity window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

CancelOcoOrderResponse

cancel_order(symbol, order_id=None, client_order_id=None, cancel_restrictions=None, recv_window=None)[source]

Cancel an order.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • order_id (Optional[int]) – Order ID. Defaults to None.

  • client_order_id (Optional[str]) – Customized order ID for users, with a limit of characters from 1 to 40. Defaults to None.

  • cancel_restrictions (Optional[CancelRestrictions]) – Cancel orders with specified status: NEW, PENDING, PARTIALLY_FILLED. Defaults to None.

  • recv_window (Optional[float]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SpotCancelOrderResponse

cancel_replace_order(symbol, cancel_replace_mode, side, order_type, stop_price, cancel_order_id=None, cancel_client_order_id=None, cancel_restrictions=None, quantity=None, quote_order_qty=None, price=None, new_client_order_id=None, recv_window=None)[source]

Cancel an existing order and send a new order.

Parameters:
  • symbol (str) – The trading pair, e.g., BTC-USDT.

  • cancel_replace_mode (CancelReplaceMode) – STOP_ON_FAILURE or ALLOW_FAILURE.

  • side (OrderSide) – BUY or SELL.

  • order_type (SpotOrderType) – MARKET/LIMIT/TAKE_STOP_LIMIT/TAKE_STOP_MARKET/TRIGGER_LIMIT/TRIGGER_MARKET.

  • stop_price (str) – Trigger price used for TAKE_STOP_LIMIT, TAKE_STOP_MARKET, TRIGGER_LIMIT, TRIGGER_MARKET order types.

  • cancel_order_id (Optional[int]) – The ID of the order to be canceled. Defaults to None.

  • cancel_client_order_id (Optional[str]) – The user-defined ID of the order to be canceled. Defaults to None.

  • cancel_restrictions (Optional[CancelRestrictions]) – Cancel orders with specified status: NEW, PENDING, PARTIALLY_FILLED. Defaults to None.

  • quantity (Optional[float]) – Order quantity, e.g., 0.1 BTC. Defaults to None.

  • quote_order_qty (Optional[float]) – Order amount, e.g., 100 USDT. Defaults to None.

  • price (Optional[float]) – Order price, e.g., 10000 USDT. Defaults to None.

  • new_client_order_id (Optional[str]) – Custom order ID consisting of letters, numbers, and _. Defaults to None.

  • recv_window (Optional[float]) – Request valid time window in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SpotCancelReplaceOrderResponse

create_oco_order(symbol, side, quantity, limit_price, order_price, trigger_price, list_client_order_id=None, above_client_order_id=None, below_client_order_id=None, recv_window=None)[source]

Create an OCO order.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • side (OrderSide) – BUY or SELL.

  • quantity (float) – Order quantity, e.g., 0.1 BTC.

  • limit_price (float) – Limit order price, e.g., 10000 USDT.

  • order_price (float) – The limit order price set after a stop-limit order is triggered, e.g., 10000 USDT.

  • trigger_price (float) – The trigger price of the stop-limit order, e.g., 10000 USDT.

  • list_client_order_id (Optional[str]) – Custom unique ID for the entire Order List. Defaults to None.

  • above_client_order_id (Optional[str]) – Custom unique ID for the limit order. Defaults to None.

  • below_client_order_id (Optional[str]) – Custom unique ID for the stop-limit order. Defaults to None.

  • recv_window (Optional[float]) – Request validity time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

CreateOcoOrderResponse

current_open_orders(symbol=None, recv_window=None)[source]

Query current open orders.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Query all pending orders when left blank. Defaults to None.

  • recv_window (Optional[float]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

CurrentOpenOrdersResponse

place_multiple_orders(data, sync=None)[source]

Place multiple orders.

Parameters:
  • data (List[PlaceOrderRequest]) – The request array for placing orders, limited to 5 orders.

  • sync (Optional[bool]) – sync=false (default false if not filled in): parallel ordering (but all orders need to have the same symbol/side/type), sync = true (multiple orders are ordered serially, all orders do not require the same symbol/side/type). Defaults to None.

Returns:

The response data.

Return type:

SpotPlaceMultipleOrdersResponse

place_order(symbol, side, order_type, stop_price=None, quantity=None, quote_order_qty=None, price=None, new_client_order_id=None, time_in_force=None, recv_window=None)[source]

Place an order.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • side (OrderSide) – BUY/SELL.

  • order_type (SpotOrderType) – MARKET/LIMIT/TAKE_STOP_LIMIT/TAKE_STOP_MARKET/TRIGGER_LIMIT/TRIGGER_MARKET.

  • stop_price (Optional[str]) – Order trigger price, used for TAKE_STOP_LIMIT, TAKE_STOP_MARKET, TRIGGER_LIMIT, TRIGGER_MARKET type orders. Defaults to None.

  • quantity (Optional[float]) – Original quantity, e.g., 0.1BTC. Defaults to None.

  • quote_order_qty (Optional[float]) – Quote order quantity, e.g., 100USDT. If quantity and quote_order_qty are input at the same time, quantity will be used first. Defaults to None.

  • price (Optional[float]) – Price, e.g., 10000USDT. Defaults to None.

  • new_client_order_id (Optional[str]) – Customized order ID for users, with a limit of characters from 1 to 40. Defaults to None.

  • time_in_force (Optional[TimeInForce]) – Time in force, currently supports PostOnly, GTC, IOC, FOK. Default is GTC if not specified. Defaults to None.

  • recv_window (Optional[float]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SpotPlaceOrderResponse

query_all_open_oco_orders(page_index, page_size, recv_window=None)[source]

Query all open OCO orders.

Parameters:
  • page_index (int) – Page number.

  • page_size (int) – Number of items per page.

  • recv_window (Optional[int]) – Request validity window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryAllOpenOcoOrdersResponse

query_oco_historical_order_list(page_index, page_size, start_time=None, end_time=None, recv_window=None)[source]

Query OCO historical order list.

Parameters:
  • page_index (int) – Page number.

  • page_size (int) – Number of items per page.

  • start_time (Optional[int]) – Start time, timestamp, in milliseconds. Defaults to None.

  • end_time (Optional[int]) – End time, timestamp, in milliseconds. Defaults to None.

  • recv_window (Optional[int]) – Request validity window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryOcoHistoricalOrderListResponse

query_oco_order_list(order_list_id=None, client_order_id=None, recv_window=None)[source]

Query an OCO order list.

Parameters:
  • order_list_id (Optional[str]) – OCO order group ID. Defaults to None.

  • client_order_id (Optional[str]) – User-defined OCO order group ID. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryOcoOrderListResponse

query_order_details(symbol, order_id=None, client_order_id=None, recv_window=None)[source]

Query order details.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • order_id (Optional[int]) – Order ID. Defaults to None.

  • client_order_id (Optional[str]) – Customized order ID for users, with a limit of characters from 1 to 40. Defaults to None.

  • recv_window (Optional[float]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SpotQueryOrderDetailsResponse

query_order_history(symbol=None, order_id=None, start_time=None, end_time=None, page_index=None, page_size=None, status=None, order_type=None, recv_window=None)[source]

Query order history.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • order_id (Optional[int]) – If orderId is set, orders >= orderId. Otherwise, the most recent orders will be returned. Defaults to None.

  • start_time (Optional[int]) – Start timestamp, Unit: ms. Defaults to None.

  • end_time (Optional[int]) – End timestamp, Unit: ms. Defaults to None.

  • page_index (Optional[int]) – Page number, must >0. If not specified, it defaults to 1. Restriction: pageIndex * pageSize <= 10,000. Defaults to None.

  • page_size (Optional[int]) – Page size, must >0. Max 100. If not specified, it defaults to 100. Restriction: pageIndex * pageSize <= 10,000. Defaults to None.

  • status (Optional[OrderStatus]) – Order status: FILLED (fully filled) CANCELED: (canceled) FAILED: (failed). Defaults to None.

  • order_type (Optional[SpotOrderType]) – Order type: MARKET/LIMIT/TAKE_STOP_LIMIT/TAKE_STOP_MARKET/TRIGGER_LIMIT/TRIGGER_MARKET. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryOrderHistoryResponse

query_trading_commission_rate(symbol, recv_window=None)[source]

Query trading commission rate.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • recv_window (Optional[float]) – Request valid time window in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryTradingCommissionRateResponse

query_transaction_details(symbol, order_id, start_time=None, end_time=None, from_id=None, limit=None, recv_window=None)[source]

Query transaction details.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • order_id (int) – Order ID.

  • start_time (Optional[int]) – Start timestamp, unit: ms. Defaults to None.

  • end_time (Optional[int]) – End timestamp, unit: ms. Defaults to None.

  • from_id (Optional[int]) – Starting trade ID. By default, the latest trade will be retrieved. Defaults to None.

  • limit (Optional[int]) – Default 500, maximum 1000. Defaults to None.

  • recv_window (Optional[float]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryTransactionDetailsResponse

class bingx_py.asyncio.spot.wallet.WalletAPI(client)[source]

Bases: object

API for managing wallet on BingX.

Parameters:

client (BingXHttpClient)

get_currency_deposit_withdrawal_data(coin=None, recv_window=None)[source]

Get currency deposit and withdrawal data.

Parameters:
  • coin (Optional[str]) – Coin identification. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

CurrencyDepositWithdrawalDataResponse

get_deposit_records(coin=None, status=None, start_time=None, end_time=None, offset=None, limit=None, recv_window=None)[source]

Get deposit records.

Parameters:
  • coin (Optional[str]) – Coin name. Defaults to None.

  • status (Optional[int]) – Status (0-In progress, 6-Chain uploaded, 1-Completed). Defaults to None.

  • start_time (Optional[int]) – Start time in milliseconds. Defaults to None.

  • end_time (Optional[int]) – End time in milliseconds. Defaults to None.

  • offset (Optional[int]) – Starting record number, default is 0. Defaults to None.

  • limit (Optional[int]) – Page size, default is 1000, maximum is 1000. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

DepositRecordsResponse

get_deposit_risk_control_records()[source]

Get deposit risk control records.

Returns:

The response data.

Return type:

DepositRiskControlRecordsResponse

get_main_account_deposit_address(coin, offset=None, limit=None, recv_window=None)[source]

Get main account deposit address.

Parameters:
  • coin (str) – Name of the coin for transfer.

  • offset (Optional[int]) – Starting record number, default is 0. Defaults to None.

  • limit (Optional[int]) – Page size, default is 100, maximum is 1000. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

MainAccountDepositAddressResponse

get_withdraw_records(withdraw_id=None, coin=None, withdraw_order_id=None, status=None, start_time=None, end_time=None, offset=None, limit=None, recv_window=None)[source]

Get withdraw records.

Parameters:
  • withdraw_id (Optional[str]) – Unique ID of the withdrawal record. Defaults to None.

  • coin (Optional[str]) – Coin name. Defaults to None.

  • withdraw_order_id (Optional[str]) – Custom withdrawal ID. Defaults to None.

  • status (Optional[int]) – Status (4-Under Review, 5-Failed, 6-Completed). Defaults to None.

  • start_time (Optional[int]) – Start time in milliseconds. Defaults to None.

  • end_time (Optional[int]) – End time in milliseconds. Defaults to None.

  • offset (Optional[int]) – Starting record number, default is 0. Defaults to None.

  • limit (Optional[int]) – Page size, default is 1000, maximum is 1000. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

WithdrawRecordsResponse

withdraw(coin, address, amount, wallet_type, network=None, address_tag=None, withdraw_order_id=None, recv_window=None)[source]

Perform a withdrawal.

Parameters:
  • coin (str) – Coin name.

  • address (str) – Withdrawal address.

  • amount (float) – Withdrawal amount.

  • wallet_type (int) – Account type (1=Fund Account, 2=Standard Account, 3=Perpetual Account).

  • network (Optional[str]) – Network name. Defaults to None.

  • address_tag (Optional[str]) – Tag or memo. Defaults to None.

  • withdraw_order_id (Optional[str]) – Custom withdrawal ID. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

WithdrawResponse

Swap Perpetual API for BingX.

This module provides a comprehensive API for interacting with BingX’s swap perpetual trading features. It includes functionalities for account management, market data retrieval, and trade execution.

Classes:
  • SwapPerpetualAPI: Combines AccountAPI, MarketAPI, and TradesAPI to provide a unified interface for managing swap perpetual trading on BingX.

class bingx_py.asyncio.swap.SwapPerpetualAPI(client)[source]

Bases: AccountAPI, MarketAPI, TradesAPI

API for managing swap perpetual on BingX.

This class combines functionalities from AccountAPI, MarketAPI, and TradesAPI to provide a unified interface for managing swap perpetual trading, including account data, market data, and trade execution.

Parameters:

client (BingXHttpClient)

class bingx_py.asyncio.swap.account.AccountAPI(client)[source]

Bases: object

API for managing account on BingX.

Parameters:

client (BingXHttpClient)

async get_account_profit_and_loss_fund_flow(symbol=None, income_type=None, start_time=None, end_time=None, limit=None, recv_window=None)[source]

Get account profit and loss fund flow.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • income_type (Optional[str]) – Income type. Defaults to None.

  • start_time (Optional[int]) – Start time, timestamp in milliseconds. Defaults to None.

  • end_time (Optional[int]) – End time, timestamp in milliseconds. Defaults to None.

  • limit (Optional[int]) – Number of result sets to return. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

GetAccountProfitAndLossFundFlowResponse

async query_account_data(recv_window=None)[source]

Query account data.

Parameters:

recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryAccountDataResponse

async query_position_data(symbol=None, recv_window=None)[source]

Query position data.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryPositionDataResponse

async query_trading_commission_rate(recv_window=None)[source]

Query trading commission rate.

Parameters:

recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SwapQueryTradingCommissionRateResponse

class bingx_py.asyncio.swap.market.MarketAPI(client)[source]

Bases: object

API for managing market on BingX.

Parameters:

client (BingXHttpClient)

async get_funding_rate_history(symbol=None, start_time=None, end_time=None, limit=None, recv_window=None)[source]

Get Funding Rate History.

Parameters:
  • symbol (Optional[str]) – Trading pair, for example: BTC-USDT. Defaults to None.

  • start_time (Optional[int]) – Start time, unit: millisecond. Defaults to None.

  • end_time (Optional[int]) – End time, unit: millisecond. Defaults to None.

  • limit (Optional[int]) – Default: 100, maximum: 1000. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

GetFundingRateHistoryResponse

async get_market_historical_orders(from_id=None, symbol=None, limit=None, recv_window=None)[source]

Query historical transaction orders.

Parameters:
  • from_id (Optional[int]) – From which transaction ID to start returning. By default, it returns the most recent transaction records. Defaults to None.

  • symbol (Optional[str]) – Trading pair, for example: BTC-USDT. Defaults to None.

  • limit (Optional[int]) – The number of returned result sets. Default: 50, maximum: 100. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SwapQueryHistoricalTransactionOrdersResponse

async get_order_book(symbol, limit=None, recv_window=None)[source]

Order Book.

Parameters:
  • symbol (str) – Trading pair, for example: BTC-USDT, please use capital letters.

  • limit (Optional[int]) – Default 20, optional value:[5, 10, 20, 50, 100, 500, 1000]. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SwapOrderBookResponse

async get_recent_trades_list(symbol, limit=None, recv_window=None)[source]

Recent Trades List.

Parameters:
  • symbol (str) – There must be a hyphen/ “-” in the trading pair symbol. eg: BTC-USDT.

  • limit (Optional[int]) – Default: 500, maximum 1000. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SwapRecentTradesListResponse

async get_symbols(symbol=None, recv_window=None)[source]

USDT-M Perp Futures symbols.

Parameters:
  • symbol (Optional[str]) – Trading pair, for example: BTC-USDT. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

UsdtMPerpFuturesSymbolsResponse

async kline_candlestick_data(symbol, interval, start_time=None, end_time=None, limit=None, recv_window=None)[source]

Kline/Candlestick Data.

Parameters:
  • symbol (str) – Trading pair, for example: BTC-USDT.

  • interval (str) – Time interval, refer to field description.

  • start_time (Optional[int]) – Start time, unit: millisecond. Defaults to None.

  • end_time (Optional[int]) – End time, unit: millisecond. Defaults to None.

  • limit (Optional[int]) – Default: 500, maximum: 1440. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

KlineCandlestickDataResponse

async mark_price_and_funding_rate(symbol=None, recv_window=None)[source]

Mark Price and Funding Rate.

Parameters:
  • symbol (Optional[str]) – Trading pair, for example: BTC-USDT. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

MarkPriceAndFundingRateResponse

async mark_price_kline_candlestick_data(symbol, interval, start_time=None, end_time=None, limit=None, recv_window=None)[source]

Mark Price Kline/Candlestick Data.

Parameters:
  • symbol (str) – Trading pair, for example: BTC-USDT.

  • interval (str) – Time interval, refer to field description.

  • start_time (Optional[int]) – Start time, unit: millisecond. Defaults to None.

  • end_time (Optional[int]) – End time, unit: millisecond. Defaults to None.

  • limit (Optional[int]) – Default: 500, maximum: 1440. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

MarkPriceKlineCandlestickDataResponse

async open_interest_statistics(symbol, recv_window=None)[source]

Open Interest Statistics.

Parameters:
  • symbol (str) – Trading pair, for example: BTC-USDT.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

OpenInterestStatisticsResponse

async symbol_order_book_ticker(symbol, recv_window=None)[source]

Symbol Order Book Ticker.

Parameters:
  • symbol (str) – Trading pair, for example: BTC-USDT.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SymbolOrderBookTickerResponse

async symbol_price_ticker(symbol=None, recv_window=None)[source]

Symbol Price Ticker.

Parameters:
  • symbol (Optional[str]) – Trading pair, for example: BTC-USDT. If no transaction pair parameters are sent, all transaction pair information will be returned. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SwapSymbolPriceTickerResponse

async ticker_price_change_statistics(symbol=None, recv_window=None)[source]

24hr Ticker Price Change Statistics.

Parameters:
  • symbol (Optional[str]) – Trading pair, for example: BTC-USDT. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

TickerPriceChangeStatisticsResponse

class bingx_py.asyncio.swap.trades.TradesAPI(client)[source]

Bases: object

API for managing trades on BingX.

This class provides methods to place, cancel, and query orders, manage positions, and interact with various trading features such as leverage, margin, and TWAP orders.

Parameters:

client (BingXHttpClient)

async apply_vst(recv_window=None)[source]

Apply VST.

Parameters:

recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

ApplyVstResponse

async batch_cancel_replace_orders(batch_orders, recv_window=None)[source]

Cancel and replace multiple orders in batches.

Parameters:
  • batch_orders (List[Dict[str, Any]]) – List of orders to cancel and replace.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

BatchCancelReplaceOrdersResponse

async cancel_all_after(state_type, time_out)[source]

Cancel all orders after a specified time.

Parameters:
  • state_type (str) – ACTIVATE or CLOSE.

  • time_out (int) – Timeout in seconds (10-120).

Returns:

The response data.

Return type:

CancelAllAfterResponse

async cancel_all_open_orders(symbol=None, order_type=None, recv_window=None)[source]

Cancel all open orders.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • order_type (Optional[OrderType]) – Order type. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window (milliseconds). Defaults to None.

Returns:

The response data.

Return type:

CancelAllOpenOrdersResponse

async cancel_multiple_orders(symbol, order_id_list=None, client_order_id_list=None, recv_window=None)[source]

Cancel multiple orders.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • order_id_list (Optional[List[int]]) – List of order IDs. Defaults to None.

  • client_order_id_list (Optional[List[str]]) – List of customized order IDs. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window (milliseconds). Defaults to None.

Returns:

The response data.

Return type:

CancelMultipleOrdersResponse

async cancel_order(symbol, order_id=None, client_order_id=None, recv_window=None)[source]

Cancel an order.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • order_id (Optional[int]) – Order ID. Defaults to None.

  • client_order_id (Optional[str]) – Customized order ID. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window (milliseconds). Defaults to None.

Returns:

The response data.

Return type:

CancelOrderResponse

async cancel_replace_order(request)[source]

Cancel an existing order and place a new one.

Parameters:

request (CancelReplaceOrderRequest) – The request object.

Returns:

The response data.

Return type:

CancelReplaceOrderResponse

async cancel_twap_order(main_order_id, recv_window=None)[source]

Cancel a TWAP order.

Parameters:
  • main_order_id (str) – TWAP order number.

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

CancelTwapOrderResponse

async change_margin_type(symbol, margin_type, recv_window=None)[source]

Change margin type for a trading pair.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT. There must be a hyphen (“-”) in the trading pair symbol.

  • margin_type (MarginType) – Margin mode (ISOLATED or CROSSED).

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

ChangeMarginTypeResponse

async close_all_positions(symbol=None, recv_window=None)[source]

Close all positions.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

CloseAllPositionsResponse

async close_position_by_id(position_id, recv_window=None)[source]

Close a position by its ID.

Parameters:
  • position_id (str) – The position ID to close.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

ClosePositionResponse

async get_current_all_open_orders(symbol=None, order_type=None, recv_window=None)[source]

Get current all open orders.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • order_type (Optional[OrderType]) – Order type. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window (milliseconds). Defaults to None.

Returns:

The response data.

Return type:

CurrentAllOpenOrdersResponse

async get_trading_historical_orders(trading_unit, start_ts, end_ts, order_id=None, currency=None, recv_window=None)[source]

Query historical transaction orders.

Parameters:
  • order_id (Optional[int]) – Order ID. Defaults to None.

  • currency (Optional[str]) – USDC or USDT. Defaults to None.

  • trading_unit (str) – Trading unit (COIN or CONT).

  • start_ts (int) – Starting timestamp in milliseconds.

  • end_ts (int) – End timestamp in milliseconds.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryHistoricalTransactionOrdersResponse

async hedge_mode_auto_add_margin(symbol, position_id, function_switch, amount=None, recv_window=None)[source]

Enable or disable automatic margin addition for a hedge mode position.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT, please use uppercase letters.

  • position_id (int) – Position ID.

  • function_switch (str) – Whether to enable the automatic margin addition feature, true: enable, false: disable.

  • amount (Optional[str]) – Amount of margin to be added, in USDT. Must be specified when enabling the feature. Defaults to None.

  • recv_window (Optional[int]) – Request validity window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

HedgeModeAutoAddMarginResponse

async isolated_margin_change_history(symbol, position_id, start_time, end_time, page_index, page_size, recv_window=None)[source]

Query isolated margin change history.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • position_id (str) – Position ID.

  • start_time (int) – Start timestamp in milliseconds.

  • end_time (int) – End timestamp in milliseconds.

  • page_index (int) – Page number, must be greater than 0.

  • page_size (int) – Page size, must be greater than 0.

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

IsolatedMarginChangeHistoryResponse

async modify_isolated_position_margin(symbol, amount, direction_type, position_side=None, position_id=None, recv_window=None)[source]

Modify isolated position margin.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • amount (float) – Margin funds.

  • direction_type (int) – Adjustment direction (1: increase, 2: decrease).

  • position_side (Optional[str]) – Position direction (LONG or SHORT). Defaults to None.

  • position_id (Optional[int]) – Position ID. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

ModifyIsolatedPositionMarginResponse

async one_click_reverse_position(reverse_type, symbol, trigger_price=None, working_type=None, recv_window=None)[source]

Perform a one-click reverse position.

Parameters:
  • reverse_type (str) – Reverse type, Reverse: immediate reverse, TriggerReverse: planned reverse.

  • symbol (str) – Trading pair, e.g.: BTC-USDT.

  • trigger_price (Optional[str]) – Trigger price, required for planned reverse. Defaults to None.

  • working_type (Optional[str]) – TriggerPrice price type: MARK_PRICE, CONTRACT_PRICE, INDEX_PRICE, CONTRACT_PRICE. Required for planned reverse. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

OneClickReversePositionResponse

async place_multiple_orders(batch_orders, recv_window=None)[source]

Place multiple orders.

Parameters:
  • batch_orders (List[OrderRequest]) – List of orders to place, supporting up to 5 orders.

  • recv_window (Optional[int]) – Request valid time window value in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

PlaceMultipleOrdersResponse

async place_order(request, recv_window=None)[source]

Place an order.

Parameters:
  • request (OrderRequest) – Order request model.

  • recv_window (Optional[int]) – Request valid time window (milliseconds). Defaults to None.

Returns:

The response data.

Return type:

PlaceOrderResponse

async place_order_in_demo_trading(request, recv_window=None)[source]

Place an order in demo trading.

Parameters:
  • request (OrderRequest) – Order request model.

  • recv_window (Optional[int]) – Request valid time window (milliseconds). Defaults to None.

Returns:

The response data.

Return type:

PlaceOrderInDemoTradingResponse

async place_twap_order(symbol, side, position_side, price_type, price_variance, trigger_price, interval, amount_per_order, total_amount, recv_window=None)[source]

Place a TWAP order.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • side (str) – Buying and selling direction (SELL, BUY).

  • position_side (str) – LONG or SHORT.

  • price_type (str) – Price limit type (constant or percentage).

  • price_variance (str) – Price difference or slippage ratio.

  • trigger_price (str) – Trigger price.

  • interval (int) – Time interval for order placing (5-120s).

  • amount_per_order (str) – Quantity of a single order.

  • total_amount (str) – Total trading volume.

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

PlaceTwapOrderResponse

async position_and_maintenance_margin_ratio(symbol, recv_window=None)[source]

Query position and maintenance margin ratio.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

PositionAndMaintenanceMarginRatioResponse

async query_all_orders(symbol=None, order_id=None, start_time=None, end_time=None, limit=500, recv_window=None)[source]

Query all orders.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • order_id (Optional[int]) – Order ID. Defaults to None.

  • start_time (Optional[int]) – Start time in milliseconds. Defaults to None.

  • end_time (Optional[int]) – End time in milliseconds. Defaults to None.

  • limit (int) – Number of orders to return. Defaults to 500.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryAllOrdersResponse

async query_historical_transaction_details(symbol, start_ts, end_ts, currency=None, order_id=None, last_fill_id=None, page_index=None, page_size=None, recv_window=None)[source]

Query historical transaction details.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • start_ts (int) – Starting timestamp in milliseconds.

  • end_ts (int) – End timestamp in milliseconds.

  • currency (Optional[str]) – USDC or USDT. Defaults to None.

  • order_id (Optional[int]) – Order ID. Defaults to None.

  • last_fill_id (Optional[int]) – The last tradeId of the last query. Defaults to None.

  • page_index (Optional[int]) – Page number. Defaults to None.

  • page_size (Optional[int]) – Page size. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryHistoricalTransactionDetailsResponse

async query_leverage_and_available_positions(symbol, recv_window=None)[source]

Query leverage and available positions for a trading pair.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT. There must be a hyphen (“-”) in the trading pair symbol.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryLeverageAndAvailablePositionsResponse

async query_margin_type(symbol, recv_window=None)[source]

Query margin type for a trading pair.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT. There must be a hyphen (“-”) in the trading pair symbol.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryMarginTypeResponse

async query_multi_assets_margin(recv_window=None)[source]

Query the margin details for multi-assets mode.

Parameters:

recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryMultiAssetsMarginResponse

async query_multi_assets_mode(recv_window=None)[source]

Query the current multi-assets mode.

Parameters:

recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryMultiAssetsModeResponse

async query_multi_assets_rules(recv_window=None)[source]

Query the rules for multi-assets mode.

Parameters:

recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryMultiAssetsRulesResponse

async query_order_details(symbol, order_id=None, client_order_id=None, recv_window=None)[source]

Query order details.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT. There must be a hyphen (“-”) in the trading pair symbol.

  • order_id (Optional[int]) – Order ID. Defaults to None.

  • client_order_id (Optional[str]) – Customized order ID for users, with a limit of characters from 1 to 40. The system will convert this field to lowercase. Different orders cannot use the same clientOrderId. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryOrderDetailsResponse

async query_order_history(symbol=None, currency=None, order_id=None, start_time=None, end_time=None, limit=500, recv_window=None)[source]

Query order history.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • currency (Optional[str]) – USDC or USDT. Defaults to None.

  • order_id (Optional[int]) – Order ID. Defaults to None.

  • start_time (Optional[int]) – Start time, unit: millisecond. Defaults to None.

  • end_time (Optional[int]) – End time, unit: millisecond. Defaults to None.

  • limit (int) – Number of result sets to return. Defaults to 500.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SwapQueryOrderHistoryResponse

async query_pending_order_status(symbol, order_id=None, client_order_id=None, recv_window=None)[source]

Query pending order status.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT.

  • order_id (Optional[int]) – Order ID. Defaults to None.

  • client_order_id (Optional[str]) – Customized order ID. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window (milliseconds). Defaults to None.

Returns:

The response data.

Return type:

QueryPendingOrderStatusResponse

async query_position_history(start_ts, end_ts, symbol=None, currency=None, position_id=None, page_index=None, page_size=None, recv_window=None)[source]

Query position history.

Parameters:
  • start_ts (int) – Start timestamp in milliseconds.

  • end_ts (int) – End timestamp in milliseconds.

  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • currency (Optional[str]) – USDC or USDT. Defaults to None.

  • position_id (Optional[int]) – Position ID. Defaults to None.

  • page_index (Optional[int]) – Page number. Defaults to None.

  • page_size (Optional[int]) – Page size. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryPositionHistoryResponse

async query_position_mode(recv_window=None)[source]

Query position mode.

Parameters:

recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryPositionModeResponse

async query_twap_entrusted_order(symbol=None, recv_window=None)[source]

Query TWAP entrusted orders.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryTwapEntrustedOrderResponse

async query_twap_historical_orders(page_index, page_size, start_time, end_time, symbol=None, recv_window=None)[source]

Query TWAP historical orders.

Parameters:
  • page_index (int) – Page number, must be greater than 0.

  • page_size (int) – Page size, must be greater than 0.

  • start_time (int) – Start timestamp in milliseconds.

  • end_time (int) – End timestamp in milliseconds.

  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryTwapHistoricalOrdersResponse

async query_twap_order_details(main_order_id, recv_window=None)[source]

Query TWAP order details.

Parameters:
  • main_order_id (str) – TWAP order number.

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryTwapOrderDetailsResponse

async set_leverage(symbol, side, leverage, recv_window=None)[source]

Set leverage for a trading pair.

Parameters:
  • symbol (str) – Trading pair, e.g., BTC-USDT. There must be a hyphen (“-”) in the trading pair symbol.

  • side (str) – Leverage for long or short positions. In the Hedge mode, LONG for long positions, SHORT for short positions. In the One-way mode, only supports BOTH.

  • leverage (int) – Leverage value.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SetLeverageResponse

async set_position_mode(dual_side_position, recv_window=None)[source]

Set position mode.

Parameters:
  • dual_side_position (bool) – “true” for dual position mode, “false” for single position mode.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SetPositionModeResponse

async switch_multi_assets_mode(asset_mode, recv_window=None)[source]

Switch multi-assets mode.

Parameters:
  • asset_mode (str) – Multi-assets mode (singleAssetMode or multiAssetsMode).

  • recv_window (Optional[int]) – Request valid time window, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SwitchMultiAssetsModeResponse

async test_order(request, recv_window=None)[source]

Test placing an order.

Parameters:
  • request (OrderRequest) – Order request model.

  • recv_window (Optional[int]) – Request valid time window (milliseconds). Defaults to None.

Returns:

The response data.

Return type:

TestOrderResponse

async users_force_orders(symbol=None, currency=None, auto_close_type=None, start_time=None, end_time=None, limit=None, recv_window=None)[source]

Query user’s force orders.

Parameters:
  • symbol (Optional[str]) – Trading pair, e.g., BTC-USDT. Defaults to None.

  • currency (Optional[str]) – USDC or USDT. Defaults to None.

  • auto_close_type (Optional[str]) – “LIQUIDATION” or “ADL”. Defaults to None.

  • start_time (Optional[int]) – Start time, unit: millisecond. Defaults to None.

  • end_time (Optional[int]) – End time, unit: millisecond. Defaults to None.

  • limit (Optional[int]) – The number of returned result sets. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

UsersForceOrdersResponse

class bingx_py.asyncio.agent.AgentAPI(client)[source]

Bases: object

API for managing agent on BingX.

This class provides methods to manage agent, including query agent user information, query partner information, query invited users, query deposit details of invited users, query api transaction commission, and query daily commission.

Parameters:

client (BingXHttpClient)

async daily_commission_query(start_time, end_time, pagination, uid=None, recv_window=None)[source]

Daily Commission Query (invitation relationship).

Parameters:
  • start_time (str) – Start timestamp, in days, with a maximum query window of 30 days and a sliding range of the last 365 days.

  • end_time (str) – End timestamp, in days, with a maximum query window of 30 days and a sliding range of the last 365 days.

  • pagination (PaginationParams) – Page number for pagination, must be greater than 0 and page size for pagination, must be greater than 0 with a maximum value of 100.

  • uid (Optional[int]) – Invited User UID. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Default is 5 seconds if not provided. Defaults to None.

Returns:

The response data.

Return type:

DailyCommissionQueryResponse

async query_agent_user_information(uid)[source]

Query agent user information.

Parameters:

uid (int) – Invited User UID.

Returns:

The response data.

Return type:

QueryAgentUserInformationResponse

async query_api_transaction_commission_non_invitation(commission_biz_type, start_time, end_time, pagination, uid=None, recv_window=None)[source]

Query API transaction commission (non-invitation relationship).

Parameters:
  • commission_biz_type (CommissionBizType) – Commission business type.

  • start_time (str) – Start timestamp (days), only supports querying data after December 1, 2023.

  • end_time (str) – End timestamp (days), only supports querying data after December 1, 2023.

  • pagination (PaginationParams) – Page number for pagination, must be greater than 0 and page size for pagination, must be greater than 0 with a maximum value of 100.

  • uid (Optional[int]) – UID of the trading user (non-invitation relationship user). Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, unit: milliseconds. If not filled, the default is 5 seconds. Defaults to None.

Returns:

The response data.

Return type:

QueryApiTransactionCommissionNonInvitationResponse

async query_deposit_details_of_invited_users(uid, biz_type, start_time, end_time, pagination, recv_window=None)[source]

Query the deposit details of invited users.

Parameters:
  • uid (int) – Inviting user UID, must be the parent user UID.

  • biz_type (int) – 1: Deposit.

  • start_time (int) – Start timestamp (days), only supports querying the last 90 days of data.

  • end_time (int) – End timestamp (days). Only the last 90 days of data can be queried.

  • pagination (PaginationParams) – Page number and size for pagination.

  • recv_window (Optional[int]) – Request valid time window value, unit: milliseconds. If not filled, the default is 5 seconds. Defaults to None.

Returns:

The response data.

Return type:

QueryDepositDetailsOfInvitedUsersResponse

async query_invited_users(pagination, start_time=None, end_time=None, last_uid=None, recv_window=None)[source]

Query Invited Users.

Parameters:
  • pagination (PaginationParams) – Page number and size for pagination.

  • start_time (Optional[int]) – Start timestamp (millisecond). The maximum query window is 30 days.

  • data (If querying for all)

  • None. (Defaults to)

  • end_time (Optional[int]) – End timestamp (millisecond). The maximum query window is 30 days.

  • data

  • None.

  • last_uid (Optional[int]) – User UID, must be transmitted when the queried data exceeds 10,000.

  • passed (The first request does not need to be)

  • afterwards. (and the last uid of the current page is passed each time)

  • None.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Default is 5 seconds if not provided.

  • None.

Returns:

The response data.

Return type:

QueryInvitedUsersResponse

async query_partner_information(start_time, end_time, pagination, uid=None, recv_window=None)[source]

Query partner information.

Parameters:
  • start_time (int) – Start time, unit: day, only supports querying the latest 3 months.

  • end_time (int) – End time, unit: day, only supports querying the latest 3 months.

  • pagination (PaginationParams) – Page number for pagination, must be greater than 0 and page size for pagination, must be greater than 0 with a maximum value of 200.

  • uid (Optional[int]) – Partner UID. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, unit: milliseconds. If not filled, the default is 5 seconds. Defaults to None.

Returns:

The response data.

Return type:

QueryPartnerInformationResponse

class bingx_py.asyncio.standard.StandardFuturesAPI(client)[source]

Bases: object

API for managing standard futures on BingX.

This class provides methods to interact with standard futures features such as querying positions, placing orders, and more.

Parameters:

client (BingXHttpClient)

async get_all_positions()[source]

Get all positions.

Returns:

List of position data.

Return type:

PositionResponse

async get_historical_orders(symbol, order_id=None, start_time=None, end_time=None, limit=None, recv_window=None)[source]

Get historical orders.

Parameters:
  • symbol (str) – Currency pair, the format is similar: BTC-USDT, must pass.

  • order_id (Optional[int]) – Order ID, optional. Defaults to None.

  • start_time (Optional[int]) – Start time, optional. Defaults to None.

  • end_time (Optional[int]) – End time, optional. Defaults to None.

  • limit (Optional[int]) – Quantity, optional. Defaults to None.

  • recv_window (Optional[int]) – Timestamp of initiating the request, Unit: milliseconds. Defaults to None.

Returns:

List of historical order data.

Return type:

HistoricalOrderResponse

async query_standard_contract_balance()[source]

Query standard contract balance.

Returns:

The response data.

Return type:

StandardContractBalanceResponse

class bingx_py.asyncio.sub_account.SubAccountAPI(client)[source]

Bases: object

API for managing sub-accounts on BingX.

This class provides methods to create, manage, and query sub-accounts, including creating API keys, managing deposits, and transferring assets between sub-accounts and the main account.

Parameters:

client (BingXHttpClient)

async authorize_sub_account_internal_transfer(sub_uids, transferable, recv_window=None)[source]

Authorize sub-account internal transfers.

Parameters:
  • sub_uids (str) – User uid list, comma separated.

  • transferable (bool) – Is it allowed? True allows, false prohibits.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

AuthorizeSubAccountInternalTransferResponse

async batch_query_sub_account_asset_overview(page_index, page_size, sub_uid=None, account_type=None, recv_window=None)[source]

Batch query of sub-account asset overview.

Parameters:
  • page_index (int) – Page number, must be greater than 0.

  • page_size (int) – Paging size, must be greater than 0, maximum 10.

  • sub_uid (Optional[int]) – Sub-account UID. Defaults to None.

  • account_type (Optional[str]) – Account type. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

BatchQuerySubAccountAssetOverviewResponse

async create_sub_account(sub_account_string, note=None, recv_window=None)[source]

Create a new sub-account.

Parameters:
  • sub_account_string (str) – Sub account username (Starting with a letter, containing a number, and longer than 6 characters).

  • note (Optional[str]) – Notes. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

CreateSubAccountResponse

async create_sub_account_api_key(sub_uid, note, permissions, ip_addresses=None, recv_window=None)[source]

Create an API Key for a sub-account.

Parameters:
  • sub_uid (int) – Sub account uid.

  • note (str) – Notes.

  • permissions (List[str]) – Permissions, e.g., [“1”, “2”, “3”].

  • ip_addresses (Optional[List[str]]) – IP whitelist. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

CreateSubAccountApiKeyResponse

async create_sub_account_deposit_address(coin, sub_uid, network, wallet_type, recv_window=None)[source]

Create a deposit address for a sub-account.

Parameters:
  • coin (str) – Currency name.

  • sub_uid (int) – Sub-account UID.

  • network (str) – Network name.

  • wallet_type (int) – Account type (1=Fund Account, 2=Standard Futures Account, 3=USDⓢ-M Perp).

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

CreateSubAccountDepositAddressResponse

async delete_sub_account_api_key(sub_uid, api_key, recv_window=None)[source]

Delete the API Key of a sub-account.

Parameters:
  • sub_uid (int) – Sub account uid.

  • api_key (str) – API Key.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

DeleteSubAccountApiKeyResponse

async freeze_unfreeze_sub_account(sub_uid, freeze, recv_window=None)[source]

Freeze or unfreeze a sub-account.

Parameters:
  • sub_uid (int) – Sub account uid.

  • freeze (bool) – Whether to freeze the account.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

FreezeUnfreezeSubAccountResponse

async get_sub_account_deposit_address(coin, sub_uid, offset=None, limit=None, recv_window=None)[source]

Get the deposit address for a sub-account.

Parameters:
  • coin (str) – Name of the transfer coin.

  • sub_uid (int) – Sub-account UID.

  • offset (Optional[int]) – Starting record number, default is 0. Defaults to None.

  • limit (Optional[int]) – Page size, default is 100, maximum is 1000. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

GetSubAccountDepositAddressResponse

async get_sub_account_deposit_records(coin=None, sub_uid=None, status=None, start_time=None, end_time=None, offset=None, limit=None, recv_window=None)[source]

Get deposit records for sub-accounts.

Parameters:
  • coin (Optional[str]) – Transfer currency name. Defaults to None.

  • sub_uid (Optional[int]) – Sub-account UID. Defaults to None.

  • status (Optional[int]) – Status (0-In progress, 6-Chain uploaded, 1-Completed). Defaults to None.

  • start_time (Optional[int]) – Start time. Defaults to None.

  • end_time (Optional[int]) – End time. Defaults to None.

  • offset (Optional[int]) – Starting record number, default is 0. Defaults to None.

  • limit (Optional[int]) – Page size, default is 100, maximum is 1000. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

GetSubAccountDepositRecordsResponse

async get_sub_account_list(page, limit, sub_uid=None, sub_account_string=None, is_freeze=None, recv_window=None)[source]

Get the list of sub-accounts.

Parameters:
  • page (int) – Page number, starting with 1.

  • limit (int) – Paging size, maximum 1000.

  • sub_uid (Optional[int]) – Sub account uid. Defaults to None.

  • sub_account_string (Optional[str]) – Sub account username. Defaults to None.

  • is_freeze (Optional[bool]) – Freeze or not. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

GetSubAccountListResponse

async query_account_uid(recv_window=None)[source]

Query the account UID.

Parameters:

recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QueryAccountUidResponse

async query_sub_account_api_key(uid, api_key=None, recv_window=None)[source]

Query the API Key of a sub-account.

Parameters:
  • uid (int) – User uid.

  • api_key (Optional[str]) – API Key. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QuerySubAccountApiKeyResponse

async query_sub_account_internal_transfer_records(coin, transfer_client_id=None, start_time=None, end_time=None, offset=None, limit=None, recv_window=None)[source]

Query internal transfer records for sub-accounts.

Parameters:
  • coin (str) – Transfer currency name.

  • transfer_client_id (Optional[str]) – Client’s self-defined internal transfer ID. Defaults to None.

  • start_time (Optional[int]) – Start time. Defaults to None.

  • end_time (Optional[int]) – End time. Defaults to None.

  • offset (Optional[int]) – Starting record number, default is 0. Defaults to None.

  • limit (Optional[int]) – Page size, default is 100, maximum is 1000. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QuerySubAccountInternalTransferRecordsResponse

async query_sub_account_spot_assets(sub_uid, recv_window=None)[source]

Query the spot assets of a sub-account.

Parameters:
  • sub_uid (int) – Sub account uid.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

QuerySubAccountSpotAssetsResponse

async query_sub_account_transfer_history(uid, transfer_type=None, tran_id=None, start_time=None, end_time=None, page_id=None, paging_size=None, recv_window=None)[source]

Query transfer history for sub-accounts (for master account operations only).

Parameters:
  • uid (int) – UID to query.

  • transfer_type (Optional[str]) – Transfer type. Defaults to None.

  • tran_id (Optional[str]) – Transfer ID. Defaults to None.

  • start_time (Optional[int]) – Start time. Defaults to None.

  • end_time (Optional[int]) – End time. Defaults to None.

  • page_id (Optional[int]) – Current page, default is 1. Defaults to None.

  • paging_size (Optional[int]) – Page size, default is 10, cannot exceed 100. Defaults to None.

  • recv_window (Optional[int]) – Execution window time, cannot exceed 60000. Defaults to None.

Returns:

The response data.

Return type:

QuerySubAccountTransferHistoryResponse

async query_transferable_amount(from_uid, from_account_type, to_uid, to_account_type, recv_window=None)[source]

Query the transferable amount of funds in the parent-child account (only for parent account operations).

Parameters:
  • from_uid (int) – Sender UID.

  • from_account_type (int) – Sender account type (1=Fund account, 2=Contract account, 3=Perpetual USD-based account).

  • to_uid (int) – Receiver UID.

  • to_account_type (int) – Receiver account type (1=Fund account, 2=Contract account, 3=Perpetual USD-based account).

  • recv_window (Optional[int]) – Execution window time, cannot exceed 60000. Defaults to None.

Returns:

The response data.

Return type:

QueryTransferableAmountResponse

async reset_sub_account_api_key(sub_uid, api_key, note, permissions, ip_addresses=None, recv_window=None)[source]

Reset the API Key of a sub-account.

Parameters:
  • sub_uid (int) – Sub account uid.

  • api_key (str) – API Key.

  • note (str) – Notes.

  • permissions (List[int]) – Permissions, e.g., [1, 2, 3].

  • ip_addresses (Optional[List[str]]) – IP whitelist. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window value, Unit: milliseconds. Defaults to None.

Returns:

The response data.

Return type:

ResetSubAccountApiKeyResponse

async sub_account_asset_transfer(asset_name, transfer_amount, from_uid, from_type, from_account_type, to_uid, to_type, to_account_type, remark, recv_window=None)[source]

Perform asset transfer between sub-accounts (for master account operations only).

Parameters:
  • asset_name (str) – Name of the asset, e.g., USDT.

  • transfer_amount (float) – Transfer amount.

  • from_uid (int) – Sender UID.

  • from_type (int) – Sender sub/master account type (1=Master account, 2=Sub-account).

  • from_account_type (int) – Sender account type (1=Fund account, 2=Contract account, 3=Perpetual USD-based account).

  • to_uid (int) – Receiver UID.

  • to_type (int) – Receiver sub/master account type (1=Master account, 2=Sub-account).

  • to_account_type (int) – Receiver account type (1=Fund account, 2=Contract account, 3=Perpetual USD-based account).

  • remark (str) – Transfer remark.

  • recv_window (Optional[int]) – Execution window time, cannot exceed 60000. Defaults to None.

Returns:

The response data.

Return type:

SubAccountAssetTransferResponse

async sub_account_internal_transfer(coin, user_account_type, user_account, amount, wallet_type, calling_code=None, recv_window=None)[source]

Perform an internal transfer within a sub-account.

Parameters:
  • coin (str) – Transfer currency name.

  • user_account_type (int) – User account type (1=UID, 2=phone number, 3=email).

  • user_account (str) – User account (UID, phone, email).

  • amount (float) – Transfer amount.

  • wallet_type (int) – Account type (1=Fund Account, 2=Standard Futures Account, 3=Perpetual Futures Account).

  • calling_code (Optional[str]) – Area code for telephone, required when userAccountType=2. Defaults to None.

  • recv_window (Optional[int]) – Request valid time window, in milliseconds. Defaults to None.

Returns:

The response data.

Return type:

SubAccountInternalTransferResponse