order_book
0.3.0
Exchange feed order book that prints the best bid and offer
Toggle main menu visibility
Loading...
Searching...
No Matches
order_book.hpp
1
#pragma once
2
3
#include <cstddef>
4
#include <cstdint>
5
#include <expected>
6
#include <functional>
7
#include <string>
8
#include <string_view>
9
10
#include <ankerl/unordered_dense.h>
11
12
#include <order_book/feed.hpp>
13
#include <order_book/levels.hpp>
14
15
namespace
order_book {
16
18
struct
StringHash
{
19
using
is_transparent
= void;
20
using
is_avalanching
= void;
22
[[nodiscard]] std::uint64_t
operator()
(std::string_view text)
const
noexcept
23
{
24
return
ankerl::unordered_dense::hash<std::string_view>{}(text);
25
}
26
};
27
29
enum class
BookError : std::uint8_t {
30
DuplicateOrder,
31
UnknownOrder,
32
};
33
42
class
OrderBook
{
43
public
:
47
[[nodiscard]] std::expected<bool, BookError>
apply
(std::string_view order,
const
Event& event);
49
[[nodiscard]]
Bbo
bbo
()
const
;
51
[[nodiscard]] std::size_t
order_count
()
const
{
return
m_orders.size(); }
53
[[nodiscard]] std::size_t
level_count
()
const
{
return
m_levels.size(); }
54
55
private
:
56
struct
Order {
57
Shares remaining;
58
std::uint32_t level;
59
};
60
61
std::expected<bool, BookError> add(std::string_view order,
const
AddOrder& add);
62
63
BookLevels m_book;
64
LevelPool m_levels;
65
ankerl::unordered_dense::map<std::string, Order, StringHash, std::equal_to<>> m_orders;
66
};
67
68
}
// namespace order_book
order_book::OrderBook
Definition
order_book.hpp:42
order_book::OrderBook::order_count
std::size_t order_count() const
Number of resting orders on both sides.
Definition
order_book.hpp:51
order_book::OrderBook::apply
std::expected< bool, BookError > apply(std::string_view order, const Event &event)
order_book::OrderBook::level_count
std::size_t level_count() const
Number of price levels on both sides.
Definition
order_book.hpp:53
order_book::OrderBook::bbo
Bbo bbo() const
Current best bid and offer.
order_book::Bbo
Best bid and offer; an empty side has no level.
Definition
levels.hpp:21
order_book::StringHash
Hash that lets string-keyed unordered containers look up a std::string_view without a copy.
Definition
order_book.hpp:18
order_book::StringHash::operator()
std::uint64_t operator()(std::string_view text) const noexcept
Hash of the characters, equal for a std::string and a view of it.
Definition
order_book.hpp:22
order_book::StringHash::is_transparent
void is_transparent
Enables heterogeneous lookup.
Definition
order_book.hpp:19
order_book::StringHash::is_avalanching
void is_avalanching
Definition
order_book.hpp:20
include
order_book
order_book.hpp
Generated by
1.17.0