Leka
A low-latency C++20 price-time-priority limit order book and matching engine
▶ Replay viewer
Loading...
Searching...
No Matches
price.hpp
1// include/lob/types/price.hpp
2#ifndef PRICE_HPP
3#define PRICE_HPP
4#include <cstdint>
5#include <compare>
6
7namespace lob {
8/** @brief Type-safe nonzero price value used for price ordering. */
9class Price {
10 private:
11 std::uint64_t price;
12
13 public:
14 /** Constructs an invalid, zero-valued price. */
15 Price(): price(0){}
16
17 /** Constructs a price from its numeric value. */
18 Price(std::uint64_t price): price(price){}
19
20 /** Returns the underlying numeric price. */
21 std::uint64_t getPrice() const { return price;};
22
23 /** Compares prices chronologically by numeric value. */
24 auto operator<=>(const Price &other) const {
25 return this->price <=> other.price;
26 };
27 /** Returns whether the price is nonzero. */
28 bool isValid() const {
29 return price != 0;
30 };
31};
32} // namespace lob
33
34#endif
bool isValid() const
Returns whether the price is nonzero.
Definition price.hpp:28
Price()
Constructs an invalid, zero-valued price.
Definition price.hpp:15
std::uint64_t getPrice() const
Returns the underlying numeric price.
Definition price.hpp:21
auto operator<=>(const Price &other) const
Compares prices chronologically by numeric value.
Definition price.hpp:24
Price(std::uint64_t price)
Constructs a price from its numeric value.
Definition price.hpp:18