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_idonplace_orderfor safe retries. - Symbols use the unseparated form (
BTCUSDT,DOGEUSDT).
Install
- Python
- Java
- Go
- Node.js
pip install cryptography requests
Gradle:
dependencies {
implementation 'org.bouncycastle:bcprov-jdk18on:1.78'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
}
go get github.com/google/uuid
Node 18+ — no dependencies.
Use it
- Python
- Java
- Go
- Node.js
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))
import com.example.coinswitch.CoinswitchFutures;
import java.util.Map;
CoinswitchFutures cf = new CoinswitchFutures(
"<your api key>", "<your secret key>");
System.out.println(cf.walletBalance());
// Place a limit order
String placed = cf.placeOrder(Map.of(
"symbol", "DOGEUSDT", "side", "BUY",
"order_type", "LIMIT",
"price", 0.28, "quantity", 22
));
System.out.println(placed);
// List + cancel
System.out.println(cf.openOrders("DOGEUSDT"));
// String body... extract order_id, then:
// cf.cancelOrder(orderId);
// Positions
System.out.println(cf.positions(null));
import (
"fmt"
coinswitchfutures "your.module/path/coinswitchfutures"
)
cf := coinswitchfutures.NewClient("<api key>", "<secret key>")
bal, _ := cf.WalletBalance()
fmt.Println(string(bal))
placed, err := cf.PlaceOrder(map[string]any{
"symbol": "DOGEUSDT", "side": "BUY",
"order_type": "LIMIT",
"price": 0.28, "quantity": 22,
})
if err != nil { panic(err) }
fmt.Println(string(placed))
pos, _ := cf.Positions("")
fmt.Println(string(pos))
const { FuturesClient } = require('./coinswitch_futures');
const cf = new FuturesClient({
apiKey: '<your hex api key>',
secretKey: '<your hex secret key>',
});
console.log(await cf.walletBalance());
const placed = await cf.placeOrder({
symbol: 'DOGEUSDT', side: 'BUY',
order_type: 'LIMIT',
price: 0.28, quantity: 22,
});
const orderId = placed.data.order_id;
console.log(await cf.openOrders('DOGEUSDT'));
console.log(await cf.cancelOrder(orderId));
// Stop-loss
await cf.placeOrder({
symbol: 'DOGEUSDT', side: 'SELL',
order_type: 'STOP_MARKET',
quantity: 0,
trigger_price: 0.30,
reduce_only: true,
});
console.log(await cf.positions());
Endpoints covered
| Method | Endpoint |
|---|---|
wallet_balance / walletBalance / WalletBalance | GET /trade/api/v2/futures/wallet_balance |
transactions / Transactions | GET /trade/api/v2/futures/transactions |
instrument_info / instrumentInfo / InstrumentInfo | GET /trade/api/v2/futures/instrument_info |
order_book / orderBook / OrderBook | GET /trade/api/v2/futures/order_book |
ticker / Ticker | GET /trade/api/v2/futures/ticker |
all_pairs_ticker / allPairsTicker / AllPairsTicker | GET /trade/api/v2/futures/all-pairs/ticker |
klines / Klines | GET /trade/api/v2/futures/klines |
market_trades / marketTrades / MarketTrades | GET /trade/api/v2/futures/trades |
place_order / placeOrder / PlaceOrder | POST /trade/api/v2/futures/order |
cancel_order / cancelOrder / CancelOrder | DELETE /trade/api/v2/futures/order |
cancel_all_open_orders / cancelAllOpenOrders / CancelAllOpenOrders | POST /trade/api/v2/futures/cancel-all |
get_order_status / getOrderStatus / GetOrderStatus | GET /trade/api/v2/futures/order |
open_orders / openOrders / OpenOrders | GET /trade/api/v2/futures/orders?open=true |
closed_orders / closedOrders / ClosedOrders | GET /trade/api/v2/futures/orders?open=false |
positions / Positions | GET /trade/api/v2/futures/positions |
get_leverage / getLeverage / GetLeverage | GET /trade/api/v2/futures/leverage |
update_leverage / updateLeverage / UpdateLeverage | POST /trade/api/v2/futures/leverage |
add_margin / addMargin / AddMargin | POST /trade/api/v2/futures/add_margin |
For per-endpoint request/response details, see Futures Reference.
Related
- Order Lifecycle —
PARTIALLY_EXECUTEDis terminal for Futures. - Position Lifecycle — opening, adding, reducing, closing.
- Margin & Leverage — when leverage can/can't change.