Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
instrument_status_event.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <algorithm>
5#include <cstring>
6#include <string_view>
7#include <type_traits>
8
9namespace slick::trader {
10
11constexpr size_t MAX_STATUS_REASON_LENGTH = 32;
12
13// What an instrument's market is doing, as its exchange reports it.
14enum class TradingStatus : uint8_t {
15 UNKNOWN, // not reported, or something this does not model
16 PRE_OPEN, // orders are taken and nothing matches yet
17 OPEN, // continuous trading
18 HALTED, // trading is suspended
19 CLOSED, // not trading: outside its session, or expired
20};
21
22inline const char* to_string(TradingStatus status) {
23 switch (status) {
24 case TradingStatus::PRE_OPEN: return "PRE_OPEN";
25 case TradingStatus::OPEN: return "OPEN";
26 case TradingStatus::HALTED: return "HALTED";
27 case TradingStatus::CLOSED: return "CLOSED";
28 default: return "UNKNOWN";
29 }
30}
31
32// InstrumentStatusEvent - a change of an instrument's trading state, published by a
33// broker's market data connector (for CME, from MDP 3.0's security status). StrategyManager
34// forwards it to every strategy; what to do about a halt is the strategy's decision.
35#pragma pack(push, 1)
38 bool cancel_allowed; // false while the exchange refuses cancels, as before an opening cross
39 char reason[MAX_STATUS_REASON_LENGTH]; // The exchange's reason, as text; may be empty
40
47
48 void set_reason(std::string_view text) {
49 size_t len = std::min(text.size(), MAX_STATUS_REASON_LENGTH - 1);
50 std::memcpy(reason, text.data(), len);
51 reason[len] = '\0';
52 }
53};
54#pragma pack(pop)
55
56static_assert(std::is_trivially_copyable_v<InstrumentStatusEvent>, "InstrumentStatusEvent must be trivially copyable");
57
58} // namespace slick::trader
const char * to_string(BrokerId bid)
Definition event.hpp:78
constexpr size_t MAX_STATUS_REASON_LENGTH
Event(EventType t=EventType::TRADE)
Definition event.hpp:63