Slick OrderBook 1.1.0
High-Performance C++23 OrderBook Library
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1// Copyright 2026 Slick Quant
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
7#include <cstdint>
8#include <string_view>
9#include <limits>
10
12
13// Core numeric types with strong typing for performance and safety
14
18using Price = int64_t;
19
21using Quantity = int64_t;
22
24using OrderId = uint64_t;
25
27using SymbolId = uint16_t;
28
30using Timestamp = uint64_t;
31
32constexpr uint16_t INVALID_INDEX = std::numeric_limits<uint16_t>::max();
33
35enum Side : uint8_t {
36 Buy = 0,
37 Sell = 1,
38 SideCount = 2 // Helper for array sizing
39};
40
42enum class OrderType : uint8_t {
43 Limit, // Limit order
44 Market, // Market order
45 Stop, // Stop order
46 StopLimit // Stop-limit order
47};
48
50struct Symbol {
51 SymbolId id; // Unique identifier
52 std::string_view name; // Symbol name (non-owning view for performance)
53
54 constexpr Symbol() noexcept : id(0), name() {}
55 constexpr Symbol(SymbolId id_, std::string_view name_) noexcept
56 : id(id_), name(name_) {}
57
58 [[nodiscard]] constexpr bool operator==(const Symbol& other) const noexcept {
59 return id == other.id;
60 }
61
62 [[nodiscard]] constexpr bool operator!=(const Symbol& other) const noexcept {
63 return !(*this == other);
64 }
65};
66
68
69[[nodiscard]] constexpr const char* toString(Side side) noexcept {
70 switch (side) {
71 case Buy: return "Buy";
72 case Sell: return "Sell";
73 default: return "Unknown";
74 }
75}
76
77[[nodiscard]] constexpr Side opposite(Side side) noexcept {
78 return side == Buy ? Sell : Buy;
79}
80
82
83[[nodiscard]] constexpr const char* toString(OrderType type) noexcept {
84 switch (type) {
85 case OrderType::Limit: return "Limit";
86 case OrderType::Market: return "Market";
87 case OrderType::Stop: return "Stop";
88 case OrderType::StopLimit: return "StopLimit";
89 default: return "Unknown";
90 }
91}
92
#define SLICK_NAMESPACE_END
Definition config.hpp:127
#define SLICK_NAMESPACE_BEGIN
Definition config.hpp:126
OrderType
Order type.
Definition types.hpp:42
int64_t Quantity
Quantity type - volume or size.
Definition types.hpp:21
int64_t Price
Price type - fixed-point representation Example: For 4 decimal places, price = actual_price * 10000 T...
Definition types.hpp:18
uint64_t OrderId
Unique order identifier.
Definition types.hpp:24
Side
Order side - using enum for easy array indexing.
Definition types.hpp:35
constexpr const char * toString(Side side) noexcept
Helper functions for Side enum.
Definition types.hpp:69
constexpr Side opposite(Side side) noexcept
Definition types.hpp:77
constexpr uint16_t INVALID_INDEX
Definition types.hpp:32
uint16_t SymbolId
Symbol identifier - can be hash or sequential ID.
Definition types.hpp:27
uint64_t Timestamp
Timestamp in nanoseconds since epoch.
Definition types.hpp:30
Symbol information.
Definition types.hpp:50
std::string_view name
Definition types.hpp:52
constexpr Symbol(SymbolId id_, std::string_view name_) noexcept
Definition types.hpp:55
constexpr bool operator!=(const Symbol &other) const noexcept
Definition types.hpp:62
constexpr Symbol() noexcept
Definition types.hpp:54
constexpr bool operator==(const Symbol &other) const noexcept
Definition types.hpp:58