-
Notifications
You must be signed in to change notification settings - Fork 0
FIX API
FIX (Financial Information eXchange) is a standard message protocol used to interact with trading system for placing and cancelling orders. The FIX interface is based on the FIX 4.4 specification.
Please contact the BTC Markets support team and complete the account verification process to gain secure access to the FIX interface.
Clients must establish a secure connection to the FIX gateway in order to establish a session.
Endpoint
tcp+ssl://fix.btcmarkets.net:433
All requests are limited to 150 calls per 10 seconds per FIX session. An account can establish and maintain a single FIX session only.
FIX engine will go down on daily basis at UTC time 17:00:00 for maintenance and updates.
FIX engine will have a maintenance window daily basis between 5pm UTC to 5:10pm UTC. During this time all sessions will be closed. All clients are required to restart their sessions during this time and reset sequence numbers to 0 and logon again to start a new connection.
To establish a FIX connection, an API key must be set up (similar process as required for the REST API). This will be the SenderCompID for messages sent by the Client.
Authentication will be verified at logon. The raw data element within the logon message must contain a valid signature, which will be validated by the FIX engine.
The prehash string for the signature input contains the following fields concatenated with an empty string.
seqNum + "A" + apiKey + timestamp
timestamp
is taken from the Logon message SendingTime tag (converted to epoch value in milliseconds).
The following steps demonstrate how to convert the prehash string to a signature:
const msg = seqNum+'A'+apiKey+timestamp
var buffer = Buffer.from(apiPrivateKey, 'base64');
var hmac = crypto.createHmac('sha512', buffer);
const signature = hmac.update(preHashString).digest('base64');
If you are starting to develop your FIX client application, the following code samples can be useful. These demonstrate authentication and the ability to place and cancel orders:
- Connection
- Logon and Authentication
- Synchronizing sequence numbers
- Place or cancel orders
BTC Markets has implemented common messaging and naming conventions used by other crypto exchanges, while also ensuring compatibility with the REST API. The table below shows the FIX and corresponding REST API names.
FIX Name | REST API |
---|---|
Symbol | marketId |
OrdType | type |
OrderQty | amount |
ClOrdID | clientOrderId |
SelfTradePrevention | selfTrade |
ExecInst | postOnly |
LeavesQty | openAmount |
All messages have an attribute called MsgType
which represents the type of message to be communicated with the FIX engine.
Message type | Identifier |
---|---|
Logon | A |
Heartbeat | 0 |
Test Message | 1 |
Logout | 5 |
New Single Order | D |
Cancel Order | F |
Order Status | H |
Message type | Identifier |
---|---|
Logon | A |
Heartbeat | 0 |
Test Message | 1 |
Logout | 5 |
Order Execution Report | 8 |
Order Cancel Reject | 9 |
All messages must include the following header:
Tag | Name | Description |
---|---|---|
8 | BeginString | Must be FIX.4.4 |
9 | BodyLength | Length of the message body in bytes |
8 | MsgType | e.g. D |
49 | SenderCompID | API key (similar API keys used for REST APIs) |
56 | TargetCompID | Must be BTCM (for messages from the client) |
34 | MsgSeqNum | FIX Sequence Number |
52 | SendingTime | Sender time |
10 | CheckSum | FIX computed checksum |
Side
Value | Description |
---|---|
1 | BUY |
2 | SELL |
OrdType
Value | Description |
---|---|
1 | Market |
2 | Limit |
3 | Stop |
4 | Stop Limit |
TimeInForce
Value | Description |
---|---|
1 | Good Till Cancel (GTC) |
3 | Immediate or Cancel (IOC) |
4 | Fill Or Kill (FOK) |
ExecInst
Value | Description |
---|---|
6 | Post only order |
SelfTradeProtection
Value | Description |
---|---|
P | Prevent self trade |
A | Allow self trade |
ExecType
Value | Description |
---|---|
0 | New |
4 | Cancelled |
8 | Rejected |
F | Trade |
I | Order Status |
L | Triggered Order |
OrdStatus
Value | Description |
---|---|
0 | New |
1 | Partially Filled |
2 | Filled |
4 | Canceled |
8 | Rejected |
OrdType
Value | Description |
---|---|
1 | Market |
2 | Limit |
3 | Stop |
4 | Stop Limit |
OrdRejReason
Value | Description |
---|---|
101 | INPUT_ERROR |
102 | AUTH_ERROR |
103 | SERVER_ERROR |
104 | THROTTLED |
105 | INSUFFICIENT_FUNDS |
99 | OTHER |
CxlRejReason
Value | Description |
---|---|
0 | TOO_LATE_TO_CANCEL |
1 | UNKNOWN_ORDER |
101 | INPUT_ERROR |
102 | AUTH_ERROR |
103 | SERVER_ERROR |
104 | THROTTLED |
99 | OTHER |
The Logon message is sent by the Client to initiate a FIX session. Logon must be the first message immediately after the connection is established. Only one FIX session can be established per connection, and any additional Logon messages will be rejected. A corresponding Logon message will be returned to the Client.
Tag | Name | Example Value | Description |
---|---|---|---|
98 | EncryptMethod | 0 | Must be set to "0" (None). Encryption is not supported |
108 | HeartBInt | 30 | Must be set to "30" |
96 | RawData | 8f7e...4783 | Signature |
95 | RawDataLength | ... | Size of RawData |
8013 | CancelOrdersOnDisconnect | 1 | See below |
CancelOrdersOnDisconnect
Value | Description |
---|---|
0 | No orders will be cancelled on disconnect or logout |
1 | Cancel all orders on disconnect only |
2 | Cancel all orders on logout only |
3 | Cancel all orders on disconnect or logout |
Logout message is sent by the Client or Server to close a session gracefully.
Heartbeat messages can be sent by both the Client and Server if no messages have been sent for 30 seconds (or as agreed at Logon message request).
Tag | Name | Example Value | Description |
---|---|---|---|
112 | TestReqID | TEST | Echoed back if responding back to Test Request (1) |
Test messages can be sent by both the Client or Server.
Tag | Name | Example Value | Description |
---|---|---|---|
112 | TestReqID | TEST | Indicates a string that is expected to be echoed back in the next heartbeat |
New single order messages can be sent by the Client to enter a new single order.
Tag | Name | Example Value | Required Y/N | Description |
---|---|---|---|---|
11 | ClOrdID | order123 | Y | Client order ID is a string field allowing up 64 characters: a-z, A-Z, 0-9, and standard formats like UUID |
55 | Symbol | BTC-AUD | Y | |
40 | OrdType | 2 | Y | See below |
38 | OrderQty | 1.1 | Y | Order quantity |
44 | Price | 8000 | N | Limit price - required for OrdType = 2 or 4 |
99 | StopPx | 9000 | N | Stop price - required for OrdType = 3 or 4 |
54 | Side | 1 | Y | See below |
59 | TimeInForce | 1 | Y | See below |
18 | ExecInst | 6 | N | See below. Defaults to not post only if not specified |
7928 | SelfTradePrevention | P | N | See below. Defaults to allow self trade if not specified |
A cancel order request can be sent by the Client to cancel an existing order. Either the OrderID or the OrigClordID must be provided
Tag | Name | Example Value | Description |
---|---|---|---|
37 | OrderID | 123456 | Order ID for the original order (system generated) |
41 | OrigClOrdID | order123 | Original client order ID |
The order status request message can be sent by the Client to get the status of an order. Either the OrderID or the OrigClordID must be provided.
Tag | Name | Example Value | Description |
---|---|---|---|
11 | ClOrdID | order123 | Client order ID; must be unique |
37 | OrderID | orderxyz | Order ID (system generated) |
The order execution report message is sent by the Server to report the result of a request from the Client.
Tag | Name | Example Value | Description |
---|---|---|---|
11 | ClOrdID | order123 | Client order ID |
37 | OrderID | orderxyz | Order ID (system generated) |
150 | ExecType | 0 | See below |
39 | OrdStatus | 0 | See below |
55 | Symbol | BTC-AUD | |
54 | Side | 1 | See below |
40 | OrdType | 2 | See below |
38 | OrderQty | 1.1 | Original order quantity. Only available for ExecType = I |
44 | Price | 8000 | Only available for ExecType = I |
32 | LastQty | 0.2 | Last quantity traded. Only available for ExecType = F |
31 | LastPx | 100 | Last price traded. Only available for ExecType = F |
151 | LeavesQty | 10 | Open order quantity |
103 | OrdRejReason | 101 | See below. Only available for ExecType = 8 |
58 | Text | Invalid market id | Free format reject reason text. Only available for ExecType = 8 |
The order cancel reject message can be sent by the Server to reject an order cancellation request from the Client. These messages can be sent if the order is already cancelled, filled or does not exist in the system.
Tag | Name | Example Value | Description |
---|---|---|---|
37 | OrderID | 123456 | Order ID for the original order (system generated) |
41 | OrigClOrdID | order123 | Original client order ID |
39 | OrdStatus | 8 | Fixed value |
102 | CxlRejReason | 0 | See below |
434 | CxlRejResponseTo | 1 | Response to the cancel request; Fixed value |