Skip to content

Trade Service

Igor Sazonov edited this page Mar 9, 2026 · 1 revision

The TradeService is the heart of your trading application, providing the full suite of functionalities required to execute and manage your trading operations on the BingX platform. This service allows you to create, cancel, and query orders for both spot and futures markets.

Accessing the Service

To begin executing trades, you must first access the TradeService through your BingXClient instance:

from bingx import BingXClient

client = BingXClient(api_key="YOUR_API_KEY", api_secret="YOUR_API_SECRET")
trade_service = client.trade()

Core Functionalities

The TradeService is organized into several logical groups of methods, each designed to handle a specific aspect of the trading lifecycle.

Order Management

These methods provide the tools to create and manage your orders.

Method Description
create_order(params) Creates a new order with the specified parameters.
create_test_order(params) Allows you to test order creation without actually executing the trade.
create_batch_orders(orders) Creates multiple orders in a single API call.
cancel_order(symbol, order_id) Cancels a specific order.
cancel_all_orders(symbol) Cancels all open orders for a given symbol.

Order and Trade History

These methods allow you to query your historical trading activity.

Method Description
get_order(symbol, order_id) Retrieves the details of a specific order.
get_open_orders(symbol, limit) Retrieves a list of all your open orders.
get_order_history(symbol, limit) Retrieves your historical order data.
get_user_trades(symbol, limit) Retrieves your historical trade data.

Quick Methods for Common Trades

For convenience, the TradeService provides a set of "quick" methods for executing common trade types.

Method Description
spot_market_buy(symbol, quantity) Executes a market buy order on the spot market.
spot_market_sell(symbol, quantity) Executes a market sell order on the spot market.
spot_limit_buy(symbol, quantity, price) Places a limit buy order on the spot market.
spot_limit_sell(symbol, quantity, price) Places a limit sell order on the spot market.
futures_long_market(symbol, margin, leverage) Executes a long market order on the futures market.
futures_short_market(symbol, margin, leverage) Executes a short market order on the futures market.

Position and Margin Configuration

These methods allow you to manage your position modes and margin types.

Method Description
get_position_mode() Retrieves your current position mode (HEDGE_MODE or ONE_WAY_MODE).
set_position_mode(dual_side_position) Sets your position mode.
close_all_positions(symbol) Closes all open positions for a given symbol.
get_margin_type(symbol) Retrieves the margin type for a symbol (ISOLATED or CROSSED).
change_margin_type(symbol, margin_type) Changes the margin type for a symbol.

Clone this wiki locally