order_book 0.3.0
Exchange feed order book that prints the best bid and offer
Loading...
Searching...
No Matches
feed.hpp
1#pragma once
2
3#include <cstdint>
4#include <expected>
5#include <string>
6#include <string_view>
7#include <variant>
8
9namespace order_book {
10
12using Price = std::uint32_t;
14using Shares = std::uint32_t;
17using Quantity = std::uint64_t;
18
20enum class Side : std::uint8_t {
21 Buy,
22 Sell,
23};
24
26struct AddOrder {
27 Side side;
28 Price price;
29 Shares shares;
31 friend bool operator==(const AddOrder&, const AddOrder&) = default;
32};
33
36 Shares shares;
38 friend bool operator==(const DecreaseOrder&, const DecreaseOrder&) = default;
39};
40
44 friend bool operator==(const DeleteOrder&, const DeleteOrder&) = default;
45};
46
49 Shares shares;
51 friend bool operator==(const ExecuteOrder&, const ExecuteOrder&) = default;
52};
53
55struct FillOrder {
57 friend bool operator==(const FillOrder&, const FillOrder&) = default;
58};
59
61struct NoOp {
63 friend bool operator==(const NoOp&, const NoOp&) = default;
64};
65
67using Event = std::variant<AddOrder, DecreaseOrder, DeleteOrder, ExecuteOrder, FillOrder, NoOp>;
68
70struct Message {
71 std::uint64_t time;
72 std::string_view ticker;
73 std::string_view order;
74 Event event;
75};
76
81[[nodiscard]] std::expected<Message, std::string> parse_line(std::string_view line);
82
83} // namespace order_book
B or S: add a resting order.
Definition feed.hpp:26
Side side
Side the order rests on.
Definition feed.hpp:27
friend bool operator==(const AddOrder &, const AddOrder &)=default
Memberwise equality.
Price price
Limit price.
Definition feed.hpp:28
C: decrease the order to shares; no effect unless smaller, removes the order at 0.
Definition feed.hpp:35
friend bool operator==(const DecreaseOrder &, const DecreaseOrder &)=default
Memberwise equality.
D: delete the order.
Definition feed.hpp:42
friend bool operator==(const DeleteOrder &, const DeleteOrder &)=default
Every delete is equal.
E: execute shares of the order, clamped to what remains; removes the order at 0.
Definition feed.hpp:48
friend bool operator==(const ExecuteOrder &, const ExecuteOrder &)=default
Memberwise equality.
F: fill, and so remove, the order.
Definition feed.hpp:55
friend bool operator==(const FillOrder &, const FillOrder &)=default
Every fill is equal.
One feed line. ticker and order view the parsed line and dangle once it goes away.
Definition feed.hpp:70
Event event
Effect on the order.
Definition feed.hpp:74
std::string_view order
Order ID, unique among live orders.
Definition feed.hpp:73
std::string_view ticker
Stock symbol.
Definition feed.hpp:72
std::uint64_t time
Milliseconds since midnight.
Definition feed.hpp:71
T or X: a trade that does not touch the book.
Definition feed.hpp:61
friend bool operator==(const NoOp &, const NoOp &)=default
Every no-op is equal.