CBOE Emulator  1.0
structures.hpp
1 // Types and structures for the LimitOrderBook: order, limit
2 // Copyright 2020 Christian Kauten
3 //
4 // Author: Christian Kauten (kautenja@auburn.edu)
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef DATA_FEED_LIMIT_ORDER_BOOK_STRUCTURES_HPP
19 #define DATA_FEED_LIMIT_ORDER_BOOK_STRUCTURES_HPP
20 
21 #include "doubly_linked_list.hpp"
22 #include "binary_search_tree.hpp"
23 #include <cstdint>
24 
26 namespace DataFeed {
27 
29 namespace LOB {
30 
32 enum class Side : bool { Sell = false, Buy = true };
33 
39 inline Side operator!(Side side) {
40  return static_cast<Side>(!static_cast<bool>(side));
41 }
42 
44 typedef uint64_t UID;
46 typedef uint32_t Quantity;
48 typedef uint64_t Price;
49 
50 // forward declare the `Limit` structure so `Order` can reference it
51 struct Limit;
52 
54 struct Order : DLL::Node {
56  const UID uid = 0;
58  const Side side = Side::Sell;
62  const Price price = 0;
64  Limit* limit = nullptr;
65 
67  Order() : DLL::Node() { }
68 
76  Order(UID uid_, Side side_, Quantity quantity_, Price price_) :
77  DLL::Node(),
78  uid(uid_),
79  side(side_),
80  quantity(quantity_),
81  price(price_) { }
82 };
83 
85 typedef uint32_t Count;
87 typedef uint64_t Volume;
88 
90 struct Limit : BST::Node<Price> {
92  Count count = 0;
94  const uint32_t _padding = 0;
98  Order* order_head = nullptr;
100  Order* order_tail = nullptr;
101 
103  Limit() : BST::Node<Price>() { }
104 
109  explicit Limit(Order* order) :
110  BST::Node<Price>(order->price),
111  count(1),
112  volume(order->quantity),
113  order_head(order),
114  order_tail(order) { }
115 };
116 
117 } // namespace LOB
118 
119 } // namespace DataFeed
120 
121 #endif // DATA_FEED_LIMIT_ORDER_BOOK_STRUCTURES_HPP
DataFeed::LOB::Order::quantity
Quantity quantity
the number of shares in the order
Definition: structures.hpp:60
DataFeed::LOB::Order::Order
Order(UID uid_, Side side_, Quantity quantity_, Price price_)
Initialize a new order data.
Definition: structures.hpp:76
DataFeed::LOB::Order::uid
const UID uid
the day-unique ID for this particular order
Definition: structures.hpp:56
DataFeed::LOB::Order::side
const Side side
a boolean determining whether the order id a buy (true) or sell (false)
Definition: structures.hpp:58
DataFeed::LOB::Limit::count
Count count
the number of orders at this limit price
Definition: structures.hpp:92
DataFeed::LOB::Side
Side
the possible sides for the LimitTree
Definition: structures.hpp:32
DataFeed::LOB::Volume
uint64_t Volume
a type for limit total volume
Definition: structures.hpp:87
DataFeed::LOB::Limit::Limit
Limit(Order *order)
Initialize a new limit data.
Definition: structures.hpp:109
DataFeed::LOB::Limit::order_tail
Order * order_tail
the last order in the queue (last to execute)
Definition: structures.hpp:100
DataFeed::LOB::Limit::Limit
Limit()
Initialize a new limit data.
Definition: structures.hpp:103
DataFeed
Logic for sending and receiving messages on a financial data feed.
Definition: heartbeat.hpp:28
DataFeed::LOB::Order
A single order in the LimitOrderBook.
Definition: structures.hpp:54
DataFeed::LOB::Limit::order_head
Order * order_head
the first order in the queue (next to execute)
Definition: structures.hpp:98
DataFeed::LOB::Limit
A price limit containing a FIFO queue of Order objects.
Definition: structures.hpp:90
DataFeed::LOB::Quantity
uint32_t Quantity
a type for order quantities
Definition: structures.hpp:46
DataFeed::LOB::UID
uint64_t UID
a type for order IDs
Definition: structures.hpp:44
DataFeed::LOB::Price
uint64_t Price
a type for order prices
Definition: structures.hpp:48
DataFeed::LOB::operator!
Side operator!(Side side)
Return the opposite side using the invert operator.
Definition: structures.hpp:39
DataFeed::LOB::Order::price
const Price price
the limit price for the order (market price if market order)
Definition: structures.hpp:62
DataFeed::LOB::Count
uint32_t Count
a type for limit price order counts
Definition: structures.hpp:85
DataFeed::LOB::Limit::volume
Volume volume
the total amount of volume at this limit price (sum of order shares)
Definition: structures.hpp:96
DataFeed::LOB::Order::limit
Limit * limit
the limit this order falls under
Definition: structures.hpp:64
DataFeed::LOB::Limit::_padding
const uint32_t _padding
padding for byte alignment
Definition: structures.hpp:94
DataFeed::LOB::Order::Order
Order()
Initialize a new order data.
Definition: structures.hpp:67