Slick Trader
0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
shared_top_of_book.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
slick-trader/utils/types.hpp
>
4
#include <atomic>
5
#include <cstddef>
6
#include <deque>
7
#include <limits>
8
9
namespace
slick::trader
{
10
11
// One instrument's best bid and offer, as a broker's market data worker last built
12
// them, for its order worker to read. A post-only order is checked against it when
13
// the exchange has no post-only instruction of its own.
14
//
15
// Each side is one atomic: the market data worker stores, the order worker loads,
16
// neither waits. An order looks at the one side it could cross, so the two need not be
17
// consistent with each other. Its own cache line, so the market data worker writing
18
// one instrument does not take the line the order worker is reading another from.
19
struct
alignas
(64)
SharedTopOfBook
{
20
// The book is not in sequence: being built, or rebuilt after a gap.
21
static
constexpr
price_t
UNKNOWN
= std::numeric_limits<price_t>::min();
22
// The side has no orders.
23
static
constexpr
price_t
EMPTY
=
NULL_PRICE
;
24
25
std::atomic<price_t>
bid
{
UNKNOWN
};
26
std::atomic<price_t>
ask
{
UNKNOWN
};
27
};
28
29
// Every instrument's SharedTopOfBook. An entry never moves once allocated, so a pointer
30
// handed to another thread stays good for as long as the store lives. allocate() is for
31
// one thread alone: whichever learns the instruments.
32
class
SharedTopOfBookStore
{
33
public
:
34
SharedTopOfBook
*
allocate
() {
return
&tops_.emplace_back(); }
35
[[nodiscard]]
size_t
size
() const noexcept {
return
tops_.size(); }
36
37
private
:
38
std::deque<SharedTopOfBook> tops_;
39
};
40
41
}
// namespace slick::trader
slick::trader::SharedTopOfBookStore
Definition
shared_top_of_book.hpp:32
slick::trader::SharedTopOfBookStore::size
size_t size() const noexcept
Definition
shared_top_of_book.hpp:35
slick::trader::SharedTopOfBookStore::allocate
SharedTopOfBook * allocate()
Definition
shared_top_of_book.hpp:34
slick::trader
Definition
coinbase_broker.hpp:11
slick::trader::NULL_PRICE
constexpr price_t NULL_PRICE
Definition
types.hpp:19
slick::trader::price_t
int64_t price_t
Definition
types.hpp:16
slick::trader::SharedTopOfBook
Definition
shared_top_of_book.hpp:19
slick::trader::SharedTopOfBook::ask
std::atomic< price_t > ask
Definition
shared_top_of_book.hpp:26
slick::trader::SharedTopOfBook::EMPTY
static constexpr price_t EMPTY
Definition
shared_top_of_book.hpp:23
slick::trader::SharedTopOfBook::bid
std::atomic< price_t > bid
Definition
shared_top_of_book.hpp:25
slick::trader::SharedTopOfBook::UNKNOWN
static constexpr price_t UNKNOWN
Definition
shared_top_of_book.hpp:21
types.hpp
slick-trader
brokers
common
shared_top_of_book.hpp
Generated by
1.15.0