FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
feed.hpp
Go to the documentation of this file.
1#pragma once
2// Hot-path connector concepts (6.2). A venue's market-data feed and order gateway are plain
3// classes instantiated inside the venue's connection handlers (static dispatch, everything
4// inlined); the Venue virtual interface (venue.hpp) is control-path only.
5//
6// MarketDataFeed: on_message(json, rx_ts) -> ParseStatus (writes into its EventSink)
7// on_connected() / on_disconnected()
8// subscription_payloads() -> span<const std::string>
9// OrderGateway: encode(cmd, now_ms, out) -> bool (Out*Msg -> wire bytes)
10// on_message(json, rx_ts) -> ParseStatus (responses -> order events)
11// can_send(now_ns) -> bool
15
16#include <concepts>
17#include <cstdint>
18#include <span>
19#include <string>
20#include <string_view>
21
22namespace fastmm::venues {
23
24enum class ParseStatus : std::uint8_t {
25 Ok = 0,
26 Ignored = 1, // valid message we do not consume (subscription acks, pongs, ...)
27 Malformed = 2, // JSON error or missing/invalid field
28 UnknownSymbol = 3, // symbol not in the SymbolTable
29 Overflow = 4, // ring full (market data) or output buffer too small
30 Error = 5, // venue-level error payload
31};
32[[nodiscard]] constexpr std::string_view to_string(ParseStatus s) noexcept {
33 switch (s) {
35 return "Ok";
37 return "Ignored";
39 return "Malformed";
41 return "UnknownSymbol";
43 return "Overflow";
45 return "Error";
46 }
47 return "?";
48}
49
50// What a decoder produced into the caller's scratch buffer.
51enum class MdKind : std::uint8_t {
52 None = 0,
54 BookSnapshot = 2,
55 BookTicker = 3,
56 Trade = 4,
57 PerpState = 5, // PerpStateMsg (venues/perp_state.hpp)
58};
59
60enum class OrderEventKind : std::uint8_t {
61 None = 0,
62 Ack = 1,
63 Reject = 2,
64 CancelAck = 3,
65 CancelReject = 4,
66 Fill = 5,
67 Expired = 6,
68 Position = 7,
69};
70
71struct DecodeResult {
75 std::uint32_t len = 0; // bytes written to the output buffer
76 [[nodiscard]] bool ok() const noexcept { return status == ParseStatus::Ok; }
77};
79// Every decoder needs a scratch area for the largest message it can produce.
80inline constexpr std::uint32_t kDecoderScratchBytes = kMaxMsgBytes;
81
82// Parsers that hand raw text frames to simdjson need SIMDJSON_PADDING (64) readable bytes
83// after the payload; RecvBuffer::kPadding guarantees it for WebSocket frames and
84// PaddedJson (padded_json.hpp) for fixtures/tests.
85inline constexpr std::size_t kJsonPadding = 64;
86
87template <class F>
88concept MarketDataFeed = requires(F& f, std::string_view json, std::int64_t rx_ts) {
89 { f.on_message(json, rx_ts) } -> std::same_as<ParseStatus>;
90 { f.on_connected() };
91 { f.on_disconnected() };
92 { f.subscription_payloads() } -> std::convertible_to<std::span<const std::string>>;
93};
94
95template <class G>
96concept OrderGateway = requires(G& g,
97 const OrderCommand& cmd,
98 std::int64_t now_ms,
99 std::span<char> out,
100 std::string_view json,
101 std::int64_t rx_ts,
102 std::int64_t now_ns) {
103 { g.encode(cmd, now_ms, out) } -> std::same_as<std::size_t>; // 0 = failed
104 { g.on_message(json, rx_ts) } -> std::same_as<ParseStatus>;
105 { g.can_send(now_ns) } -> std::same_as<bool>;
106};
107
108} // namespace fastmm::venues
Definition feed.hpp:90
EventSink (5.15): the net -> engine seam.
Event bus message structs (5.5).
Definition venue.hpp:38
constexpr std::uint32_t kDecoderScratchBytes
Every decoder needs a scratch area for the largest message it can produce.
Definition feed.hpp:82
MdKind
What a decoder produced into the caller's scratch buffer.
Definition feed.hpp:53
@ PerpState
PerpStateMsg (venues/perp_state.hpp)
OrderEventKind
Definition feed.hpp:62
constexpr std::string_view to_string(ChannelState s) noexcept
Definition venue.hpp:51
@ None
not a multicast venue
ParseStatus
Definition feed.hpp:26
@ Malformed
JSON error or missing/invalid field.
@ Overflow
ring full (market data) or output buffer too small
@ UnknownSymbol
symbol not in the SymbolTable
@ Error
venue-level error payload
@ Ignored
valid message we do not consume (subscription acks, pongs, ...)
constexpr std::size_t kJsonPadding
Parsers that hand raw text frames to simdjson need SIMDJSON_PADDING (64) readable bytes after the pay...
Definition feed.hpp:87
constexpr std::uint32_t kMaxMsgBytes
Definition messages.hpp:692
OrderCommand: a uniform, non-owning view over the three outbound engine messages (OutNewOrderMsg / Ou...
One execution as a strategy sees it (on_fill).
Definition hooks.hpp:56
Definition position.hpp:20
bool ok() const noexcept
Definition feed.hpp:78
std::uint32_t len
bytes written to the output buffer
Definition feed.hpp:77
OrderEventKind order_kind
Definition feed.hpp:76
MdKind kind
Definition feed.hpp:75
ParseStatus status
Definition feed.hpp:74