Skip to main content

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.co by default.
  • category defaults to linear (futures) — pass option for options.
  • Auto-minted orderLinkId / client_txn_id for safe retries.
  • A helper for GET /dma/api/v1/socket/signature so you can authenticate the private NATS WebSocket.

Install

pip install cryptography requests

Use it

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

Endpoints covered

MethodEndpoint
server_time / serverTime / ServerTimeGET /v5/market/time
instruments_info / instrumentsInfo / InstrumentsInfoGET /v5/market/instruments-info
tickers / TickersGET /v5/market/tickers
order_book / orderBook / OrderBookGET /v5/market/orderbook
place_order / placeOrder / PlaceOrderPOST /v5/order/create
order_realtime / orderRealtime / OrderRealtimeGET /v5/order/realtime
execution_list / executionList / ExecutionListGET /v5/execution/list
positions / PositionsGET /v5/position/list
set_leverage / setLeverage / SetLeveragePOST /v5/position/set-leverage
switch_position_mode / switchPositionMode / SwitchPositionModePOST /v5/position/switch-mode
transfer_funds / transferFunds / TransferFundsPOST /dma/api/v1/funds/transfer
socket_signature / socketSignature / SocketSignatureGET /dma/api/v1/socket/signature

For per-endpoint request/response details and edge cases, see HFT Reference.