463 lines
16 KiB
C++
463 lines
16 KiB
C++
#include "SpartanError.h"
|
|
#include "lib/utils/bts_assert.h"
|
|
#include <fmt/format.h>
|
|
#include <ostream>
|
|
|
|
namespace bts::spartan {
|
|
|
|
const char *translate_business_reject_reason(int reason) {
|
|
switch (reason) {
|
|
case 0:
|
|
return "Other";
|
|
case 1:
|
|
return "Unknown ID (unknown PartyDetailsListReqID being referenced in "
|
|
"business message)";
|
|
case 2:
|
|
return "Unknown Security";
|
|
case 3:
|
|
return "Unsupported Message Type (for example using messages specific to "
|
|
"cash markets for futures)";
|
|
case 5:
|
|
return "Required Field Missing";
|
|
case 6:
|
|
return "Not Authorized";
|
|
case 8:
|
|
return "Throttle Limit Exceeded (volume controls)";
|
|
case 100:
|
|
return "Value is incorrect (out of range) for this tag (for example "
|
|
"using a value outside defined range of integer) ";
|
|
case 101:
|
|
return "Incorrect data format for value (for example using ASCII "
|
|
"character outside 32-126 in string field)";
|
|
case 102:
|
|
return "Rejected due to Kill Switch";
|
|
case 103:
|
|
return "Rejected due to Risk Management API";
|
|
case 104:
|
|
return "Rejected due to Globex Credit Controls";
|
|
case 105:
|
|
return "Not Authorized to trade Deliverable Swap Futures";
|
|
case 106:
|
|
return "Not Authorized to trade Interest Rate Swap Futures";
|
|
case 107:
|
|
return "Rejected due to Inline Credit Controls";
|
|
case 108:
|
|
return "Invalid PartyDetailsListReqID (reusing already existing "
|
|
"PartyDetailsListReqID while creating Party Details Definition "
|
|
"Request)";
|
|
case 109:
|
|
return "Incoming message could not be decoded. (Check schema version)";
|
|
case 110:
|
|
return "Same repeating group entry appears more than once";
|
|
case 111:
|
|
return "Exceeded maximum number of allowable Party Details Definition "
|
|
"Requests";
|
|
case 112:
|
|
return "Technical Error in Registering Party Details";
|
|
case 113:
|
|
return "Rejected due to Cross Venue Risk";
|
|
case 114:
|
|
return "Order Status Not Available";
|
|
case 115:
|
|
return "Enum Not Supported";
|
|
case 116:
|
|
return "Order Status Not Found";
|
|
case 117:
|
|
return "Mass Order Status Cannot be Completed";
|
|
case 118:
|
|
return "Exceeded Maximum Number of Allowable RequestingPartyID's in "
|
|
"Party Details List Request";
|
|
case 119:
|
|
return "Duplicate Order Threshold Exceeded";
|
|
case 120:
|
|
return "On-Demand Message Rejected Due to Preceding Party Details "
|
|
"Definition Request Being Rejected";
|
|
case 121:
|
|
return "Message Rejected Since PartyDetailsListReqID Does Not Match with "
|
|
"Immediately Preceding Party Details Definition Request sent to "
|
|
"MSGW when using On-demand administrative information";
|
|
case 122:
|
|
return "Party Details Definition Request sent to MSGW Being Rejected Due "
|
|
"to Corresponding Business Message Being Rejected";
|
|
case 123:
|
|
return "Another Message Sent in Between Party Details Definition Request "
|
|
"and Business Message when using On-demand administrative "
|
|
"information";
|
|
case 124:
|
|
return "Cannot Have More Than One In-Flight Mass Order Status Request in "
|
|
"Progress";
|
|
case 125:
|
|
return "Exceeded Maximum Number of In-Flight Order Status Requests";
|
|
case 126:
|
|
return "Cannot Have More Than One In-Flight Party Details List Request "
|
|
"in Progress";
|
|
case 127:
|
|
return "Party Details List Request is Missing Requesting Party ID and "
|
|
"Party ID";
|
|
case 128:
|
|
return "Party Details List Request cannot contain both RequestingPartyID "
|
|
"and PartyID";
|
|
case 129:
|
|
return "Party Details Definition Request Being Rejected Since Another "
|
|
"Message was sent in Between On-Demand Message";
|
|
case 130:
|
|
return "Buy Side Firm ID Does Not Match Sell Side Firm ID in New Order "
|
|
"Cross";
|
|
case 131:
|
|
return "Message Type Not Supported on Backup Instance";
|
|
case 132:
|
|
return "New Order Cross Does Not Contain Buy Side Followed by Sell Side";
|
|
}
|
|
return "Unknown or invalid business reject reason.";
|
|
}
|
|
|
|
const char *translate_negotiation_reject(int reason) {
|
|
// https://www.cmegroup.com/confluence/display/EPICSANDBOX/Negotiation+Reject
|
|
// 01/13/2020
|
|
switch (reason) {
|
|
case 0:
|
|
return "HMACNotAuthenticated: failed authentication because identity is "
|
|
"not recognized";
|
|
case 1:
|
|
return "HMACNotAvailable: HMAC component is not responding (5sec)";
|
|
case 2:
|
|
return "InvalidUUID: UUID is not greater than the one last used or value "
|
|
"sent by the client is out of acceptable range (MIN, MAX)";
|
|
case 3:
|
|
return "InvalidTimestamp: Timestamp is not greater than the one last "
|
|
"used or value sent by the client is out of acceptable range "
|
|
"(MIN, MAX)";
|
|
case 4:
|
|
return "RequiredHMACSignatureMissing: empty bytes in HMACSignature field";
|
|
case 5:
|
|
return "RequiredAccessKeyIDMissing: empty bytes in AccessKeyID field";
|
|
case 6:
|
|
return "RequiredSessionMissing: empty bytes in Session field";
|
|
case 7:
|
|
return "RequiredFirmMissing: empty bytes in Firm field";
|
|
case 8:
|
|
return "RequiredUUIDMisssing: null value in UUID field";
|
|
case 9:
|
|
return "RequiredRequestTimestampMissing: null value in RequestTimestamp "
|
|
"field";
|
|
case 10:
|
|
return "SessionBlocked: session and firm are not authorized for this "
|
|
"port";
|
|
case 12:
|
|
return "InvalidAccessKeyID: contains non-printable ASCII character";
|
|
case 13:
|
|
return "InvalidSession: contains non-printable ASCII character";
|
|
case 14:
|
|
return "InvalidFirm: contains non-printable ASCII character";
|
|
case 15:
|
|
return "Volume Controls - exceeding TPS limit as defined for volume "
|
|
"controls (reject action)";
|
|
case 16:
|
|
return "SplitMessageRejected - Messages queued due to split message "
|
|
"penalty being rejected because of logout or disconnect";
|
|
case 17:
|
|
return "SplitMessageQueue - Reached threshold of messages queued due to "
|
|
"split message penalty";
|
|
case 27:
|
|
return "DesignatedBackup - Using Designated backup before designated "
|
|
"primary not allowed";
|
|
}
|
|
return "Unknown or invalid Negotiate reject reason.";
|
|
}
|
|
|
|
const char *translate_establish_reject(int reason) {
|
|
switch (reason) {
|
|
case 0:
|
|
return "HMACNotAuthenticated: failed authentication because identity is "
|
|
"not recognized";
|
|
case 1:
|
|
return "HMACNotAvailable: HMAC component is not responding (5sec)";
|
|
case 2:
|
|
return "InvalidUUID: UUID is not greater than the one last used or value "
|
|
"sent by the client is out of acceptable range (MIN, MAX)";
|
|
case 3:
|
|
return "InvalidTimestamp: Timestamp is not greater than the one last "
|
|
"used or value sent by the client is out of acceptable range "
|
|
"(MIN, MAX)";
|
|
case 4:
|
|
return "RequiredHMACSignatureMissing: empty bytes in HMACSignature field";
|
|
case 5:
|
|
return "RequiredAccessKeyIDMissing: empty bytes in AccessKeyID field";
|
|
case 6:
|
|
return "RequiredSessionMissing: empty bytes in Session field";
|
|
case 7:
|
|
return "RequiredFirmMissing: empty bytes in Firm field";
|
|
case 8:
|
|
return "RequiredUUIDMisssing: null value in UUID field";
|
|
case 9:
|
|
return "RequiredRequestTimestampMissing: null value in RequestTimestamp "
|
|
"field";
|
|
case 10:
|
|
return "SessionBlocked: session and firm are not authorized for this "
|
|
"port";
|
|
case 11:
|
|
return "InvalidKeepAliveInterval: value is out of acceptable range (MIN, "
|
|
"MAX)";
|
|
case 12:
|
|
return "InvalidAccessKeyID: contains non-printable ASCII character";
|
|
case 13:
|
|
return "InvalidSession: contains non-printable ASCII character";
|
|
case 14:
|
|
return "InvalidFirm: contains non-printable ASCII character";
|
|
case 15:
|
|
return "Volume Controls - exceeding TPS limit as defined for volume "
|
|
"controls (reject action)";
|
|
case 16:
|
|
return "SplitMessageRejected - Messages queued due to split message "
|
|
"penalty being rejected because of logout or disconnect";
|
|
case 17:
|
|
return "SplitMessageQueue - Reached threshold of messages queued due to "
|
|
"split message penalty";
|
|
case 18:
|
|
return "RequiredTradingSystemNameMissing: empty bytes in "
|
|
"TradingSystemName";
|
|
case 19:
|
|
return "RequiredTradingSystemVersionMissing: empty bytes in "
|
|
"TradingSystemVersion";
|
|
case 20:
|
|
return "RequiredTradingSystemVendorMissing: empty bytes in "
|
|
"TradingSystemVendor";
|
|
case 21:
|
|
return "RequiredKeepAliveIntervalMissing: null value in "
|
|
"KeepAliveInterval field";
|
|
case 22:
|
|
return "RequiredNextSeqNoMissing: empty bytes in NextSeqNo field";
|
|
case 23:
|
|
return "InvalidTradingSystemName: contains non-prinatable ASCII "
|
|
"character";
|
|
case 24:
|
|
return "InvalidTradingSystemVersion: contains non-prinatable ASCII "
|
|
"character";
|
|
case 25:
|
|
return "InvalidTradingSystemVendor: contains non-prinatable ASCII "
|
|
"character";
|
|
case 26:
|
|
return "DesignatedBackup - Using Designated backup before designated "
|
|
"primary not allowed";
|
|
case 27:
|
|
return "DesignatedBackup - Using Designated backup before designated "
|
|
"primary not allowed";
|
|
}
|
|
return "Unknown or invalid Establish reject reason.";
|
|
}
|
|
|
|
const char *translate_terminate(int reason) {
|
|
switch (reason) {
|
|
case 0:
|
|
return "Finished: session is being terminated without finalization";
|
|
|
|
case 2:
|
|
return "Unnegotiated: Sending any message when session has not been "
|
|
"Negotiated ";
|
|
|
|
case 3:
|
|
return "NotEstablished: Sending any message (except Negotiate) when "
|
|
"session has not been established";
|
|
|
|
case 4:
|
|
return "AlreadyNegotiated: NegotiationResponse was already sent; "
|
|
"Negotiate was redundant";
|
|
|
|
case 5:
|
|
return "NegotiationInProgress: Previous Negotiate still being processed; "
|
|
"Wait for NegotiationResponse or timeout";
|
|
|
|
case 6:
|
|
return "AlreadyEstablished: EstablishmentAck was already sent; Establish "
|
|
"was redundant";
|
|
|
|
case 7:
|
|
return "EstablishInProgress: Previous Establish still being processed; "
|
|
"Wait for EstablishmentAck or timeout";
|
|
|
|
case 8:
|
|
return "CMEAdministeredPortClosure: due to invalid number of "
|
|
"Negotiate/Establish attempts being exceeded";
|
|
|
|
case 9:
|
|
return "Volume Controls - exceeding TPS limit as defined for volume "
|
|
"controls (logout action)";
|
|
|
|
case 10:
|
|
return "InvalidNextSeqNo - value is not greater than the one last used "
|
|
"for same UUID or value sent by the client is out of acceptable "
|
|
"range (MIN, MAX)";
|
|
|
|
case 11:
|
|
return "InvalidMsgSeqNo - value is lower than the last one used for the "
|
|
"same UUID or value is not initialized to 1 at the beginning of "
|
|
"the week or value sent by the client is out of acceptable range "
|
|
"(MIN, MAX)";
|
|
|
|
case 12:
|
|
return "InvalidLastSeqNo - value is lower than the last one used for the "
|
|
"same UUID or value sent by the client is out of acceptable range "
|
|
"(MIN, MAX)";
|
|
|
|
case 13:
|
|
return "InvalidUUID: UUID value does not match current UUID or value "
|
|
"sent by the client is out of acceptable range (MIN, MAX)";
|
|
|
|
case 14:
|
|
return "InvalidTimestamp: Timestamp value does not match with "
|
|
"RequestTimestamp sent by CME or value sent by the client is out "
|
|
"of acceptable range (MIN, MAX)";
|
|
|
|
case 15:
|
|
return "RequiredUUIDMisssing: null value in UUID field";
|
|
|
|
case 16:
|
|
return "RequiredRequestTimestampMissing: null value in RequestTimestamp "
|
|
"field";
|
|
|
|
case 17:
|
|
return "RequiredCodeMisssing: null value in Code field";
|
|
|
|
case 18:
|
|
return "InvalidSOFH: Invalid message length or invalid encoding type "
|
|
"specified";
|
|
|
|
case 19:
|
|
return "DecodingError: Incoming message could not be decoded";
|
|
|
|
case 20:
|
|
return "KeepAliveIntervalLapsed: KeepAliveInterval has lapsed without "
|
|
"any response so terminating session";
|
|
|
|
case 21:
|
|
return "RequiredNextSeqNoMissing: null value in NextSeqNo field";
|
|
|
|
case 22:
|
|
return "RequiredKeepAliveIntervalLapsedMissing: null value in "
|
|
"KeepAliveIntervalLapsed field";
|
|
|
|
case 23:
|
|
return "Non-Negotiate/Establish message received when not "
|
|
"Negotiated/Established";
|
|
|
|
case 24:
|
|
return "TerminateInProgress: Previous Terminate still being processed; "
|
|
"Wait for Terminate or timeout";
|
|
|
|
case 25:
|
|
return "Other: any other error condition not mentioned above";
|
|
|
|
case 26:
|
|
return "DisconnectFromPrimary: Backup session will be terminated as "
|
|
"well}";
|
|
default:
|
|
return "Unknown error";
|
|
}
|
|
}
|
|
|
|
SpartanError SpartanError::il3_new_order_reject(
|
|
std::string const &reason_txt, int code) {
|
|
return {GW_NEW_ORDER_REJECTION, reason_txt, code};
|
|
}
|
|
|
|
SpartanError SpartanError::il3_bussiness_reject(int reason) {
|
|
return {
|
|
GW_BUSINESS_REJECT, translate_business_reject_reason(reason), reason};
|
|
}
|
|
|
|
SpartanError SpartanError::il3_negotiation_reject(int reason) {
|
|
return {GW_NEGOTIATION_REJECT, translate_negotiation_reject(reason), reason};
|
|
}
|
|
|
|
SpartanError SpartanError::il3_establish_reject(int reason) {
|
|
return {GW_ESTABLISH_REJECT, translate_establish_reject(reason), reason};
|
|
}
|
|
|
|
SpartanError SpartanError::il3_unexpected_terminate(
|
|
std::string const &reason_txt, int code) {
|
|
return {
|
|
GW_UNEXPECTED_TERMINATE,
|
|
fmt::format(
|
|
"Reason: {} Text: {} Error: {} ", reason_txt,
|
|
translate_terminate(code), code)};
|
|
}
|
|
|
|
SpartanError SpartanError::il3_cancel_reject(
|
|
std::string const &text, int reason) {
|
|
if (reason == 2045)
|
|
return {
|
|
GW_ATTEMPT_TO_CANCEL_UNKNOWN_ORDER,
|
|
fmt::format(
|
|
"Attempt to cancel unknown order. Text: {} Error: {}", text,
|
|
reason)};
|
|
else
|
|
return {
|
|
GW_CANCEL_REJECT,
|
|
fmt::format("Cancel reject. Text: {} Error: {}", text, reason)};
|
|
}
|
|
|
|
SpartanError SpartanError::il3_cancel_replace_reject(
|
|
std::string const &text, int reason) {
|
|
if (reason == 2045)
|
|
return {
|
|
GW_ATTEMPT_TO_CANCEL_REPLACE_UNKNOWN_ORDER,
|
|
fmt::format(
|
|
"Attempt to cancel replace unknown order. Text: {} Error: {}",
|
|
text, reason)};
|
|
else
|
|
return {
|
|
GW_CANCEL_REPLACE_REJECT,
|
|
fmt::format("Cancel reject. Text: {} Error: {}", text, reason)};
|
|
}
|
|
|
|
std::string error_code_name(SpartanError::ErrorCode c) {
|
|
switch (c) {
|
|
case SpartanError::NONE:
|
|
return "NONE";
|
|
case SpartanError::GW_UNKNOWN_MESSAGE:
|
|
return "UNKNOWN_MESSAGE";
|
|
case SpartanError::GW_FAILED_TO_CONNECT:
|
|
return "FAILED_TO_CONNECT";
|
|
case SpartanError::GW_BUSINESS_REJECT:
|
|
return "BUSSINESS_REJECT";
|
|
case SpartanError::GW_NEGOTIATION_REJECT:
|
|
return "NEGOTIATION_REJECT";
|
|
case SpartanError::GW_ESTABLISH_REJECT:
|
|
return "ESTABLISH_REJECT";
|
|
case SpartanError::GW_UNEXPECTED_TERMINATE:
|
|
return "UNEXPECTED_TERMINATE";
|
|
case SpartanError::GW_UNEXPECTED_DISCONNECT:
|
|
return "UNEXPECTED_DISCONNECT";
|
|
case SpartanError::GW_RETRANSMIT_FAILURE:
|
|
return "RETRANSMIT_FAILURE";
|
|
case SpartanError::GW_TRADE_CORRECTION:
|
|
return "TRADE_CORRECTION";
|
|
case SpartanError::GW_ATTEMPT_TO_CANCEL_UNKNOWN_ORDER:
|
|
return "ATTEMPT_TO_CANCEL_UNKNOWN_ORDER";
|
|
case SpartanError::GW_ATTEMPT_TO_CANCEL_REPLACE_UNKNOWN_ORDER:
|
|
return "ATTEMPT_TO_CANCEL_REPLACE_UNKNOWN_ORDER";
|
|
case SpartanError::GW_CANCEL_REJECT:
|
|
return "CANCEL_REJECT";
|
|
case SpartanError::GW_CANCEL_REPLACE_REJECT:
|
|
return "CANCEL_REPLACE_REJECT";
|
|
case SpartanError::GW_NEW_ORDER_REJECTION:
|
|
return "NEW_ORDER_REJECTION";
|
|
case SpartanError::FH_PACKET_LOSS:
|
|
return "FH_PACKET_LOSS";
|
|
case SpartanError::RISK_CLIP_SIZE:
|
|
return "RISK_CLIP_SIZE";
|
|
case SpartanError::RISK_MSG_GOVERNOR:
|
|
return "RISK_MSG_GOVERNOR";
|
|
}
|
|
bts_assert(false);
|
|
return {};
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &out, SpartanError const &gw) {
|
|
out << "Error: " << error_code_name(gw.error_code())
|
|
<< " Msg: " << gw.message() << " ExCode: " << gw.exchange_error_code();
|
|
return out;
|
|
}
|
|
|
|
} // namespace bts::spartan
|