Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
messages.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <cstddef>
5#include <cstring>
6#include <format>
7#include <type_traits>
8#include <common/order.hpp>
9
10namespace slick::sim {
11
33
39
40inline std::string to_string(BusinessRejectReason reject) {
41 switch (reject) {
43 return "UNKNOWN_SECURITY_ID";
45 return "DUPLICATE_REQUEST_ID";
47 return "UNKNOWN";
48 }
49 return std::format("UNHANDLED BusinessRejectReason ({0})", static_cast<std::underlying_type<BusinessRejectReason>::type>(reject));
50}
51
59
60inline std::string to_string(SessionRejectReason reject) {
61 switch (reject) {
63 return "NONE";
65 return "ALREADY_LOGGED_IN";
67 return "NOT_LOGGED_IN";
69 return "INVALID_SESSION_ID";
71 return "UNKNOWN";
72 }
73 return std::format("UNHANDLED SessionRejectReason ({0})", static_cast<std::underlying_type<SessionRejectReason>::type>(reject));
74}
75
101
102inline std::string to_string(OrdRejectReason reject)
103{
104 switch (reject) {
106 return "NONE";
108 return "UNKNOWN";
110 return "UNKNOWN_CONTRACT";
112 return "UNKNOWN_ORDER";
114 return "MARKET_CLOSED";
116 return "MARKET_HALTED";
118 return "SMP";
120 return "INVALID_DISPLAY_QTY";
122 return "FAK_MUST_BE_LIMIT";
124 return "ICEBERG_MUST_BE_LIMIT";
126 return "ICEBERG_MUST_BE_DAY_OR_GTC";
128 return "PRICE_CANT_BE_BELOW_STOP_PRICE";
130 return "PRICE_CANT_BE_ABOVE_STOP_PRICE";
132 return "STOP_PRICE_MUST_BE_BELOW_LAST_TRADE_PRICE";
134 return "STOP_PRICE_MUST_BE_ABOVE_LAST_TRADE_PRICE";
136 return "TIME_IN_FORCE_NOT_ALLOWED_IN_CURRENT_MARKET_STATE";
138 return "ORDER_TYPE_NOT_ALLOWED_IN_CURRENT_MARKET_STATE";
140 return "INVALID_TICK_SIZE";
142 return "INVALID_QTY";
144 return "INVALID_MIN_QTY";
146 return "CLIENT_ORDER_ID_ALREADY_EXISTS";
148 return "FOK_CANNOT_FILL";
150 return "LICENSE_REQUIRED";
151 }
152 return std::format("UNHANDLED OrdRejectReason ({0})", static_cast<std::underlying_type<OrdRejectReason>::type>(reject));
153}
154
176
177inline std::string to_string(CxlRejectReason reject) {
178 switch (reject) {
180 return "NONE";
182 return "UNKNOWN";
184 return "MARKET_CLOSED";
186 return "MARKET_HALTED";
188 return "PREOPEN";
190 return "ORDER_NOT_FOUND";
192 return "INVALID_DISPLAY_QTY";
194 return "ICEBERG_REQUEST_ON_NON_ICEBERG";
196 return "NON_ICEBERG_REQUEST_ON_ICEBERG";
198 return "ORDER_TYPE_MISMATCH";
200 return "TIME_IN_FORCE_MISMATCH";
202 return "PRICE_CANT_BE_BELOW_STOP_PRICE";
204 return "PRICE_CANT_BE_ABOVE_STOP_PRICE";
206 return "STOP_PRICE_MUST_BE_BELOW_LAST_TRADE_PRICE";
208 return "STOP_PRICE_MUST_BE_ABOVE_LAST_TRADE_PRICE";
210 return "INVALID_TICK_SIZE";
212 return "INVALID_QTY";
214 return "INVALID_MIN_QTY";
216 return "INTERCEPTED";
217 }
218 return std::format("UNHANDLED CxlRejectReason ({0})", static_cast<std::underlying_type<CxlRejectReason>::type>(reject));
219}
220
221#pragma pack(push, 1)
223
238
251
259
261 char user_id[37];
262 char order_id[37];
264};
265
267 uint8_t channel;
268 void* client;
269};
270
293
329
330struct Trade {
331 uint64_t order_id;
333};
334
345
347#pragma pack(pop)
348
349// setOrderIdentity() copies an order's OrderIdentity over the head of an
350// OrderResponse in one go, which is only valid while the two layouts agree byte
351// for byte. Adding, reordering or resizing a field at either end fails the build
352// here rather than silently shifting the ids on the wire.
353static_assert(std::is_standard_layout_v<OrderResponse>);
354static_assert(offsetof(OrderResponse, symbol) == offsetof(OrderIdentity, symbol));
355static_assert(offsetof(OrderResponse, user_id) == offsetof(OrderIdentity, user_id));
356static_assert(offsetof(OrderResponse, client_order_id) == offsetof(OrderIdentity, client_order_id));
357static_assert(offsetof(OrderResponse, order_id) == offsetof(OrderIdentity, order_id));
358static_assert(sizeof(OrderResponse::symbol) == decltype(OrderIdentity::symbol)::buffer_size());
359static_assert(sizeof(OrderResponse::user_id) == decltype(OrderIdentity::user_id)::buffer_size());
360static_assert(sizeof(OrderResponse::client_order_id) == decltype(OrderIdentity::client_order_id)::buffer_size());
361static_assert(sizeof(OrderResponse::order_id) == decltype(OrderIdentity::order_id)::buffer_size());
362static_assert(offsetof(OrderResponse, error_message) == sizeof(OrderIdentity));
363
368inline void setOrderIdentity(OrderResponse &response, const Order &order) noexcept {
369 // void*: OrderResponse is trivially copyable, GCC's -Wclass-memaccess just trips on its
370 // default member initializers.
371 std::memcpy(static_cast<void *>(&response), static_cast<const OrderIdentity *>(&order), sizeof(OrderIdentity));
372 response.order_num = order.id;
373 response.request_tag = order.request_tag;
374 response.aggressor = false;
375 // Readers copy error_message as a C string on rejects and cancels. Clear it because recycled
376 // response slots can retain reject text without a NUL terminator. Invalid text in the REST/WS
377 // JSON payload can make dump() throw and stop the gateway thread.
378 response.error_message[0] = '\0';
379}
380
401
402} // end namespace slick::sim
constexpr price_t NULL_PRICE
Definition types.hpp:28
uint_fast64_t time_t
Definition types.hpp:23
@ UNKNOWN_SIDE
Definition order.hpp:23
void setOrderIdentity(OrderResponse &response, const Order &order) noexcept
Fills a response's identity from an order: the symbol/user_id/client_order_id/ order_id header in one...
Definition messages.hpp:368
@ TIME_IN_FORCE_NOT_ALLOWED_IN_CURRENT_MARKET_STATE
Definition messages.hpp:92
constexpr const char * to_string(FeedState state) noexcept
int_fast64_t qty_t
Definition types.hpp:22
int_fast64_t price_t
Definition types.hpp:21
The four identity fields, stored inline in the order and width used by OrderResponse.
Definition order.hpp:288
utils::fixed_string< 32 > symbol
Definition order.hpp:289
utils::fixed_string< 37 > client_order_id
Definition order.hpp:291
utils::fixed_string< 37 > order_id
Definition order.hpp:292
utils::fixed_string< 37 > user_id
Definition order.hpp:290
uint64_t order_num
The order's numeric exchange id, Order::id - the same number the order carries in order-by-order mark...
Definition messages.hpp:321
OrdRejectReason reject_reason
Definition messages.hpp:312
uint64_t request_tag
request_tag of the request this response answers, or for a response no request triggered (a passive f...
Definition messages.hpp:324
bool aggressor
On a fill (ExecType::TRADE): whether this order was the aggressor - the one that crossed the spread -...
Definition messages.hpp:327
AddOrderMessage add_order
Definition messages.hpp:282
uint64_t request_tag
Opaque correlation token, carried onto the order and echoed on every OrderResponse that order produce...
Definition messages.hpp:280
CancelOrderMessage cancel_order
Definition messages.hpp:284
ModifyOrderMessage modify_order
Definition messages.hpp:283
MDSubscriptionMessage md_subscription
Definition messages.hpp:285
MessageType msg_type
Definition messages.hpp:274
TradeSummaryInfo()
One aggressor leg plus the resting legs it swept.
Definition messages.hpp:399
std::vector< Trade > Trades
Definition messages.hpp:393
qty_t phantom_qty
Portion of qty that was matched against phantom (market-mirroring) liquidity rather than the simulato...
Definition messages.hpp:391
#define SLICK_SIM_ZERO_SIZE_ARRAY_BEGIN
Definition types.hpp:15
#define SLICK_SIM_ZERO_SIZE_ARRAY_END
Definition types.hpp:16