-
Notifications
You must be signed in to change notification settings - Fork 0
Trade Service
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.
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()The TradeService is organized into several logical groups of methods, each designed to handle a specific aspect of the trading lifecycle.
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. |
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. |
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. |
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. |