17#include "fastmm/core/config_macros.hpp"
21#include "fastmm/core/msg_ring.hpp"
78 return "ContextNames";
84 enum Flags : std::uint8_t {
109 std::uint8_t
pad_[8];
111static_assert(
sizeof(
RecordHeader) == 64 && std::is_trivially_copyable_v<RecordHeader>);
167static_assert(
sizeof(
FillRecord) == 384 && std::is_trivially_copyable_v<FillRecord>);
168static_assert(offsetof(
FillRecord, named_qty) == 160 &&
183static_assert(
sizeof(
OrderRecord) == 192 && std::is_trivially_copyable_v<OrderRecord>);
197static_assert(
sizeof(
PositionRecord) == 192 && std::is_trivially_copyable_v<PositionRecord>);
213static_assert(
sizeof(
FundingRecord) == 192 && std::is_trivially_copyable_v<FundingRecord>);
229static_assert(
sizeof(
KillRecord) == 128 && std::is_trivially_copyable_v<KillRecord>);
239static_assert(
sizeof(
ReplayedRecord) == 64 && std::is_trivially_copyable_v<ReplayedRecord>);
264static_assert(
sizeof(ParamRecord) ==
sizeof(ParamUpdateMsg) &&
265 std::is_trivially_copyable_v<ParamRecord>);
266static_assert(offsetof(ParamRecord, count) == offsetof(ParamUpdateMsg, count) &&
267 offsetof(ParamRecord, origin) == offsetof(ParamUpdateMsg, origin) &&
268 offsetof(ParamRecord, arm) == offsetof(ParamUpdateMsg, arm) &&
269 offsetof(ParamRecord, flags) == offsetof(ParamUpdateMsg, flags) &&
270 offsetof(ParamRecord, publish_seq) == offsetof(ParamUpdateMsg, publish_seq) &&
271 offsetof(ParamRecord, field) == offsetof(ParamUpdateMsg, field) &&
272 offsetof(ParamRecord, source) == offsetof(ParamUpdateMsg, source) &&
273 offsetof(ParamRecord, value) == offsetof(ParamUpdateMsg, value));
290 std::uint8_t
pad_[320 - 276 -
sizeof(FixedString<8>)];
292static_assert(
sizeof(
LimitsRecord) == 320 && std::is_trivially_copyable_v<LimitsRecord>);
314 return "risk_bucket";
316 return "account_paused";
318 return "account_orders_10s";
320 return "account_orders_1m";
322 return "account_orders_1d";
324 return "venue_local";
342 static constexpr std::int64_t
kFoldNs = 100'000'000;
377static_assert(
sizeof(
RejectRecord) == 256 && std::is_trivially_copyable_v<RejectRecord>);
389static_assert(
sizeof(
MarkoutRecord) == 128 && std::is_trivially_copyable_v<MarkoutRecord>);
412static_assert(
sizeof(
CapacityRecord) == 192 && std::is_trivially_copyable_v<CapacityRecord>);
418 static constexpr std::size_t
kNameLen = 23;
424 std::is_trivially_copyable_v<ContextNamesRecord>);
430 explicit RecordWriter(MsgRing* ring =
nullptr, std::uint64_t session_id = 0) noexcept
431 : ring_(ring), session_id_(session_id) {}
433 [[nodiscard]]
bool enabled() const noexcept {
return ring_ !=
nullptr; }
434 [[nodiscard]] std::uint64_t
written() const noexcept {
return written_; }
435 [[nodiscard]] std::uint64_t
dropped() const noexcept {
return dropped_; }
438 if (ring_ ==
nullptr)
return true;
439 std::byte* p = ring_->try_reserve(r.len);
440 if (FASTMM_UNLIKELY(p ==
nullptr)) {
444 std::memcpy(p, &r, r.len);
448 h->session_id = session_id_;
456 FASTMM_FORCE_INLINE
void init(R& r,
462 static_assert(std::is_trivially_copyable_v<R> &&
sizeof(R) % 64 == 0);
464 r.hdr.
len =
static_cast<std::uint32_t
>(
sizeof(R));
467 r.hdr.instrument = inst;
469 r.hdr.engine_ts = engine_ts;
470 r.hdr.wall_ts = wall_ts;
475 std::uint64_t session_id_;
476 std::uint64_t written_ = 0;
477 std::uint64_t dropped_ = 0;
The capacity price ([capacity]): every action that uses an order slot is a purchase.
Engine-side producer.
Definition record_stream.hpp:430
bool enabled() const noexcept
Definition record_stream.hpp:435
FASTMM_FORCE_INLINE bool put(const RecordHeader &r) noexcept
Definition record_stream.hpp:439
std::uint64_t written() const noexcept
Definition record_stream.hpp:436
std::uint64_t dropped() const noexcept
Definition record_stream.hpp:437
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:458
Fixed<Tag>: int64 fixed point with a global 1e-8 scale (ADR-0001).
Event bus message structs (5.5).
Definition strategy.hpp:23
constexpr std::size_t kQuoteContextSize
The numbers a strategy publishes about its quotes on one side of an instrument (StrategyContext::quot...
Definition order.hpp:71
RejectSource
What refused an order (RejectRecord::source): the limit behind a rate-limit refusal,...
Definition record_stream.hpp:300
@ Capacity
worth less than the order slot it takes ([capacity], RejectReason::PricedOut)
@ 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
OrderState
Definition enums.hpp:79
FixedString< 40 > VenueOrderId
Definition strong_id.hpp:42
KillReason
Why a kill switch (global or one venue's) was tripped.
Definition enums.hpp:603
@ 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:41
Side
Definition enums.hpp:12
FeeAsset
The asset a fill's commission is charged in.
Definition enums.hpp:481
constexpr std::uint8_t kRecordVersion
Definition record_stream.hpp:38
CapacityMode
Definition capacity_price.hpp:51
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:483
Order: the OMS's 128-byte record for one order across its lifetime.
Position tracking, average-cost method (5.8).
RiskLimits: the pre-trade limits a session runs with ([risk] in the configuration),...
Strongly typed identifiers.
A minute of one account's capacity price ([capacity], core/capacity_price.hpp): the actions priced,...
Definition record_stream.hpp:396
RecordHeader hdr
Definition record_stream.hpp:397
std::uint8_t pad0_[3]
Definition record_stream.hpp:406
std::uint32_t decided
64 actions priced
Definition record_stream.hpp:398
std::uint32_t observed_new
80 would have been priced out
Definition record_stream.hpp:402
std::uint32_t priced_out_move
76
Definition record_stream.hpp:401
double price_max
104
Definition record_stream.hpp:408
double day_price
128 the account's and the strategy's day prices
Definition record_stream.hpp:411
double price_mean
112
Definition record_stream.hpp:409
std::uint32_t sent
68 new orders and replaces sent
Definition record_stream.hpp:399
CapacityMode mode
92
Definition record_stream.hpp:405
double price_min
96 quote currency
Definition record_stream.hpp:407
std::uint32_t peak_used
88 the most orders in one window
Definition record_stream.hpp:404
std::uint8_t pad_[56]
-> 192
Definition record_stream.hpp:412
std::uint32_t observed_move
84
Definition record_stream.hpp:403
std::uint32_t priced_out_new
72
Definition record_stream.hpp:400
double floor
120 L, the value of a minimum-notional order
Definition record_stream.hpp:410
The names the strategy gave the values of its quote context (StrategyContext:: quote_context_names),...
Definition record_stream.hpp:419
RecordHeader hdr
Definition record_stream.hpp:421
static constexpr std::size_t kNameLen
bytes kept of a name
Definition record_stream.hpp:420
FixedString< kNameLen > names[kQuoteContextSize]
64 -> 160
Definition record_stream.hpp:422
std::uint8_t pad_[32]
-> 192
Definition record_stream.hpp:423
One execution.
Definition record_stream.hpp:126
std::uint8_t trail
381 1: the order fields above are set
Definition record_stream.hpp:166
Qty named_qty
The part of this execution that named an estimate (a synthetic fill of the same order booked before i...
Definition record_stream.hpp:144
Side side
250
Definition record_stream.hpp:147
ExecId exec_id
209 -> 250
Definition record_stream.hpp:146
std::uint8_t arm
253 its order's Order::arm
Definition record_stream.hpp:150
std::uint8_t pad0_[2]
-> 256
Definition record_stream.hpp:151
Qty leaves_qty
104
Definition record_stream.hpp:133
QuoteContext fill_context
344 the side's context when the fill arrived
Definition record_stream.hpp:163
Price price
72
Definition record_stream.hpp:129
ClientOrderId cl_ord_id
64
Definition record_stream.hpp:128
Notional fee
112 settlement currency, booked
Definition record_stream.hpp:134
Liquidity liquidity
251
Definition record_stream.hpp:148
Timestamp sent_ts
264 the working leg went out: placed_ts, or the last accepted replace's send
Definition record_stream.hpp:153
std::uint8_t pad_[2]
-> 384
Definition record_stream.hpp:167
Price position_avg_px
136
Definition record_stream.hpp:137
OrderState order_state
380 the order's state when the fill arrived, before it
Definition record_stream.hpp:165
Notional fee_amount
120 as reported, in fee_asset units
Definition record_stream.hpp:135
Qty booked_qty
88 what the position moved by (base-asset fees deducted)
Definition record_stream.hpp:131
RecordHeader hdr
Definition record_stream.hpp:127
Price pending_px
304 the replace in flight: its price
Definition record_stream.hpp:161
Timestamp pending_ts
A cancel or replace was in flight when the fill arrived (order_state PendingCancel or PendingReplace)...
Definition record_stream.hpp:159
Qty position_qty
128 the instrument's position after this fill
Definition record_stream.hpp:136
Price placed_px
296 the first leg's price
Definition record_stream.hpp:160
Qty cum_qty
96
Definition record_stream.hpp:132
FeeAsset fee_asset
252
Definition record_stream.hpp:149
Timestamp venue_ack_ts
272 the working leg's ack, venue time (invalid: none)
Definition record_stream.hpp:155
Qty qty
80 this execution, as the venue reported it
Definition record_stream.hpp:130
Timestamp placed_ts
256 the order's first leg went out
Definition record_stream.hpp:152
std::uint32_t amends
376 replaces the venue accepted before the fill
Definition record_stream.hpp:164
Notional position_realized
144
Definition record_stream.hpp:138
QuoteContext order_context
312 the side's context when the working leg went out
Definition record_stream.hpp:162
Notional position_fees
152
Definition record_stream.hpp:139
Timestamp local_ack_ts
280 the same ack, when it reached the engine
Definition record_stream.hpp:156
VenueOrderId venue_order_id
168 -> 209
Definition record_stream.hpp:145
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:204
Notional position_realized
80 the instrument's realized after it
Definition record_stream.hpp:208
Notional amount
64
Definition record_stream.hpp:206
ExecId funding_id
104 -> 145
Definition record_stream.hpp:211
RecordHeader hdr
Definition record_stream.hpp:205
FixedString< 8 > asset
145 -> 154
Definition record_stream.hpp:212
Notional position_funding
88 the instrument's funding after it
Definition record_stream.hpp:209
std::uint8_t pad_[38]
-> 192
Definition record_stream.hpp:213
Qty position_qty
72 the position it was paid on
Definition record_stream.hpp:207
Notional total_funding
96 over every instrument
Definition record_stream.hpp:210
A kill switch trip. hdr.flags & kVenue marks a per-venue trip (hdr.venue names it).
Definition record_stream.hpp:218
RecordHeader hdr
Definition record_stream.hpp:219
std::uint8_t pad_[8]
-> 128
Definition record_stream.hpp:229
Notional unrealized
96
Definition record_stream.hpp:226
std::uint8_t pad0_[3]
-> 68
Definition record_stream.hpp:221
std::uint64_t venue_kills
80
Definition record_stream.hpp:224
std::uint64_t kills
72 global trips so far
Definition record_stream.hpp:223
Notional pnl_carry
112
Definition record_stream.hpp:228
Notional fees
104
Definition record_stream.hpp:227
KillReason reason
64
Definition record_stream.hpp:220
std::uint32_t kill_flags
68 RiskEngine::kill_flags()
Definition record_stream.hpp:222
Notional realized
88
Definition record_stream.hpp:225
An operator's limits command the engine applied (ControlCommand::SetLimits or SetUnderlyingLimit): th...
Definition record_stream.hpp:280
std::int64_t underlying_before
256 kUnderlying: max_net, raw Qty in base units
Definition record_stream.hpp:285
std::uint8_t kind
Definition record_stream.hpp:288
RecordHeader hdr
Definition record_stream.hpp:282
Kind
Definition record_stream.hpp:281
@ kRisk
Definition record_stream.hpp:281
@ kUnderlying
Definition record_stream.hpp:281
std::int64_t underlying_after
264
Definition record_stream.hpp:286
FixedString< 8 > underlying
272 kUnderlying: the base asset
Definition record_stream.hpp:287
std::uint8_t check_balance_after
Definition record_stream.hpp:291
std::uint8_t check_balance_before
Definition record_stream.hpp:290
std::uint8_t pad_[320 - 276 - sizeof(FixedString< 8 >)]
Definition record_stream.hpp:292
RiskLimits after
160
Definition record_stream.hpp:284
RiskLimits before
64
Definition record_stream.hpp:283
std::uint8_t forced
Definition record_stream.hpp:289
The instrument's mid horizon_ms after one of its fills, 0 at the fill ([engine] markout_ms).
Definition record_stream.hpp:383
RecordHeader hdr
Definition record_stream.hpp:384
std::int32_t horizon_ms
88
Definition record_stream.hpp:388
std::uint64_t fill_seq
64 the FillRecord's hdr.seq
Definition record_stream.hpp:385
Price mid
80
Definition record_stream.hpp:387
Timestamp fill_ts
72 the fill's engine time
Definition record_stream.hpp:386
std::uint8_t pad_[36]
-> 128
Definition record_stream.hpp:389
The OMS record after a transition.
Definition record_stream.hpp:181
RecordHeader hdr
Definition record_stream.hpp:182
Order order
Definition record_stream.hpp:183
A strategy parameter update the engine applied (ParamUpdateMsg): after the header,...
Definition record_stream.hpp:247
std::uint8_t pad0_[1]
Definition record_stream.hpp:253
std::uint8_t arm
69 ParamUpdateMsg::arm
Definition record_stream.hpp:251
std::uint64_t publish_seq
72
Definition record_stream.hpp:254
RecordHeader hdr
Definition record_stream.hpp:248
ParamUpdateMsg::Origin origin
68
Definition record_stream.hpp:250
char source[ParamUpdateMsg::kSourceLen]
144 NUL-terminated
Definition record_stream.hpp:256
std::int64_t value[ParamUpdateMsg::kMaxFields]
192 raw value of each pair
Definition record_stream.hpp:258
std::uint8_t flags
70 ParamUpdateMsg::flags
Definition record_stream.hpp:252
std::uint32_t count
64 pairs used
Definition record_stream.hpp:249
std::string_view source_view() const noexcept
Definition record_stream.hpp:260
std::uint16_t field[ParamUpdateMsg::kMaxFields]
80 index in the parameter table
Definition record_stream.hpp:255
std::uint8_t pad1_[8]
Definition record_stream.hpp:257
Origin
Definition messages.hpp:802
static constexpr std::size_t kMaxFields
Definition messages.hpp:796
static constexpr std::size_t kSourceLen
source, NUL-terminated
Definition messages.hpp:797
One instrument's position and the portfolio totals at the same instant.
Definition record_stream.hpp:188
Position pos
64 -> 128
Definition record_stream.hpp:190
RecordHeader hdr
Definition record_stream.hpp:189
Notional pnl_carry
152 carried in from earlier sessions (EngineConfig::pnl_carry)
Definition record_stream.hpp:194
Notional total_unrealized
136
Definition record_stream.hpp:192
Notional total_funding
168 over every instrument, part of total_realized
Definition record_stream.hpp:196
Notional funding
160 this instrument's funding so far, part of pos.realized
Definition record_stream.hpp:195
Notional total_fees
144
Definition record_stream.hpp:193
Notional total_realized
128
Definition record_stream.hpp:191
std::uint8_t pad_[16]
-> 192
Definition record_stream.hpp:197
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:343
Qty qty
80
Definition record_stream.hpp:359
FixedString< 40 > text
184 the venue's text (OrderRejectMsg::text)
Definition record_stream.hpp:376
Side side
66
Definition record_stream.hpp:355
std::int64_t orders_1d_used
144
Definition record_stream.hpp:368
std::int64_t orders_10s_admits
120
Definition record_stream.hpp:365
RejectReason reason
64
Definition record_stream.hpp:353
std::uint8_t pad0_[2]
Definition record_stream.hpp:375
std::int64_t local_tokens
96 [risk] bucket tokens left (OrderBudget::kUnlimited: off)
Definition record_stream.hpp:361
static constexpr std::int64_t kFoldMaxNs
Definition record_stream.hpp:345
ClientOrderId cl_ord_id
88 the venue's refusals; 0 for a pre-trade one
Definition record_stream.hpp:360
std::uint8_t budget_known
180 the account's connector has published a budget
Definition record_stream.hpp:373
RejectSource source
65
Definition record_stream.hpp:354
std::int64_t weight_used
160
Definition record_stream.hpp:370
std::int64_t local_wait_ns
104
Definition record_stream.hpp:362
std::int64_t orders_1m_used
128
Definition record_stream.hpp:366
std::int64_t weight_admits
168
Definition record_stream.hpp:371
Price price
72
Definition record_stream.hpp:358
std::int64_t orders_10s_used
The account's windows: used and what the connector admits (RateWindow::admits; 0 unknown).
Definition record_stream.hpp:364
Flags
Definition record_stream.hpp:346
@ kFromVenue
an OrderReject, not a pre-trade check
Definition record_stream.hpp:350
@ kReduceOnly
Definition record_stream.hpp:349
@ kReplace
a replace, not a new order
Definition record_stream.hpp:347
@ kReduces
with the open orders on its side, it only takes the position to zero
Definition record_stream.hpp:348
std::uint32_t folded
68 refusals of the same key folded in since the last record
Definition record_stream.hpp:357
std::int64_t orders_1m_admits
136
Definition record_stream.hpp:367
std::int64_t orders_1d_admits
152
Definition record_stream.hpp:369
std::uint8_t pad_[31]
-> 256
Definition record_stream.hpp:377
static constexpr std::int64_t kFoldNs
Definition record_stream.hpp:344
std::int32_t venue_code
176 the venue's error code (OrderRejectMsg::venue_code)
Definition record_stream.hpp:372
std::uint8_t paused
181
Definition record_stream.hpp:374
std::uint8_t flags
67
Definition record_stream.hpp:356
RecordHeader hdr
Definition record_stream.hpp:352
A venue's execution replay ended complete (a reconciliation began with ReconcileMsg::kExecutionsExact...
Definition record_stream.hpp:238
RecordHeader hdr
Definition record_stream.hpp:239
Definition risk_limits.hpp:18