FIX API
FIX (Financial Information eXchange) is a standard electronic messaging protocol for placing orders, receiving order updates, and cancelling orders. BTSE's FIX API is based on the FIX 4.2 specification.
Connectionβ
| Environment | Host | Port |
|---|---|---|
| Production | tcp+ssl://fix.btse.com | 9876 |
| Testnet | tcp+ssl://fix.btse.io | 9876 |
Sessions for Spot and Futures are separated using SenderSubID:
| SenderSubID | Market |
|---|---|
SPOT | Spot trading |
FUTURES | Futures trading |
Rate Limitsβ
| Group | Message Types | Limit |
|---|---|---|
| Auth | Logon (A), Logout (5) | 2 per second |
| General | All other messages | 30 per second |
When a rate limit is exceeded, a Business Message Reject (j) is returned with BusinessRejectReason: 4 (application not available).
Common Request Attributesβ
All client messages must include these fields:
| Tag | Name | Description |
|---|---|---|
| 8 | BeginString | Must be FIX.4.2 |
| 9 | BodyLength | Body length in bytes |
| 34 | MsgSeqNum | Sequence number β starts at 1, increments per message. Duplicates/out-of-order are rejected. Reset on new connection. |
| 35 | MsgType | Message type |
| 49 | SenderCompID | Client API key |
| 50 | SenderSubID | SPOT or FUTURES |
| 52 | SendingTime | Message send time (e.g. 20220916-07:29:07) |
| 56 | TargetCompID | Must be <Brand /> |
| 10 | CheckSum | Message checksum |
Messagesβ
Logon (A)β
Initiates a FIX session. Must be the first message sent. Only one session per connection.
| Tag | Name | Value | Description |
|---|---|---|---|
| 35 | MsgType | A | |
| 95 | RawDataLength | 96 | Length of RawData field |
| 96 | RawData | (hex) | HMAC-SHA384 signature. Concatenate with FIX field separator (0x01): SendingTime + MsgType + MsgSeqNum + SenderCompID + TargetCompID, then HMAC-SHA384 with API secret |
| 98 | EncryptMethod | 0 | Must be 0 (None) |
| 108 | HeartBtInt | 30 | Heartbeat interval in seconds. Send heartbeats every Nβ5 seconds |
| 141 | ResetSeqNumFlag | Y | Must be Y |
| 5001 | ApplyNewSymbolName | Y | Futures only. Enables new symbol names (e.g. BTC-PERP). Without this field, only old names (e.g. BTCPFC) are accepted |
Signature computation
// Concatenate fields with FIX separator (0x01):
// SendingTime + 0x01 + MsgType + 0x01 + MsgSeqNum
// + 0x01 + SenderCompID + 0x01 + TargetCompID
//
// Then: HMAC-SHA384(apiSecret, dataRaw)
// Hex-encode the result β RawData (tag 96)
Heartbeat (0)β
Keeps the session alive. Send every Nβ5 seconds where N is the heartbeat interval set in Logon.
| Tag | Name | Value | Description |
|---|---|---|---|
| 35 | MsgType | 0 | |
| 112 | TestReqID | 123 | If responding to a TestRequest, copy from the TestRequest |
Test Request (1)β
Requests a heartbeat response.
| Tag | Name | Value | Description |
|---|---|---|---|
| 35 | MsgType | 1 | |
| 112 | TestReqID | 123 | Arbitrary string β echoed back in a Heartbeat |
Logout (5)β
Terminates the session. The other side responds with another Logout message; connection closes afterwards.
| Tag | Name | Value |
|---|---|---|
| 35 | MsgType | 5 |
New Order Single (D)β
Submits a new order. Supports Market and Limit orders.
| Tag | Name | Value | Description |
|---|---|---|---|
| 35 | MsgType | D | |
| 21 | HandlInst | 1 | Must be 1 (AutomatedExecutionNoIntervention) |
| 11 | ClOrdID | order123 | Unique client-selected order identifier |
| 55 | Symbol | BTC-USD | Symbol name |
| 40 | OrdType | 2 | 1: Market Β· 2: Limit |
| 38 | OrderQty | 1.1 | Order size in base units (required for Limit and Market sell) |
| 44 | Price | 18000 | Limit or Market buy price (required for Limit and Market buy) |
| 54 | Side | 1 | 1: Buy Β· 2: Sell |
| 59 | TimeInForce | 1 | 1: GTC Β· 3: IOC Β· 4: FOK Β· a: 30s Β· b: 5min Β· c: 1h Β· d: 12h Β· e: 1 week Β· f: 1 month |
| 18 | ExecInst | 6 | Optional: E: reduce only Β· 6: post only |
| 5002 | PositionId | BTC-PERP-USDT | Optional. Position to reduce (Futures) |
| 5003 | PositionMode | ONEWAY | Optional. ONEWAY (default) Β· HEDGE Β· ISOLATED |
On acceptance, an Execution Report (8) is returned.
Order Cancel Request (F)β
Requests cancellation of an open order. Provide only one of OrderID or OrigClOrdID.
| Tag | Name | Value | Description |
|---|---|---|---|
| 35 | MsgType | F | |
| 37 | OrderID | order123 | System-assigned order ID |
| 41 | OrigClOrdID | order123 | Client-assigned order ID |
| 55 | Symbol | BTC-USD | Symbol name |
Returns an Execution Report (8) on success, or Order Cancel Reject (9) on failure.
Order Cancel Reject (9)β
Sent by the server when an Order Cancel Request fails.
| Tag | Name | Value | Description |
|---|---|---|---|
| 35 | MsgType | 9 | |
| 37 | OrderID | order123 | Copied from cancel request (if provided) |
| 41 | OrigClOrdID | order123 | Copied from cancel request (if provided) |
| 39 | OrdStatus | 4 | 4: Already cancelled Β· 8: Rejection |
| 102 | CxlRejReason | 1 | 1: Unknown order Β· 99: Other |
| 434 | CxlRejResponseTo | 1 | Always 1 |
Order Status Request (H)β
Queries order status. Provide only one of OrderID or OrigClOrdID. Use OrderID = * to request all pending orders.
| Tag | Name | Value | Description |
|---|---|---|---|
| 35 | MsgType | H | |
| 37 | OrderID | order123 | Order to query, or * for all open orders |
| 41 | OrigClOrdID | order123 | Client order ID |
| 54 | Side | 1 | 1: Buy Β· 2: Sell |
| 55 | Symbol | BTC-USD | Symbol name |
Returns an Execution Report (8) with ExecType=I. When no open orders exist, Text (58) returns "No open orders".
Execution Report (8)β
Sent by the server when: an order is filled, the order status changes, or in response to New Order Single, Order Cancel Request, or Order Status Request.
| Tag | Name | Value | Description |
|---|---|---|---|
| 11 | ClOrdID | order123 | Client order ID |
| 12 | Commission | 0.002 | Trade fee (fill only) |
| 13 | CommType | 3 | Always 3 |
| 14 | CumQty | 0.4 | Cumulative filled quantity |
| 17 | ExecID | d840c8β¦ | Execution ID |
| 31 | LastPx | 7999.25 | Fill price (fill only) |
| 32 | LastShares | 0.4 | Fill quantity (fill only) |
| 35 | MsgType | 8 | |
| 37 | OrderID | d840c8β¦ | System order ID |
| 38 | OrderQty | 1.2 | Original order quantity |
| 39 | OrdStatus | 0 | Current order status (see table below) |
| 44 | Price | 8000 | Original order price |
| 54 | Side | 1 | 1: Buy Β· 2: Sell |
| 55 | Symbol | BTC-USD | Symbol name |
| 58 | Text | text | Rejection reason description |
| 59 | TimeInForce | 6 | 1: GTC Β· 3: IOC Β· 4: FOK Β· 6: GTD Β· aβf: custom durations |
| 60 | TransactTime | 20190525-08:26:38.989 | Order update timestamp |
| 103 | OrdRejReason | 11 | 11: UNSUPPORTED_ORDER_CHARACTERISTIC β see Text(58) for details |
| 126 | ExpireTime | 20190525-08:26:38.989 | Required when TimeInForce=GTD and ExpireDate not set |
| 150 | ExecType | 1 | Reason for this message (see table below) |
| 151 | LeavesQty | 0.8 | Remaining open quantity |
| 1057 | AggressorIndicator | Y | Y: taker Β· N: maker (fill only) |
| 5000 | Liquidation | Y | Y: on-market liquidation order |
ExecType values:
| ExecType | Description |
|---|---|
| 0 | New order |
| 1 | Partially filled |
| 3 | Fully filled |
| 4 | Order cancelled |
| 5 | Order amended |
| 7 | Order refund (self-trade) |
| 8 | Rejected (response to New Order Single) |
| I | Order status (response to Order Status Request) |
OrdStatus values:
| OrdStatus | Description |
|---|---|
| 0 | New order |
| 1 | Partially filled |
| 3 | Fully filled |
| 4 | Cancelled |
| 5 | Amended |
| 7 | Refunded |
| 8 | Rejected |
Reject (3)β
Sent by the server in response to an invalid message.
| Tag | Name | Value | Description |
|---|---|---|---|
| 35 | MsgType | 3 | |
| 45 | RefSeqNum | 2 | Sequence number of rejected message |
| 371 | RefTagID | 38 | Tag number of the rejected field |
| 372 | RefMsgType | D | Message type of the rejected message |
| 58 | Text | Missing quantity | Human-readable rejection reason |
| 373 | SessionRejectReason | 1 | Code identifying rejection reason |
Business Message Reject (j)β
Sent when a rate limit is exceeded.
| Tag | Name | Example | Description |
|---|---|---|---|
| 35 | MsgType | j | |
| 45 | RefSeqNum | 11 | Sequence number of rejected message |
| 49 | SenderCompID | BTSE | Always <Brand /> |
| 56 | TargetCompID | c123...05a | Client API key |
| 57 | TargetSubID | SPOT | SPOT or FUTURES |
| 58 | Text | exceeding rate limit | Details |
| 372 | RefMsgType | F | Message type of rejected message |
| 380 | BusinessRejectReason | 4 | Always 4: application not available |