BetaTrader
A HFT Eco-System
Loading...
Searching...
No Matches
Instrument.h
Go to the documentation of this file.
1//
2// Created by sujal on 29-10-2025.
3//
4
5#pragma once
6#include <array>
7#include <cstdint>
8#include <stdexcept>
9#include <string_view>
10
11namespace common {
12
17 enum class Instrument : uint8_t {
18 EURUSD,
19 USDJPY,
20 GBPUSD,
21 USDCAD,
22 USDINR,
23 EURINR,
24 GBPINR,
25 AUDUSD,
26 USDMXN,
27 COUNT
28 };
29
33 constexpr std::array<std::string_view,
34 static_cast<size_t>(Instrument::COUNT)>
35 symbol_names = {"EURUSD", "USDJPY", "GBPUSD", "USDCAD", "USDINR",
36 "EURINR", "GBPINR", "AUDUSD", "USDMXN"};
37
43 inline std::string to_string(Instrument symbol)
44 {
45 return std::string(symbol_names[static_cast<size_t>(symbol)]);
46 }
47
54 inline Instrument from_string(std::string_view name)
55 {
56 for (size_t i = 0; i < symbol_names.size(); ++i)
57 if (symbol_names[i] == name) return static_cast<Instrument>(i);
58 throw std::invalid_argument("Unknown symbol name");
59 }
60
61} // namespace common
Definition Instrument.h:11
Instrument from_string(std::string_view name)
Converts a string to its corresponding Instrument enum.
Definition Instrument.h:54
Instrument
Represents the financial instruments available for trading.
Definition Instrument.h:17
@ AUDUSD
Australian Dollar / US Dollar.
@ EURINR
Euro / Indian Rupee.
@ GBPUSD
British Pound / US Dollar.
@ USDMXN
US Dollar / Mexican Peso.
@ COUNT
Helper to get the number of instruments.
@ USDINR
US Dollar / Indian Rupee.
@ GBPINR
British Pound / Indian Rupee.
@ EURUSD
Euro / US Dollar.
@ USDCAD
US Dollar / Canadian Dollar.
@ USDJPY
US Dollar / Japanese Yen.
std::string to_string(Instrument symbol)
Converts an Instrument enum to its string representation.
Definition Instrument.h:43
constexpr std::array< std::string_view, static_cast< size_t >(Instrument::COUNT)> symbol_names
An array of string representations for the Instrument enum.
Definition Instrument.h:35