BetaTrader
A HFT Eco-System
Loading...
Searching...
No Matches
CommandType.h
Go to the documentation of this file.
1#pragma once
2#include <array>
3#include <cstdint>
4#include <stdexcept>
5#include <string_view>
6
7namespace trading_core {
13 enum class CommandType : uint8_t {
14 NewOrder,
17 COUNT
18 };
19
23 constexpr std::array<std::string_view,
24 static_cast<size_t>(CommandType::COUNT)>
25 command_type_names = {"NewOrder", "CancelOrder", "ModifyOrder"};
26
32 inline std::string to_string(CommandType type)
33 {
34 return std::string(command_type_names[static_cast<size_t>(type)]);
35 }
36
43 inline CommandType from_string(std::string_view name)
44 {
45 for (size_t i = 0; i < command_type_names.size(); ++i)
46 if (command_type_names[i] == name)
47 return static_cast<CommandType>(i);
48 throw std::invalid_argument("Unknown command type name");
49 }
50} // namespace trading_core
A command to cancel an existing order in the trading engine.
Definition CancelOrder.h:18
A command to modify an existing order in the trading engine.
Definition ModifyOrder.h:20
A command to submit a new order to the trading engine.
Definition NewOrder.h:19
Definition CancelOrder.h:10
std::string to_string(CommandType type)
Converts a CommandType enum to its string representation.
Definition CommandType.h:32
constexpr std::array< std::string_view, static_cast< size_t >(CommandType::COUNT)> command_type_names
An array of string representations for the CommandType enum.
Definition CommandType.h:25
CommandType
Represents the different types of commands that can be processed by the trading engine.
Definition CommandType.h:13
@ COUNT
Helper to get the number of command types.
CommandType from_string(std::string_view name)
Converts a string to its corresponding CommandType enum.
Definition CommandType.h:43