Skip to main content

df_hyperliquid_core/live/frame/
mod.rs

1//! Received frames (`{"channel":..,"data":..}`) read into a type per channel ([`decode`]): live's
2//! own frame types, or the [`crate::account`] and [`crate::markets`] types where the socket sends
3//! the shape `/info` answers. Numbers are exact decimals, never floats. An unknown channel is
4//! [`Frame::Other`], kept as written; a frame that does not read is a [`BadFrame`], never a panic.
5
6pub mod control;
7pub mod read;
8pub mod reply;
9
10pub use control::{Ack, Method, Refusal};
11pub use read::{BadFrame, decode};
12pub use reply::{Answer, Reply};
13
14use crate::account::ActiveAssetData;
15use crate::live::{
16    AllDexsState, Bbo, DexState, HistoricalOrders, Ledger, Mids, OpenOrders, OrderUpdate, SpotState, TwapHistory,
17    TwapSliceFills, TwapStates, UserEvent, UserFills, UserFundings, WebData3,
18};
19use crate::markets::context::{PerpCtx, SpotCtx};
20use crate::markets::{Book, Candle, Trade};
21use crate::utils::Json;
22
23/// One frame, by channel.
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub enum Frame {
26    /// `pong`: the answer to a ping.
27    Pong,
28    /// `subscriptionResponse`: the venue took a subscribe or an unsubscribe.
29    Ack(Ack),
30    /// `error`: the venue refused something sent, in its own words.
31    Error(Refusal),
32    /// `post`: the answer to a post, by its id.
33    Post(Reply),
34    AllMids(Mids),
35    /// `l2Book`.
36    Book(Book),
37    Trades(Vec<Trade>),
38    Bbo(Bbo),
39    Candle(Candle),
40    /// `activeAssetCtx`: a perp's context.
41    AssetCtx {
42        coin: String,
43        ctx: PerpCtx,
44    },
45    /// `activeSpotAssetCtx`: what `activeAssetCtx` sends for a spot pair or an outcome side.
46    SpotAssetCtx {
47        coin: String,
48        ctx: SpotCtx,
49    },
50    /// `activeAssetData`.
51    AssetData(ActiveAssetData),
52    UserFills(UserFills),
53    OrderUpdates(Vec<OrderUpdate>),
54    /// `user`: what `userEvents` sends.
55    UserEvent(UserEvent),
56    UserFundings(UserFundings),
57    /// `userNonFundingLedgerUpdates`.
58    Ledger(Ledger),
59    ClearinghouseState(DexState),
60    AllDexsClearinghouseState(AllDexsState),
61    OpenOrders(OpenOrders),
62    SpotState(SpotState),
63    TwapStates(TwapStates),
64    /// `userTwapSliceFills`.
65    TwapSliceFills(TwapSliceFills),
66    /// `userTwapHistory`.
67    TwapHistory(TwapHistory),
68    Notification(String),
69    WebData3(WebData3),
70    /// Every perp dex's contexts, by dex name, the first `""`.
71    AllDexsAssetCtxs(Vec<(String, Vec<PerpCtx>)>),
72    AssetCtxs {
73        dex: String,
74        ctxs: Vec<PerpCtx>,
75    },
76    SpotAssetCtxs(Vec<SpotCtx>),
77    /// What changed in `outcomeMeta`, kept as sent: `[{"outcomeSettled":23205}]`. Its arrival
78    /// is the news; read `outcomeMeta` again for the whole.
79    OutcomeMetaUpdates(Json),
80    /// `fastAssetCtxs`: base64 of raw DEFLATE (RFC 1951) over JSON, kept as sent. Inflating it
81    /// needs a decompressor this crate does not carry.
82    FastAssetCtxs(String),
83    /// `userHistoricalOrders`.
84    HistoricalOrders(HistoricalOrders),
85    /// A channel this build does not read: its name, and its data as written (empty when the
86    /// frame has none).
87    Other {
88        channel: String,
89        data: String,
90    },
91}