16#include "fastmm/core/config_macros.hpp"
20#include "fastmm/core/msg_ring.hpp"
70 enum Flags : std::uint8_t {
97static_assert(
sizeof(
RecordHeader) == 64 && std::is_trivially_copyable_v<RecordHeader>);
126static_assert(
sizeof(
FillRecord) == 256 && std::is_trivially_copyable_v<FillRecord>);
127static_assert(offsetof(
FillRecord, venue_order_id) == 168 && offsetof(
FillRecord, exec_id) == 209);
139static_assert(
sizeof(
OrderRecord) == 192 && std::is_trivially_copyable_v<OrderRecord>);
153static_assert(
sizeof(
PositionRecord) == 192 && std::is_trivially_copyable_v<PositionRecord>);
169static_assert(
sizeof(
FundingRecord) == 192 && std::is_trivially_copyable_v<FundingRecord>);
185static_assert(
sizeof(
KillRecord) == 128 && std::is_trivially_copyable_v<KillRecord>);
195static_assert(
sizeof(
ReplayedRecord) == 64 && std::is_trivially_copyable_v<ReplayedRecord>);
218static_assert(
sizeof(ParamRecord) ==
sizeof(ParamUpdateMsg) &&
219 std::is_trivially_copyable_v<ParamRecord>);
220static_assert(offsetof(ParamRecord, count) == offsetof(ParamUpdateMsg, count) &&
221 offsetof(ParamRecord, origin) == offsetof(ParamUpdateMsg, origin) &&
222 offsetof(ParamRecord, publish_seq) == offsetof(ParamUpdateMsg, publish_seq) &&
223 offsetof(ParamRecord, field) == offsetof(ParamUpdateMsg, field) &&
224 offsetof(ParamRecord, source) == offsetof(ParamUpdateMsg, source) &&
225 offsetof(ParamRecord, value) == offsetof(ParamUpdateMsg, value));
246 return "risk_bucket";
248 return "account_paused";
250 return "account_orders_10s";
252 return "account_orders_1m";
254 return "account_orders_1d";
256 return "venue_local";
271 static constexpr std::int64_t
kFoldNs = 100'000'000;
305static_assert(
sizeof(
RejectRecord) == 256 && std::is_trivially_copyable_v<RejectRecord>);
311 explicit RecordWriter(MsgRing* ring =
nullptr, std::uint64_t session_id = 0) noexcept
312 : ring_(ring), session_id_(session_id) {}
314 [[nodiscard]]
bool enabled() const noexcept {
return ring_ !=
nullptr; }
315 [[nodiscard]] std::uint64_t
written() const noexcept {
return written_; }
316 [[nodiscard]] std::uint64_t
dropped() const noexcept {
return dropped_; }
319 if (ring_ ==
nullptr)
return true;
320 std::byte* p = ring_->try_reserve(r.len);
321 if (FASTMM_UNLIKELY(p ==
nullptr)) {
325 std::memcpy(p, &r, r.len);
329 h->session_id = session_id_;
337 FASTMM_FORCE_INLINE
void init(R& r,
343 static_assert(std::is_trivially_copyable_v<R> &&
sizeof(R) % 64 == 0);
345 r.hdr.
len =
static_cast<std::uint32_t
>(
sizeof(R));
348 r.hdr.instrument = inst;
350 r.hdr.engine_ts = engine_ts;
351 r.hdr.wall_ts = wall_ts;
356 std::uint64_t session_id_;
357 std::uint64_t written_ = 0;
358 std::uint64_t dropped_ = 0;
Engine-side producer.
Definition record_stream.hpp:311
bool enabled() const noexcept
Definition record_stream.hpp:316
FASTMM_FORCE_INLINE bool put(const RecordHeader &r) noexcept
Definition record_stream.hpp:320
std::uint64_t written() const noexcept
Definition record_stream.hpp:317
std::uint64_t dropped() const noexcept
Definition record_stream.hpp:318
FASTMM_FORCE_INLINE void init(R &r, RecordType type, InstrumentId inst, VenueId venue, Timestamp engine_ts, Timestamp wall_ts) noexcept
Fills in the parts every record shares.
Definition record_stream.hpp:339
Fixed<Tag>: int64 fixed point with a global 1e-8 scale (ADR-0001).
Event bus message structs (5.5).
Definition strategy.hpp:16
RejectSource
What refused an order (RejectRecord::source): the limit behind a rate-limit refusal,...
Definition record_stream.hpp:233
@ VenueLocal
the connector's own limiter refused it before sending (OrderReject text)
@ Risk
a pre-trade check other than the rate limits (reason says which)
@ AccountPaused
the account's connector is paused (429 Retry-After, 418)
@ Venue
the venue refused it (venue_code, text)
@ RiskBucket
the [risk] orders_per_sec token bucket, shared by every account
@ AccountOrders10s
the account's order window at the connector's cap
FixedString< 40 > VenueOrderId
Definition strong_id.hpp:42
KillReason
Why a kill switch (global or one venue's) was tripped.
Definition enums.hpp:523
@ Funding
a perpetual funding payment booked by the venue (FundingMsg)
RejectReason
Ordered exactly like RiskEngine::check_new evaluates them (5.7), followed by OMS / transport / venue ...
Definition enums.hpp:123
RecordType
Never 0: the ring reserves type 0 for padding.
Definition record_stream.hpp:39
Side
Definition enums.hpp:12
FeeAsset
The asset a fill's commission is charged in.
Definition enums.hpp:432
constexpr std::uint8_t kRecordVersion
Definition record_stream.hpp:36
FixedString< 40 > ExecId
Definition strong_id.hpp:44
constexpr std::string_view to_string(ParamType t) noexcept
Definition params.hpp:63
Liquidity
Definition enums.hpp:434
Order: the OMS's 128-byte record for one order across its lifetime.
Position tracking, average-cost method (5.8).
Strongly typed identifiers.
One execution.
Definition record_stream.hpp:106
std::uint8_t pad_[6]
-> 256
Definition record_stream.hpp:126
Side side
160
Definition record_stream.hpp:120
ExecId exec_id
209 -> 250
Definition record_stream.hpp:125
Qty leaves_qty
104
Definition record_stream.hpp:113
Price price
72
Definition record_stream.hpp:109
ClientOrderId cl_ord_id
64
Definition record_stream.hpp:108
std::uint8_t pad0_[5]
163 -> 168
Definition record_stream.hpp:123
Notional fee
112 settlement currency, booked
Definition record_stream.hpp:114
Liquidity liquidity
161
Definition record_stream.hpp:121
Price position_avg_px
136
Definition record_stream.hpp:117
Notional fee_amount
120 as reported, in fee_asset units
Definition record_stream.hpp:115
Qty booked_qty
88 what the position moved by (base-asset fees deducted)
Definition record_stream.hpp:111
RecordHeader hdr
Definition record_stream.hpp:107
Qty position_qty
128 the instrument's position after this fill
Definition record_stream.hpp:116
Qty cum_qty
96
Definition record_stream.hpp:112
FeeAsset fee_asset
162
Definition record_stream.hpp:122
Qty qty
80 this execution, as the venue reported it
Definition record_stream.hpp:110
Notional position_realized
144
Definition record_stream.hpp:118
Notional position_fees
152
Definition record_stream.hpp:119
VenueOrderId venue_order_id
168 -> 209
Definition record_stream.hpp:124
One execution as a strategy sees it (on_fill).
Definition hooks.hpp:56
A funding payment the engine booked (FundingMsg): amount in the instrument's settlement currency,...
Definition record_stream.hpp:160
Notional position_realized
80 the instrument's realized after it
Definition record_stream.hpp:164
Notional amount
64
Definition record_stream.hpp:162
ExecId funding_id
104 -> 145
Definition record_stream.hpp:167
RecordHeader hdr
Definition record_stream.hpp:161
FixedString< 8 > asset
145 -> 154
Definition record_stream.hpp:168
Notional position_funding
88 the instrument's funding after it
Definition record_stream.hpp:165
std::uint8_t pad_[38]
-> 192
Definition record_stream.hpp:169
Qty position_qty
72 the position it was paid on
Definition record_stream.hpp:163
Notional total_funding
96 over every instrument
Definition record_stream.hpp:166
A kill switch trip. hdr.flags & kVenue marks a per-venue trip (hdr.venue names it).
Definition record_stream.hpp:174
RecordHeader hdr
Definition record_stream.hpp:175
std::uint8_t pad_[8]
-> 128
Definition record_stream.hpp:185
Notional unrealized
96
Definition record_stream.hpp:182
std::uint8_t pad0_[3]
-> 68
Definition record_stream.hpp:177
std::uint64_t venue_kills
80
Definition record_stream.hpp:180
std::uint64_t kills
72 global trips so far
Definition record_stream.hpp:179
Notional pnl_carry
112
Definition record_stream.hpp:184
Notional fees
104
Definition record_stream.hpp:183
KillReason reason
64
Definition record_stream.hpp:176
std::uint32_t kill_flags
68 RiskEngine::kill_flags()
Definition record_stream.hpp:178
Notional realized
88
Definition record_stream.hpp:181
The OMS record after a transition.
Definition record_stream.hpp:137
RecordHeader hdr
Definition record_stream.hpp:138
Order order
Definition record_stream.hpp:139
A strategy parameter update the engine applied (ParamUpdateMsg): after the header,...
Definition record_stream.hpp:203
std::uint8_t pad0_[3]
Definition record_stream.hpp:207
std::uint64_t publish_seq
72
Definition record_stream.hpp:208
RecordHeader hdr
Definition record_stream.hpp:204
ParamUpdateMsg::Origin origin
68
Definition record_stream.hpp:206
char source[ParamUpdateMsg::kSourceLen]
144 NUL-terminated
Definition record_stream.hpp:210
std::int64_t value[ParamUpdateMsg::kMaxFields]
192 raw value of each pair
Definition record_stream.hpp:212
std::uint32_t count
64 pairs used
Definition record_stream.hpp:205
std::string_view source_view() const noexcept
Definition record_stream.hpp:214
std::uint16_t field[ParamUpdateMsg::kMaxFields]
80 index in the parameter table
Definition record_stream.hpp:209
std::uint8_t pad1_[8]
Definition record_stream.hpp:211
Origin
Definition messages.hpp:579
static constexpr std::size_t kMaxFields
Definition messages.hpp:575
static constexpr std::size_t kSourceLen
source, NUL-terminated
Definition messages.hpp:576
One instrument's position and the portfolio totals at the same instant.
Definition record_stream.hpp:144
Position pos
64 -> 128
Definition record_stream.hpp:146
RecordHeader hdr
Definition record_stream.hpp:145
Notional pnl_carry
152 carried in from earlier sessions (EngineConfig::pnl_carry)
Definition record_stream.hpp:150
Notional total_unrealized
136
Definition record_stream.hpp:148
Notional total_funding
168 over every instrument, part of total_realized
Definition record_stream.hpp:152
Notional funding
160 this instrument's funding so far, part of pos.realized
Definition record_stream.hpp:151
Notional total_fees
144
Definition record_stream.hpp:149
Notional total_realized
128
Definition record_stream.hpp:147
std::uint8_t pad_[16]
-> 192
Definition record_stream.hpp:153
Definition position.hpp:20
One order refused: by the pre-trade checks (the engine's) or by its venue (an OrderReject),...
Definition record_stream.hpp:272
Qty qty
80
Definition record_stream.hpp:287
FixedString< 40 > text
184 the venue's text (OrderRejectMsg::text)
Definition record_stream.hpp:304
Side side
66
Definition record_stream.hpp:283
std::int64_t orders_1d_used
144
Definition record_stream.hpp:296
std::int64_t orders_10s_admits
120
Definition record_stream.hpp:293
RejectReason reason
64
Definition record_stream.hpp:281
std::uint8_t pad0_[2]
Definition record_stream.hpp:303
std::int64_t local_tokens
96 [risk] bucket tokens left (OrderBudget::kUnlimited: off)
Definition record_stream.hpp:289
ClientOrderId cl_ord_id
88 the venue's refusals; 0 for a pre-trade one
Definition record_stream.hpp:288
std::uint8_t budget_known
180 the account's connector has published a budget
Definition record_stream.hpp:301
RejectSource source
65
Definition record_stream.hpp:282
std::int64_t weight_used
160
Definition record_stream.hpp:298
std::int64_t local_wait_ns
104
Definition record_stream.hpp:290
std::int64_t orders_1m_used
128
Definition record_stream.hpp:294
std::int64_t weight_admits
168
Definition record_stream.hpp:299
Price price
72
Definition record_stream.hpp:286
std::int64_t orders_10s_used
The account's windows: used and what the connector admits (RateWindow::admits; 0 unknown).
Definition record_stream.hpp:292
Flags
Definition record_stream.hpp:274
@ kFromVenue
an OrderReject, not a pre-trade check
Definition record_stream.hpp:278
@ kReduceOnly
Definition record_stream.hpp:277
@ kReplace
a replace, not a new order
Definition record_stream.hpp:275
@ kReduces
with the open orders on its side, it only takes the position to zero
Definition record_stream.hpp:276
std::uint32_t folded
68 refusals of the same key folded in since the last record
Definition record_stream.hpp:285
std::int64_t orders_1m_admits
136
Definition record_stream.hpp:295
std::int64_t orders_1d_admits
152
Definition record_stream.hpp:297
std::uint8_t pad_[31]
-> 256
Definition record_stream.hpp:305
static constexpr std::int64_t kFoldNs
Definition record_stream.hpp:273
std::int32_t venue_code
176 the venue's error code (OrderRejectMsg::venue_code)
Definition record_stream.hpp:300
std::uint8_t paused
181
Definition record_stream.hpp:302
std::uint8_t flags
67
Definition record_stream.hpp:284
RecordHeader hdr
Definition record_stream.hpp:280
A venue's execution replay ended complete (a reconciliation began with ReconcileMsg::kExecutionsExact...
Definition record_stream.hpp:194
RecordHeader hdr
Definition record_stream.hpp:195