Creating a Signature
The signature is created by concatenating
-
SendingTime (52) as a string
-
ASCII 01 value
-
SeqNum (34) as a string
-
ASCII 01 value
-
SenderCompID (49)
-
ASCII 01 value
-
TargetCompID (56)
This string is then signed using the HMAC SHA-256 Algorithm and the API Secret for the API Key. Sample Java code showing how this can be done programmatically. Note this sample relies on Apache Commons-Codec and QuickFIX for Java
/**
* Takes a Message, an apiKey and apiSecret and uses the HMAC-SHA256
* algorithm to sign a FIX message by appending
* the sending-time sequenceNumber, SenderCompID and TargetCompID with
* \u0001 separator and signing using the
* secret, putting it into the RawBytes in Base64 encoding.
*/
private static void signLogon(final Message message,
final SessionID sessionId,
final String apiKey,
final String apiSecret) throws FieldNotFound {
final var senderCompId = sessionId.getSenderCompID();
final var targetCompId = sessionId.getTargetCompID();
final var sendingTime = message.getString(SendingTime.FIELD);
final var seqNum = message.getInt(MsgSeqNum.FIELD);
final var sep = "\u0001";
final var hmac = sign(apiSecret, sendingTime + sep + seqNum + sep +
senderCompId + sep + targetCompId);
message.setString(Password.FIELD, apiKey);
message.setInt(RawDataLength.FIELD, hmac.length());
message.setString(RawData.FIELD, hmac);
}
private static String sign(final String apiSecret, final String data) {
final var mac = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_SHA_256,
apiSecret.getBytes());
final var encodedBytes = mac.doFinal(data.getBytes());
final var encoder = Base64.getUrlEncoder();//URL Safe Base64
return encoder.encodeToString(encodedBytes);
}Heartbeat
| Tag | Field Name | Req'd | Comments |
|---|---|---|---|
<MessageHeader> | Y | MsgType <35> = 0 | |
| 112 | TestReqID | Y | Required when the heartbeat is the result of a Test Request message |
<MessageTrailer> | Y |
Test Request
| Tag | Field Name | Req'd | Comments |
|---|---|---|---|
<MessageHeader> | Y | MsgType <35> = 1 | |
| 112 | TestReqID | Y | |
<MessageTrailer> | Y |
Resend Request
| Tag | Field Name | Req'd | Comments |
|---|---|---|---|
<MessageHeader> | Y | MsgType <35> = 2 | |
| 7 | BeginSeqNo | Y | |
| 16 | EndSeqNo | Y | |
<MessageTrailer> | Y |
Reject
| Tag | Field Name | Req'd | Comments |
|---|---|---|---|
<MessageHeader> | Y | MsgType <35> = 3 | |
| 45 | RefSeqNum | Y | MsgSeqNum of rejected message |
| 371 | RefTagID | N | The tag number of the FIX field being referenced |
| 372 | RefMsgType | N | The MsgType of the FIX message being referenced |
| 373 | SessionRejectReason | N | Code to identify reason for a session-level Reject message |
| 58 | Text | N | Where possible, message to explain reason for rejection |
<MessageTrailer> | Y |
Sequence Reset
| Tag | Field Name | Req'd | Comments |
|---|---|---|---|
<MessageHeader> | Y | MsgType <35> = 4 | |
| 123 | GapFillFlag | N | |
| 36 | NewSeqNo | Y | |
<MessageTrailer> | Y |
Logout
| Tag | Field Name | Req'd | Comments |
|---|---|---|---|
<MessageHeader> | Y | MsgType <35> = 5 | |
| 58 | Text | N | |
<MessageTrailer> | Y |
Updated 3 months ago
