#[non_exhaustive]pub enum WsMessage {
Heartbeat,
System(Value),
MarketData {
conid: i64,
payload: Value,
},
Order(Value),
Pnl(Value),
Other(Value),
Malformed {
text: String,
error: String,
},
}Expand description
A decoded CPAPI frame. Most messages fall into one of the variants below,
but the CPAPI occasionally emits payloads we haven’t modelled — those end
up in WsMessage::Other.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Heartbeat
Heartbeat pings sent by the server periodically.
System(Value)
System / session status messages (e.g. "topic": "system").
MarketData
Market data tick for a subscribed contract.
Fields
Order(Value)
Order update (working → filled, cancellations, etc).
Pnl(Value)
PnL / account summary update.
Other(Value)
Any message whose topic we didn’t recognise.
Malformed
The socket emitted a frame we couldn’t decode — a text body that wasn’t valid JSON, or a binary frame converted lossily to UTF-8. The decoder’s error is captured alongside the original text so callers can telemeter parse rates.
Implementations§
Source§impl WsMessage
impl WsMessage
Sourcepub fn topic(&self) -> &'static str
pub fn topic(&self) -> &'static str
Return a static label for the message variant. Useful for
tracing::Span::record("topic", ...) and metrics labels.
Sourcepub fn as_value(&self) -> Option<&Value>
pub fn as_value(&self) -> Option<&Value>
Borrow the inner Value for variants that carry one. None
for WsMessage::Heartbeat and WsMessage::Malformed (which
has no parsed value to lend).