BetaTrader
A HFT Eco-System
Loading...
Searching...
No Matches
Types.h
Go to the documentation of this file.
1//
2// Created by sujal on 21-10-2025.
3//
4
5#pragma once
6#include "Instrument.h"
7#include <array>
8#include <cstdint>
9#include <stdexcept>
10#include <string>
11
12namespace common {
17 enum class OrderSide : uint8_t {
18 Buy,
19 Sell,
20 };
21
26 enum class OrderType : uint8_t {
27 Limit,
29 Market,
31 Stop,
35 };
36
41 enum class OrderStatus : uint8_t {
42 New,
44 Filled,
45 Cancelled,
48 };
49
54 enum class TimeInForce : uint8_t {
55 DAY,
56 GTC,
57 IOC,
58 FOK,
59 MOO,
60 MOC,
61 };
62
63 // --- OrderSide Serialization ---
64 constexpr std::array<std::string_view, 2> order_side_names
65 = {"Buy", "Sell"};
66
67 inline std::string to_string(OrderSide side)
68 {
69 return std::string(order_side_names[static_cast<size_t>(side)]);
70 }
71
72 inline OrderSide from_string_OrderSide(std::string_view name)
73 {
74 for (size_t i = 0; i < order_side_names.size(); ++i)
75 if (order_side_names[i] == name) return static_cast<OrderSide>(i);
76 throw std::invalid_argument("Unknown OrderSide name");
77 }
78
79 // --- OrderType Serialization ---
80 constexpr std::array<std::string_view, 2> order_type_names
81 = {"Limit", "Market"};
82
83 inline std::string to_string(OrderType type)
84 {
85 return std::string(order_type_names[static_cast<size_t>(type)]);
86 }
87
88 inline OrderType from_string_OrderType(std::string_view name)
89 {
90 for (size_t i = 0; i < order_type_names.size(); ++i)
91 if (order_type_names[i] == name) return static_cast<OrderType>(i);
92 throw std::invalid_argument("Unknown OrderType name");
93 }
94
95 // --- OrderStatus Serialization ---
96 constexpr std::array<std::string_view, 5> order_status_names
97 = {"New", "PartiallyFilled", "Filled", "Cancelled", "Rejected"};
98
99 inline std::string to_string(OrderStatus status)
100 {
101 return std::string(order_status_names[static_cast<size_t>(status)]);
102 }
103
104 inline OrderStatus from_string_OrderStatus(std::string_view name)
105 {
106 for (size_t i = 0; i < order_status_names.size(); ++i)
107 if (order_status_names[i] == name)
108 return static_cast<OrderStatus>(i);
109 throw std::invalid_argument("Unknown OrderStatus name");
110 }
111
112 // --- TimeInForce Serialization ---
113 constexpr std::array<std::string_view, 6> time_in_force_names
114 = {"DAY", "GTC", "IOC", "FOK", "MOO", "MOC"};
115
116 inline std::string to_string(TimeInForce tif)
117 {
118 return std::string(time_in_force_names[static_cast<size_t>(tif)]);
119 }
120
121 inline TimeInForce from_string_TimeInForce(std::string_view name)
122 {
123 for (size_t i = 0; i < time_in_force_names.size(); ++i)
124 if (time_in_force_names[i] == name)
125 return static_cast<TimeInForce>(i);
126 throw std::invalid_argument("Unknown TimeInForce name");
127 }
128
130 using Price = double;
132 using Quantity = uint64_t;
134 using OrderID = uint64_t;
136 using TradeID = uint64_t;
140 using ClientID = std::string;
142 using SessionID = uint64_t;
143} // namespace common
Definition Instrument.h:11
OrderSide from_string_OrderSide(std::string_view name)
Definition Types.h:72
constexpr std::array< std::string_view, 5 > order_status_names
Definition Types.h:97
OrderStatus from_string_OrderStatus(std::string_view name)
Definition Types.h:104
double Price
A type alias for price values.
Definition Types.h:130
Instrument
Represents the financial instruments available for trading.
Definition Instrument.h:17
OrderType from_string_OrderType(std::string_view name)
Definition Types.h:88
OrderType
Represents the execution logic of an order.
Definition Types.h:26
std::string to_string(Instrument symbol)
Converts an Instrument enum to its string representation.
Definition Instrument.h:43
uint64_t OrderID
A type alias for unique order identifiers.
Definition Types.h:134
uint64_t TradeID
A type alias for unique trade identifiers.
Definition Types.h:136
uint64_t Quantity
A type alias for quantity values.
Definition Types.h:132
TimeInForce
Guides How long the order is in the system.
Definition Types.h:54
@ MOC
Market on Close.
@ DAY
Keep the order in the system for a day.
@ IOC
Immediate or cancel.
@ GTC
Good till cancellation.
@ FOK
Fill or kill.
@ MOO
Market on Open.
TimeInForce from_string_TimeInForce(std::string_view name)
Definition Types.h:121
std::string ClientID
A type alias for client identifiers.
Definition Types.h:140
OrderStatus
Represents the lifecycle of an order.
Definition Types.h:41
@ New
The order has been created but not yet matched.
@ PartiallyFilled
The order has been partially matched.
@ Cancelled
The order has been cancelled before being fully matched.
@ Filled
The order has been fully matched.
constexpr std::array< std::string_view, 2 > order_side_names
Definition Types.h:65
constexpr std::array< std::string_view, 6 > time_in_force_names
Definition Types.h:114
uint64_t SessionID
A type alias for session identifiers.
Definition Types.h:142
OrderSide
Represents the side of an order (Buy or Sell).
Definition Types.h:17
@ Sell
a sell order.
@ Buy
A buy order.
constexpr std::array< std::string_view, 2 > order_type_names
Definition Types.h:81