HFT Client
A single-file client that wraps every CoinSwitch PRO HFT REST endpoint. Drop it into your project, set your API key + secret, and start trading low-latency futures (or options).
What it gives you
- Every HFT REST endpoint as a method on
HFTClient. - Targets
https://dma.coinswitch.coby default. categorydefaults tolinear(futures) — passoptionfor options.- Auto-minted
orderLinkId/client_txn_idfor safe retries. - A helper for
GET /dma/api/v1/socket/signatureso you can authenticate the private NATS WebSocket.
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_hft import HFTClient
h = HFTClient(
api_key="<your hex api key>",
secret_key="<your hex secret key>",
)
# Account: provision the HFT account (locks settlement currency)
h.transfer_funds(direction="IN", amount=100, quote_asset="USDT")
# Set leverage and position mode
h.set_leverage(symbol="BTCUSDT", buy_leverage=2, sell_leverage=2)
h.switch_position_mode(mode=3) # hedge mode
# Market data
print(h.tickers(symbol="BTCUSDT"))
print(h.order_book(symbol="BTCUSDT", limit=10))
# Place a limit order
placed = h.place_order(
symbol="BTCUSDT", side="Buy",
order_type="Limit",
qty="0.001", price="50000",
position_idx=1, # long side (hedge mode)
)
if placed["retCode"] != 0:
raise RuntimeError(placed["retMsg"])
order_id = placed["result"]["orderId"]
# Manage
print(h.order_realtime(order_id=order_id))
print(h.execution_list(order_id=order_id))
print(h.positions(symbol="BTCUSDT"))
# Subscribe to the private NATS stream (Python NATS client outside this recipe)
creds = h.socket_signature(expires_in_seconds=600)
# creds = {"api_key": ..., "expires": ..., "signature": ...}
# use those on your NATS auth message
import com.example.coinswitch.CoinswitchHFT;
import java.util.Map;
CoinswitchHFT h = new CoinswitchHFT(
"<your api key>", "<your secret key>");
// Provision HFT account (USDT or INR — first transfer locks the currency)
System.out.println(h.transferFunds("IN", 100.0, "USDT", null));
// Set leverage
System.out.println(h.setLeverage("BTCUSDT", 2, 2));
// Place a limit long
String placed = h.placeOrder(Map.of(
"symbol", "BTCUSDT",
"side", "Buy",
"orderType", "Limit",
"qty", "0.001",
"price", "50000",
"positionIdx", 1
));
System.out.println(placed);
// Status + positions
System.out.println(h.orderRealtime(Map.of("symbol", "BTCUSDT")));
System.out.println(h.positions("BTCUSDT", null));
import (
"fmt"
coinswitchhft "your.module/path/coinswitchhft"
)
h := coinswitchhft.NewClient("<api key>", "<secret key>")
// Provision HFT account
if r, err := h.TransferFunds("IN", 100.0, "USDT", ""); err == nil {
fmt.Println(string(r))
}
// Set leverage
h.SetLeverage("BTCUSDT", 2, 2)
// Place
placed, err := h.PlaceOrder(map[string]any{
"symbol": "BTCUSDT",
"side": "Buy",
"orderType": "Limit",
"qty": "0.001",
"price": "50000",
"positionIdx": 1,
})
if err != nil { panic(err) }
fmt.Println(string(placed))
// Positions
pos, _ := h.Positions("BTCUSDT", "")
fmt.Println(string(pos))
const { HFTClient } = require('./coinswitch_hft');
const h = new HFTClient({
apiKey: '<your hex api key>',
secretKey: '<your hex secret key>',
});
// Provision
await h.transferFunds({ direction: 'IN', amount: 100, quoteAsset: 'USDT' });
// Set leverage + hedge mode
await h.setLeverage({ symbol: 'BTCUSDT', buyLeverage: 2, sellLeverage: 2 });
await h.switchPositionMode({ mode: 3 });
// Place a limit long
const placed = await h.placeOrder({
symbol: 'BTCUSDT',
side: 'Buy',
orderType: 'Limit',
qty: '0.001',
price: '50000',
positionIdx: 1,
});
if (placed.retCode !== 0) throw new Error(placed.retMsg);
const orderId = placed.result.orderId;
// Status, positions
console.log(await h.orderRealtime({ orderId }));
console.log(await h.positions({ symbol: 'BTCUSDT' }));
// Get NATS socket credentials
const creds = await h.socketSignature({ expiresInSeconds: 600 });
// creds = { api_key, expires, signature }
Endpoints covered
| Method | Endpoint |
|---|---|
server_time / serverTime / ServerTime | GET /v5/market/time |
instruments_info / instrumentsInfo / InstrumentsInfo | GET /v5/market/instruments-info |
tickers / Tickers | GET /v5/market/tickers |
order_book / orderBook / OrderBook | GET /v5/market/orderbook |
place_order / placeOrder / PlaceOrder | POST /v5/order/create |
order_realtime / orderRealtime / OrderRealtime | GET /v5/order/realtime |
execution_list / executionList / ExecutionList | GET /v5/execution/list |
positions / Positions | GET /v5/position/list |
set_leverage / setLeverage / SetLeverage | POST /v5/position/set-leverage |
switch_position_mode / switchPositionMode / SwitchPositionMode | POST /v5/position/switch-mode |
transfer_funds / transferFunds / TransferFunds | POST /dma/api/v1/funds/transfer |
socket_signature / socketSignature / SocketSignature | GET /dma/api/v1/socket/signature |
For per-endpoint request/response details and edge cases, see HFT Reference.
Related
- HFT Overview — onboarding, when to use HFT vs the regular Futures API.
- Response Envelope — always check
retCode === 0before readingresult. - HFT Sockets Overview — NATS subjects and the auth flow you wire
socket_signatureinto. - Transfer Funds — settlement-currency lock semantics.