18 #ifndef ORDER_ENTRY_MESSAGES_HPP
19 #define ORDER_ENTRY_MESSAGES_HPP
26 #include "limit_order_book/structures.hpp"
47 if (username.length() !=
sizeof(
Username))
48 throw "username must have " + std::to_string(
sizeof(
Username)) +
" characters!";
50 std::copy(&username[0], &username[0] +
sizeof(
Username), arr.data());
63 if (password.length() !=
sizeof(
Password))
64 throw "password must have " + std::to_string(
sizeof(
Password)) +
" characters!";
66 std::copy(&password[0], &password[0] +
sizeof(
Password), arr.data());
71 enum class Side : char { Sell =
'S', Buy =
'B' };
80 stream << static_cast<char>(side);
94 return (-2 *
static_cast<bool>(
static_cast<char>(side) -
'B')) + 1;
107 return not (
static_cast<char>(side) -
'B');
129 return static_cast<Side>(
'S' - side * (
'S' -
'B'));
177 stream << static_cast<char>(uid);
218 std::ostream& stream,
222 <<
"length=" << header.length <<
","
223 <<
"uid='" << header.uid <<
"',"
224 <<
"sequence=" << header.sequence <<
")";
233 std::ostringstream stream;
237 } __attribute__ ((packed));
284 std::ostream& stream,
287 stream <<
"LoginRequest(header=" << message.
header <<
",username=\"";
288 stream.write(message.
username.data(), 4);
289 stream <<
"\",password=\"";
290 stream.write(message.
password.data(), 12);
300 std::ostringstream stream;
304 } __attribute__ ((packed));
314 AlreadyAuthorized =
'C',
325 stream << static_cast<char>(status);
356 std::ostream& stream,
359 stream <<
"LoginResponse("
360 <<
"header=" << message.
header <<
","
361 <<
"status='" << message.
status <<
"')";
370 std::ostringstream stream;
374 } __attribute__ ((packed));
403 std::ostream& stream,
406 stream <<
"LogoutRequest(header=" << message.
header <<
")";
415 std::ostringstream stream;
419 } __attribute__ ((packed));
429 Administrative =
'A',
430 ProtocolViolation =
'!'
440 stream << static_cast<char>(reason);
471 std::ostream& stream,
474 stream <<
"LogoutResponse(header=" << message.
header <<
","
475 <<
"reason='" << message.
reason <<
"')";
484 std::ostringstream stream;
488 } __attribute__ ((packed));
495 static constexpr
Price ORDER_PRICE_MARKET = 0;
537 std::ostream& stream,
540 stream <<
"OrderRequest(header=" << message.
header <<
","
541 <<
"price=" << message.
price <<
","
542 <<
"quantity=" << message.
quantity <<
","
543 <<
"side='" << message.
side <<
"')";
552 std::ostringstream stream;
556 } __attribute__ ((packed));
563 static constexpr
OrderID ORDER_ID_MARKET = 0;
565 static constexpr
OrderID ORDER_ID_REJECTED = 0;
576 stream << static_cast<char>(status);
615 std::ostream& stream,
618 stream <<
"OrderResponse(header=" << message.
header <<
","
619 <<
"order_id=" << message.
order_id <<
","
620 <<
"status='" << message.
status <<
"')";
629 std::ostringstream stream;
633 } __attribute__ ((packed));
666 std::ostream& stream,
669 stream <<
"CancelRequest(header=" << message.
header <<
","
670 <<
"order_id=" << message.
order_id <<
")";
679 std::ostringstream stream;
683 } __attribute__ ((packed));
699 stream << static_cast<char>(status);
738 std::ostream& stream,
741 stream <<
"CancelResponse(header=" << message.
header <<
","
742 <<
"order_id=" << message.
order_id <<
","
743 <<
"status='" << message.
status <<
"')";
752 std::ostringstream stream;
756 } __attribute__ ((packed));
807 std::ostream& stream,
810 stream <<
"ReplaceRequest(header=" << message.
header <<
","
811 <<
"order_id=" << message.
order_id <<
","
812 <<
"price=" << message.
price <<
","
813 <<
"quantity=" << message.
quantity <<
","
814 <<
"side='" << message.
side <<
"')";
823 std::ostringstream stream;
827 } __attribute__ ((packed));
843 stream << static_cast<char>(status);
887 std::ostream& stream,
890 stream <<
"ReplaceResponse(header=" << message.
header <<
","
891 <<
"canceled=" << message.
canceled <<
","
893 <<
"status='" << message.
status <<
"')";
902 std::ostringstream stream;
906 } __attribute__ ((packed));
935 std::ostream& stream,
938 stream <<
"PurgeRequest(header=" << message.
header <<
")";
947 std::ostringstream stream;
951 } __attribute__ ((packed));
967 stream << static_cast<char>(status);
998 std::ostream& stream,
1001 stream <<
"PurgeResponse(header=" << message.
header <<
","
1002 <<
"status='" << message.
status <<
"')";
1011 std::ostringstream stream;
1013 return stream.str();
1015 } __attribute__ ((packed));
1071 std::ostream& stream,
1074 stream <<
"TradeResponse(header=" << message.
header <<
","
1075 <<
"order_id=" << message.
order_id <<
","
1076 <<
"price=" << message.
price <<
","
1077 <<
"quantity=" << message.
quantity <<
","
1079 <<
"side='" << message.
side <<
"')";
1088 std::ostringstream stream;
1090 return stream.str();
1092 } __attribute__ ((packed));
1098 #endif // ORDER_ENTRY_MESSAGES_HPP
const OrderID order_id
the order ID of the order to cancel
Definition: messages.hpp:648
ReplaceResponse(SequenceNumber sequence, OrderID canceled_, OrderID new_order_id_, ReplaceStatus status_)
Initialize a new order response message.
Definition: messages.hpp:869
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:369
constexpr Side bool_to_side(bool side)
Convert a boolean to an order side.
Definition: messages.hpp:124
LoginRequest(SequenceNumber sequence, Username username_, Password password_)
Initialize a new login request.
Definition: messages.hpp:262
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:1010
const CancelStatus status
whether the cancel was accepted
Definition: messages.hpp:714
Logic for sending/receiving application messages in a financial market.
Definition: authorizer.hpp:26
const Header header
the header for the message
Definition: messages.hpp:919
std::array< char, 40 > Packet
Definition: messages.hpp:146
const ReplaceStatus status
the status of the newly created order
Definition: messages.hpp:860
const LogoutReason reason
the reason the reason the logout
Definition: messages.hpp:453
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:822
A request that indicates a client is attempting to create a new session.
Definition: messages.hpp:248
Password make_password(std::string password)
Make a password from the given input string.
Definition: messages.hpp:62
PurgeRequest(SequenceNumber sequence)
Initialize a new purge request message.
Definition: messages.hpp:925
const Header header
the header for the message
Definition: messages.hpp:504
A response describing the status of an order request.
Definition: messages.hpp:585
const Quantity quantity
the quantity of the order
Definition: messages.hpp:508
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:299
const LoginResponseStatus status
the status of the login request
Definition: messages.hpp:338
friend std::ostream & operator<<(std::ostream &stream, const ReplaceRequest &message)
Write the data from the message to a stream.
Definition: messages.hpp:806
const Header header
the header for the message
Definition: messages.hpp:451
const Side side
the side of the order
Definition: messages.hpp:510
const Price price
the price for the order
Definition: messages.hpp:506
OrderResponse(SequenceNumber sequence, OrderID order_id_, OrderStatus status_)
Initialize a new order response message.
Definition: messages.hpp:599
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:946
LogoutReason
Reasons that a user may have been logged out.
Definition: messages.hpp:426
CancelResponse(SequenceNumber sequence, OrderID order_id_, CancelStatus status_)
Initialize a new cancel response message.
Definition: messages.hpp:722
friend std::ostream & operator<<(std::ostream &stream, const ReplaceResponse &message)
Write the data from the message to a stream.
Definition: messages.hpp:886
friend std::ostream & operator<<(std::ostream &stream, const OrderResponse &message)
Write the data from the message to a stream.
Definition: messages.hpp:614
friend std::ostream & operator<<(std::ostream &stream, const CancelRequest &message)
Write the data from the message to a stream.
Definition: messages.hpp:665
const Username username
the user name of the connecting client
Definition: messages.hpp:252
A request to place a new limit / market order in the book.
Definition: messages.hpp:502
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:751
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:414
const PurgeStatus status
whether the purge was accepted
Definition: messages.hpp:980
const Header header
the header for the message
Definition: messages.hpp:250
const Price price
the price for the order
Definition: messages.hpp:773
CancelRequest(SequenceNumber sequence, OrderID order_id_)
Initialize a new cancel request message.
Definition: messages.hpp:655
A request that indicates a client is attempting to close an active session.
Definition: messages.hpp:385
uint32_t SequenceNumber
A type for sequence numbers.
Definition: messages.hpp:36
const OrderID new_order_id
the ID of the newly created order
Definition: messages.hpp:858
A response describing the cancellation of an active order in the book.
Definition: messages.hpp:708
const Header header
the header for the message
Definition: messages.hpp:1028
const Header header
the header for the message
Definition: messages.hpp:854
std::string password_string() const
Return a string representation of the password for the account.
Definition: messages.hpp:273
const Header header
the header for the message
Definition: messages.hpp:978
const Header header
the header for the message
Definition: messages.hpp:587
std::string username_string() const
Return a string representation of the user-name for the account.
Definition: messages.hpp:268
const Header header
the header for the message
Definition: messages.hpp:769
constexpr LOB::Side side_to_LOB_side(Side side)
Convert a side character to a LOB side value.
Definition: messages.hpp:115
LogoutResponse(SequenceNumber sequence, LogoutReason reason_)
Initialize a new logout response message.
Definition: messages.hpp:460
constexpr bool side_to_bool(Side side)
Convert an order side character to a boolean value.
Definition: messages.hpp:102
LogoutRequest(SequenceNumber sequence)
Initialize a new logout request message.
Definition: messages.hpp:393
const OrderID canceled
the ID of the newly created order
Definition: messages.hpp:856
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:678
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:628
const OrderID order_id
the ID for the order connected to the trade
Definition: messages.hpp:1030
A response that tells the status of a session destruction to the client.
Definition: messages.hpp:449
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:1087
PurgeStatus
Possible statuses for a purge response.
Definition: messages.hpp:958
const Price price
the price the trade executed at
Definition: messages.hpp:1032
const Quantity leaves_quantity
the number of shares that remain in the book
Definition: messages.hpp:1036
friend std::ostream & operator<<(std::ostream &stream, const LogoutResponse &message)
Write the data from the message to a stream.
Definition: messages.hpp:470
const OrderID order_id
the order ID of the order to cancel
Definition: messages.hpp:712
const Header header
the header for the message
Definition: messages.hpp:387
uint64_t TimeStamp
a type for timestamps
Definition: clock.hpp:28
friend std::ostream & operator<<(std::ostream &stream, const CancelResponse &message)
Write the data from the message to a stream.
Definition: messages.hpp:737
const Quantity quantity
the quantity of the order
Definition: messages.hpp:775
A request to replace an active order in the book with a new order.
Definition: messages.hpp:767
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:551
friend std::ostream & operator<<(std::ostream &stream, const LoginResponse &message)
Write the data from the message to a stream.
Definition: messages.hpp:355
LoginResponse(SequenceNumber sequence, LoginResponseStatus status_)
Initialize a new login response.
Definition: messages.hpp:345
std::ostream & operator<<(std::ostream &stream, const Side &side)
Write the order side to a stream.
Definition: messages.hpp:79
std::ostream & operator<<(std::ostream &stream, const MessageID &uid)
Write a template ID to a stream.
Definition: messages.hpp:176
const Quantity quantity
the number of shares that were exchanges
Definition: messages.hpp:1034
ReplaceRequest(SequenceNumber sequence, OrderID order_id_, Price price_, Quantity quantity_, Side side_)
Initialize a new order replace message.
Definition: messages.hpp:787
const OrderStatus status
the status of the newly created order
Definition: messages.hpp:591
friend std::ostream & operator<<(std::ostream &stream, const LoginRequest &message)
Write the data from the message to a stream.
Definition: messages.hpp:283
std::deque< Packet > PacketQueue
A type for queuing packet buffers.
Definition: messages.hpp:149
ReplaceStatus
Possible statuses for a replace response.
Definition: messages.hpp:834
std::array< char, 12 > Password
A type for passwords.
Definition: messages.hpp:55
A request to cancel all active orders in the book.
Definition: messages.hpp:917
Clock::TimeStamp TimeStamp
A forward a declaration for the Clock timestamp.
Definition: messages.hpp:33
LoginResponseStatus
Possible statuses for a login response.
Definition: messages.hpp:311
A response describing the status of canceling all active orders in the book.
Definition: messages.hpp:976
friend std::ostream & operator<<(std::ostream &stream, const PurgeRequest &message)
Write the data from the message to a stream.
Definition: messages.hpp:934
uint64_t OrderID
A type for order IDs.
Definition: messages.hpp:139
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:483
const Header header
the header for the message
Definition: messages.hpp:710
Side
the possible sides for the LimitTree
Definition: structures.hpp:37
A request to cancel an active limit order in the book.
Definition: messages.hpp:644
friend std::ostream & operator<<(std::ostream &stream, const TradeResponse &message)
Write the data from the message to a stream.
Definition: messages.hpp:1070
Username make_username(std::string username)
Make a username from the given input string.
Definition: messages.hpp:46
OrderRequest(SequenceNumber sequence, Price price_, Quantity quantity_, Side side_)
Initialize a new order request message.
Definition: messages.hpp:519
friend std::ostream & operator<<(std::ostream &stream, const LogoutRequest &message)
Write the data from the message to a stream.
Definition: messages.hpp:402
friend std::ostream & operator<<(std::ostream &stream, const OrderRequest &message)
Write the data from the message to a stream.
Definition: messages.hpp:536
uint32_t Quantity
A type for order quantities.
Definition: messages.hpp:133
const Side side
the original side of the order
Definition: messages.hpp:1038
TradeResponse(SequenceNumber sequence, OrderID order_id_, Price price_, Quantity quantity_, Quantity leaves_quantity_, Side side_)
Initialize a new trade response message.
Definition: messages.hpp:1049
PurgeResponse(SequenceNumber sequence, PurgeStatus status_)
Initialize a new purge response message.
Definition: messages.hpp:987
const Password password
the password for the connecting client
Definition: messages.hpp:254
friend std::ostream & operator<<(std::ostream &stream, const PurgeResponse &message)
Write the data from the message to a stream.
Definition: messages.hpp:997
A response that tells the status of a session creation to the client.
Definition: messages.hpp:334
uint64_t Price
A type for order prices.
Definition: messages.hpp:136
const Side side
the side of the order
Definition: messages.hpp:777
const OrderID order_id
the order ID of the order to replace
Definition: messages.hpp:771
std::string to_string() const
Convert the object to an STL string.
Definition: messages.hpp:901
MessageID
Message IDs for messages in the protocol.
Definition: messages.hpp:152
const OrderID order_id
the ID of the newly created order
Definition: messages.hpp:589
const Header header
the header for the message
Definition: messages.hpp:646
A response describing the replacement of an active order with a new order.
Definition: messages.hpp:852
Side
The side of an order.
Definition: messages.hpp:71
constexpr double side_to_double(Side side)
Convert an order side character to a double.
Definition: messages.hpp:89
CancelStatus
Possible statuses for a cancellation response.
Definition: messages.hpp:690
const Header header
the header for the message
Definition: messages.hpp:336
std::array< char, 4 > Username
A type for user names.
Definition: messages.hpp:39
OrderStatus
Possible statuses for an order response.
Definition: messages.hpp:567
A response describing a trade that occurred for a limit / market order.
Definition: messages.hpp:1026