Skip to main content

Futures Client

A single-file client that wraps every CoinSwitch PRO Futures REST endpoint. Drop it into your project, set your API key + secret, and start trading perpetuals.

What it gives you

  • Every Futures REST endpoint as a method on FuturesClient.
  • exchange: "EXCHANGE_2" filled in automatically — you only need to pass symbol and order details.
  • Auto-minted client_order_id on place_order for safe retries.
  • Symbols use the unseparated form (BTCUSDT, DOGEUSDT).

Install

pip install cryptography requests

Use it

from coinswitch_futures import FuturesClient

cf = FuturesClient(
api_key="<your hex api key>",
secret_key="<your hex secret key>",
)

# Account
print(cf.wallet_balance())
print(cf.transactions(symbol="DOGEUSDT", limit=20))

# Reference data
print(cf.instrument_info(symbol="BTCUSDT"))
print(cf.ticker("BTCUSDT"))

# Leverage
print(cf.update_leverage(symbol="BTCUSDT", leverage=5))
print(cf.get_leverage("BTCUSDT"))

# Place a limit order
placed = cf.place_order(
symbol="DOGEUSDT", side="BUY",
order_type="LIMIT", price=0.28, quantity=22,
)
order_id = placed["data"]["order_id"]

# Place a stop-loss on a long DOGEUSDT position (TP/SL pattern)
cf.place_order(
symbol="DOGEUSDT", side="SELL",
order_type="STOP_MARKET",
quantity=0,
trigger_price=0.30,
reduce_only=True,
)

# Manage
print(cf.get_order_status(order_id))
print(cf.open_orders(symbol="DOGEUSDT"))
print(cf.cancel_order(order_id))
print(cf.cancel_all_open_orders(symbol="DOGEUSDT"))

# Positions
print(cf.positions())
print(cf.add_margin(symbol="DOGEUSDT", margin=16))

Endpoints covered

MethodEndpoint
wallet_balance / walletBalance / WalletBalanceGET /trade/api/v2/futures/wallet_balance
transactions / TransactionsGET /trade/api/v2/futures/transactions
instrument_info / instrumentInfo / InstrumentInfoGET /trade/api/v2/futures/instrument_info
order_book / orderBook / OrderBookGET /trade/api/v2/futures/order_book
ticker / TickerGET /trade/api/v2/futures/ticker
all_pairs_ticker / allPairsTicker / AllPairsTickerGET /trade/api/v2/futures/all-pairs/ticker
klines / KlinesGET /trade/api/v2/futures/klines
market_trades / marketTrades / MarketTradesGET /trade/api/v2/futures/trades
place_order / placeOrder / PlaceOrderPOST /trade/api/v2/futures/order
cancel_order / cancelOrder / CancelOrderDELETE /trade/api/v2/futures/order
cancel_all_open_orders / cancelAllOpenOrders / CancelAllOpenOrdersPOST /trade/api/v2/futures/cancel-all
get_order_status / getOrderStatus / GetOrderStatusGET /trade/api/v2/futures/order
open_orders / openOrders / OpenOrdersGET /trade/api/v2/futures/orders?open=true
closed_orders / closedOrders / ClosedOrdersGET /trade/api/v2/futures/orders?open=false
positions / PositionsGET /trade/api/v2/futures/positions
get_leverage / getLeverage / GetLeverageGET /trade/api/v2/futures/leverage
update_leverage / updateLeverage / UpdateLeveragePOST /trade/api/v2/futures/leverage
add_margin / addMargin / AddMarginPOST /trade/api/v2/futures/add_margin

For per-endpoint request/response details, see Futures Reference.