0
# Futures Trading
1
2
Complete futures trading functionality for both USD-margined and coin-margined futures. Includes position management, leverage control, funding rate information, and specialized futures order types.
3
4
## Capabilities
5
6
### Futures Exchange Information
7
8
Get trading rules and symbol information for futures markets.
9
10
```python { .api }
11
def futures_get_exchange_info(self): ...
12
def futures_coin_get_exchange_info(self): ...
13
```
14
15
#### Usage Examples
16
17
```python
18
# Get USD-M futures exchange info
19
futures_info = client.futures_get_exchange_info()
20
21
# Find symbols and their trading rules
22
for symbol in futures_info['symbols']:
23
if symbol['symbol'] == 'BTCUSDT':
24
print(f"Status: {symbol['status']}")
25
print(f"Base asset: {symbol['baseAsset']}")
26
print(f"Quote asset: {symbol['quoteAsset']}")
27
print(f"Filters: {symbol['filters']}")
28
29
# Get coin-margined futures exchange info
30
coin_futures_info = client.futures_coin_get_exchange_info()
31
```
32
33
### Futures Market Data
34
35
Access futures-specific market data including funding rates and open interest.
36
37
```python { .api }
38
def futures_get_all_tickers(self): ...
39
def futures_get_symbol_ticker(self, **params): ...
40
def futures_get_orderbook_ticker(self, **params): ...
41
def futures_get_order_book(self, **params): ...
42
def futures_get_klines(self, **params): ...
43
def futures_funding_rate(self, **params): ...
44
def futures_top_longshort_account_ratio(self, **params): ...
45
def futures_top_longshort_position_ratio(self, **params): ...
46
def futures_global_longshort_ratio(self, **params): ...
47
```
48
49
#### Usage Examples
50
51
```python
52
# Get all futures tickers
53
futures_tickers = client.futures_get_all_tickers()
54
btc_ticker = next(t for t in futures_tickers if t['symbol'] == 'BTCUSDT')
55
print(f"BTC Futures price: {btc_ticker['price']}")
56
57
# Get funding rate information
58
funding_rate = client.futures_funding_rate(symbol='BTCUSDT')
59
print(f"Current funding rate: {funding_rate['fundingRate']}")
60
print(f"Next funding time: {funding_rate['fundingTime']}")
61
62
# Get long/short ratio data
63
longshort_ratio = client.futures_top_longshort_account_ratio(
64
symbol='BTCUSDT',
65
period='5m',
66
limit=30
67
)
68
69
for ratio in longshort_ratio:
70
print(f"Time: {ratio['timestamp']}")
71
print(f"Long account ratio: {ratio['longAccount']}")
72
print(f"Short account ratio: {ratio['shortAccount']}")
73
```
74
75
### Futures Trading
76
77
Place and manage futures orders with leverage control.
78
79
```python { .api }
80
def futures_create_order(self, **params): ...
81
def futures_place_batch_order(self, **params): ...
82
def futures_get_order(self, **params): ...
83
def futures_get_open_orders(self, **params): ...
84
def futures_get_all_orders(self, **params): ...
85
def futures_cancel_order(self, **params): ...
86
def futures_cancel_all_open_orders(self, **params): ...
87
def futures_cancel_orders(self, **params): ...
88
def futures_modify_order(self, **params): ...
89
```
90
91
#### Usage Examples
92
93
```python
94
from binance import FUTURE_ORDER_TYPE_LIMIT, FUTURE_ORDER_TYPE_MARKET
95
96
# Place futures market order
97
futures_order = client.futures_create_order(
98
symbol='BTCUSDT',
99
side='BUY',
100
type=FUTURE_ORDER_TYPE_MARKET,
101
quantity=0.001
102
)
103
104
# Place futures limit order
105
limit_order = client.futures_create_order(
106
symbol='BTCUSDT',
107
side='BUY',
108
type=FUTURE_ORDER_TYPE_LIMIT,
109
timeInForce='GTC',
110
quantity=0.001,
111
price='45000'
112
)
113
114
# Place stop market order
115
stop_order = client.futures_create_order(
116
symbol='BTCUSDT',
117
side='SELL',
118
type='STOP_MARKET',
119
quantity=0.001,
120
stopPrice='48000'
121
)
122
123
# Place batch orders (up to 5 orders)
124
batch_orders = [
125
{
126
'symbol': 'BTCUSDT',
127
'side': 'BUY',
128
'type': 'LIMIT',
129
'timeInForce': 'GTC',
130
'quantity': '0.001',
131
'price': '45000'
132
},
133
{
134
'symbol': 'BTCUSDT',
135
'side': 'SELL',
136
'type': 'LIMIT',
137
'timeInForce': 'GTC',
138
'quantity': '0.001',
139
'price': '55000'
140
}
141
]
142
143
batch_result = client.futures_place_batch_order(batchOrders=batch_orders)
144
145
# Get futures order status
146
order_status = client.futures_get_order(
147
symbol='BTCUSDT',
148
orderId=12345678
149
)
150
151
# Cancel futures order
152
cancel_result = client.futures_cancel_order(
153
symbol='BTCUSDT',
154
orderId=12345678
155
)
156
157
# Modify existing order
158
modify_result = client.futures_modify_order(
159
symbol='BTCUSDT',
160
orderId=12345678,
161
side='BUY',
162
quantity='0.002', # New quantity
163
price='46000' # New price
164
)
165
```
166
167
### Account and Position Management
168
169
Manage futures account, positions, and leverage settings.
170
171
```python { .api }
172
def futures_account(self, **params): ...
173
def futures_account_balance(self, **params): ...
174
def futures_position_information(self, **params): ...
175
def futures_change_leverage(self, **params): ...
176
def futures_change_margin_type(self, **params): ...
177
def futures_change_position_margin(self, **params): ...
178
def futures_position_margin_history(self, **params): ...
179
```
180
181
#### Usage Examples
182
183
```python
184
# Get futures account information
185
futures_account = client.futures_account()
186
187
print(f"Total wallet balance: {futures_account['totalWalletBalance']} USDT")
188
print(f"Total unrealized PNL: {futures_account['totalUnrealizedProfit']} USDT")
189
print(f"Total margin balance: {futures_account['totalMarginBalance']} USDT")
190
print(f"Available balance: {futures_account['availableBalance']} USDT")
191
192
# Get account balance breakdown
193
account_balance = client.futures_account_balance()
194
for balance in account_balance:
195
if float(balance['balance']) > 0:
196
print(f"{balance['asset']}: {balance['balance']} (Available: {balance['withdrawAvailable']})")
197
198
# Get position information
199
positions = client.futures_position_information()
200
for position in positions:
201
if float(position['positionAmt']) != 0:
202
print(f"Symbol: {position['symbol']}")
203
print(f"Position: {position['positionAmt']} (Side: {position['positionSide']})")
204
print(f"Entry price: {position['entryPrice']}")
205
print(f"Mark price: {position['markPrice']}")
206
print(f"Unrealized PNL: {position['unRealizedProfit']}")
207
print(f"Leverage: {position['leverage']}x")
208
209
# Change leverage for symbol
210
leverage_result = client.futures_change_leverage(
211
symbol='BTCUSDT',
212
leverage=10
213
)
214
215
# Change margin type (ISOLATED or CROSSED)
216
margin_type_result = client.futures_change_margin_type(
217
symbol='BTCUSDT',
218
marginType='ISOLATED'
219
)
220
221
# Adjust position margin
222
margin_result = client.futures_change_position_margin(
223
symbol='BTCUSDT',
224
amount=100,
225
type=1 # 1: Add margin, 2: Reduce margin
226
)
227
```
228
229
### Futures Order Types and Parameters
230
231
```python
232
# Futures-specific order types
233
FUTURE_ORDER_TYPE_LIMIT = "LIMIT"
234
FUTURE_ORDER_TYPE_MARKET = "MARKET"
235
FUTURE_ORDER_TYPE_STOP = "STOP"
236
FUTURE_ORDER_TYPE_STOP_MARKET = "STOP_MARKET"
237
FUTURE_ORDER_TYPE_TAKE_PROFIT = "TAKE_PROFIT"
238
FUTURE_ORDER_TYPE_TAKE_PROFIT_MARKET = "TAKE_PROFIT_MARKET"
239
FUTURE_ORDER_TYPE_TRAILING_STOP_MARKET = "TRAILING_STOP_MARKET"
240
241
# Position sides (for hedge mode)
242
POSITION_SIDE_BOTH = "BOTH"
243
POSITION_SIDE_LONG = "LONG"
244
POSITION_SIDE_SHORT = "SHORT"
245
246
# Working type for stop orders
247
WORKING_TYPE_MARK_PRICE = "MARK_PRICE"
248
WORKING_TYPE_CONTRACT_PRICE = "CONTRACT_PRICE"
249
```
250
251
#### Advanced Order Examples
252
253
```python
254
# Trailing stop order
255
trailing_stop = client.futures_create_order(
256
symbol='BTCUSDT',
257
side='SELL',
258
type='TRAILING_STOP_MARKET',
259
quantity=0.001,
260
callbackRate=1.0 # 1% callback rate
261
)
262
263
# Stop limit order with working type
264
stop_limit = client.futures_create_order(
265
symbol='BTCUSDT',
266
side='SELL',
267
type='STOP',
268
timeInForce='GTC',
269
quantity=0.001,
270
price='47000', # Limit price
271
stopPrice='48000', # Stop price
272
workingType='MARK_PRICE' # Use mark price for trigger
273
)
274
275
# Hedge mode position (requires hedge mode enabled)
276
long_position = client.futures_create_order(
277
symbol='BTCUSDT',
278
side='BUY',
279
positionSide='LONG',
280
type='MARKET',
281
quantity=0.001
282
)
283
284
short_position = client.futures_create_order(
285
symbol='BTCUSDT',
286
side='SELL',
287
positionSide='SHORT',
288
type='MARKET',
289
quantity=0.001
290
)
291
```
292
293
### Trading History and Statistics
294
295
Access futures trading history and performance metrics.
296
297
```python { .api }
298
def futures_account_trades(self, **params): ...
299
def futures_income_history(self, **params): ...
300
def futures_adl_quantile(self, **params): ...
301
def futures_force_orders(self, **params): ...
302
```
303
304
#### Usage Examples
305
306
```python
307
# Get futures trading history
308
trades = client.futures_account_trades(symbol='BTCUSDT', limit=100)
309
310
for trade in trades:
311
print(f"Trade ID: {trade['id']}")
312
print(f"Price: {trade['price']}, Qty: {trade['qty']}")
313
print(f"Quote qty: {trade['quoteQty']}")
314
print(f"Commission: {trade['commission']} {trade['commissionAsset']}")
315
print(f"Realized PnL: {trade['realizedPnl']}")
316
317
# Get income history (funding fees, realized PnL, etc.)
318
income_history = client.futures_income_history(
319
incomeType='FUNDING_FEE', # TRANSFER, WELCOME_BONUS, REALIZED_PNL, FUNDING_FEE, COMMISSION, etc.
320
limit=100
321
)
322
323
for income in income_history:
324
print(f"Income: {income['income']} {income['asset']}")
325
print(f"Type: {income['incomeType']}")
326
print(f"Time: {income['time']}")
327
328
# Get ADL (Auto-Deleveraging) quantile
329
adl_quantile = client.futures_adl_quantile()
330
for position in adl_quantile:
331
print(f"Symbol: {position['symbol']}")
332
print(f"ADL quantile: {position['adlQuantile']}")
333
334
# Get force liquidation orders
335
force_orders = client.futures_force_orders(limit=100)
336
```
337
338
### Coin-Margined Futures
339
340
All USD-margined futures methods have coin-margined equivalents with `_coin` suffix.
341
342
```python { .api }
343
def futures_coin_create_order(self, **params): ...
344
def futures_coin_account(self, **params): ...
345
def futures_coin_account_balance(self, **params): ...
346
def futures_coin_position_information(self, **params): ...
347
def futures_coin_change_leverage(self, **params): ...
348
```
349
350
#### Coin-Margined Examples
351
352
```python
353
# Place coin-margined futures order
354
coin_order = client.futures_coin_create_order(
355
symbol='BTCUSD_PERP', # Note: different symbol format
356
side='BUY',
357
type='MARKET',
358
quantity=1 # In contracts, not BTC
359
)
360
361
# Get coin-margined account info
362
coin_account = client.futures_coin_account()
363
print(f"Total wallet balance: {coin_account['totalWalletBalance']}")
364
365
# Get coin-margined positions
366
coin_positions = client.futures_coin_position_information()
367
for position in coin_positions:
368
if float(position['positionAmt']) != 0:
369
print(f"Symbol: {position['symbol']}")
370
print(f"Position: {position['positionAmt']} contracts")
371
print(f"Unrealized PNL: {position['unRealizedProfit']} {position['asset']}")
372
```
373
374
### Portfolio Margin (PAPI)
375
376
Comprehensive portfolio margin functionality for institutional and high-volume traders with unified margin across spot, futures, and options.
377
378
```python { .api }
379
def papi_get_balance(self, **params): ...
380
def papi_get_account(self, **params): ...
381
def papi_get_margin_max_borrowable(self, **params): ...
382
def papi_get_margin_max_withdraw(self, **params): ...
383
def papi_get_um_position_risk(self, **params): ...
384
def papi_get_cm_position_risk(self, **params): ...
385
def papi_set_um_leverage(self, **params): ...
386
def papi_set_cm_leverage(self, **params): ...
387
def papi_get_um_account(self, **params): ...
388
def papi_get_cm_account(self, **params): ...
389
def papi_create_um_order(self, **params): ...
390
def papi_create_cm_order(self, **params): ...
391
def papi_get_margin_margin_loan(self, **params): ...
392
def papi_get_margin_repay_loan(self, **params): ...
393
```
394
395
#### Portfolio Margin Account Management
396
397
```python
398
# Get portfolio margin balance
399
papi_balance = client.papi_get_balance()
400
total_usd_value = 0
401
402
for balance in papi_balance:
403
if float(balance['balance']) > 0:
404
print(f"{balance['asset']}: {balance['balance']}")
405
total_usd_value += float(balance['usdValue'])
406
407
print(f"Total portfolio value: ${total_usd_value:.2f}")
408
409
# Get comprehensive portfolio account info
410
papi_account = client.papi_get_account()
411
print(f"Total net value: ${papi_account['totalNetValueOfPortfolio']}")
412
print(f"Portfolio margin ratio: {papi_account['portfolioMarginRatio']}")
413
print(f"Total maintenance margin: ${papi_account['totalMaintenanceMargin']}")
414
print(f"Available balance: ${papi_account['availableBalance']}")
415
416
# Get USD-M futures account info
417
um_account = client.papi_get_um_account()
418
print(f"Total wallet balance: {um_account['totalWalletBalance']}")
419
print(f"Available balance: {um_account['availableBalance']}")
420
421
# Get Coin-M futures account info
422
cm_account = client.papi_get_cm_account()
423
print(f"Total wallet balance: {cm_account['totalWalletBalance']}")
424
```
425
426
#### Portfolio Trading Operations
427
428
```python
429
# Create USD-M futures order in portfolio margin
430
um_order = client.papi_create_um_order(
431
symbol='BTCUSDT',
432
side='BUY',
433
type='MARKET',
434
quantity=0.001
435
)
436
437
print(f"Order ID: {um_order['orderId']}")
438
print(f"Status: {um_order['status']}")
439
440
# Create Coin-M futures order in portfolio margin
441
cm_order = client.papi_create_cm_order(
442
symbol='BTCUSD_PERP',
443
side='BUY',
444
type='MARKET',
445
quantity=1 # In contracts
446
)
447
448
# Set leverage for USD-M futures
449
um_leverage = client.papi_set_um_leverage(
450
symbol='BTCUSDT',
451
leverage=10
452
)
453
454
# Set leverage for Coin-M futures
455
cm_leverage = client.papi_set_cm_leverage(
456
symbol='BTCUSD_PERP',
457
leverage=5
458
)
459
```
460
461
#### Portfolio Margin Operations
462
463
```python
464
# Get maximum borrowable amount
465
max_borrow = client.papi_get_margin_max_borrowable(
466
asset='USDT',
467
isolatedSymbol='BTCUSDT' # Optional for isolated margin
468
)
469
print(f"Max borrowable USDT: {max_borrow['amount']}")
470
471
# Get maximum withdrawable amount
472
max_withdraw = client.papi_get_margin_max_withdraw(asset='USDT')
473
print(f"Max withdrawable USDT: {max_withdraw['amount']}")
474
475
# Execute margin loan
476
margin_loan = client.papi_get_margin_margin_loan(
477
asset='USDT',
478
amount=1000
479
)
480
481
# Repay margin loan
482
repay_loan = client.papi_get_margin_repay_loan(
483
asset='USDT',
484
amount=500
485
)
486
```
487
488
This comprehensive futures trading functionality provides complete control over both USD-margined and coin-margined futures positions with advanced order types, leverage management, and portfolio margin support.