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;
7mod hot;
8pub(crate) mod one_pass;
9pub mod read;
10pub mod reply;
11mod scan;
12
13pub use control::{Ack, Method, Refusal};
14#[cfg(feature = "__test-internals")]
15#[doc(hidden)]
16pub use read::reads_directly;
17pub use read::{BadFrame, decode};
18pub use reply::{Answer, Reply};
19
20use crate::account::ActiveAssetData;
21use crate::live::{
22    AllDexsState, Bbo, DexState, HistoricalOrders, L2, Ledger, Mids, OpenOrders, OrderUpdate, SpotState, TwapHistory,
23    TwapSliceFills, TwapStates, UserEvent, UserFills, UserFundings, WebData3,
24};
25use crate::markets::context::{PerpCtx, SpotCtx};
26use crate::markets::{Book, Candle, Trade};
27use crate::utils::Json;
28
29/// One frame, by channel.
30#[derive(Debug, Clone, PartialEq, Eq)]
31#[non_exhaustive]
32pub enum Frame {
33    /// `pong`: the answer to a ping.
34    Pong,
35    /// `subscriptionResponse`: the venue took a subscribe or an unsubscribe.
36    Ack(Ack),
37    /// `error`: the venue refused something sent, in its own words.
38    Error(Refusal),
39    /// `post`: the answer to a post, by its id.
40    Post(Reply),
41    /// `allMids`: every coin's mid on one perp dex.
42    AllMids(Mids),
43    /// `l2Book`.
44    Book(Book),
45    /// `trades`: new prints on one coin.
46    Trades(Vec<Trade>),
47    /// `bbo`: the best bid and offer of one coin.
48    Bbo(Bbo),
49    /// `candle`: one candle, sent as it changes.
50    Candle(Candle),
51    /// `activeAssetCtx`: a perp's context.
52    AssetCtx {
53        /// The perp's coin.
54        coin: String,
55        /// The perp's context.
56        ctx: PerpCtx,
57    },
58    /// `activeSpotAssetCtx`: what `activeAssetCtx` sends for a spot pair or an outcome side.
59    SpotAssetCtx {
60        /// The spot pair's or outcome side's coin.
61        coin: String,
62        /// The pair's or side's context.
63        ctx: SpotCtx,
64    },
65    /// `activeAssetData`.
66    AssetData(ActiveAssetData),
67    /// `userFills`: the account's fills.
68    UserFills(UserFills),
69    /// `orderUpdates`: status changes of the account's orders.
70    OrderUpdates(Vec<OrderUpdate>),
71    /// `user`: what `userEvents` sends.
72    UserEvent(UserEvent),
73    /// `userFundings`: the account's funding payments.
74    UserFundings(UserFundings),
75    /// `userNonFundingLedgerUpdates`.
76    Ledger(Ledger),
77    /// `clearinghouseState`: the account's clearinghouse on one dex.
78    ClearinghouseState(DexState),
79    /// `allDexsClearinghouseState`: the account's clearinghouse on every dex.
80    AllDexsClearinghouseState(AllDexsState),
81    /// `openOrders`: the account's resting orders on one dex.
82    OpenOrders(OpenOrders),
83    /// `spotState`: the account's spot balances.
84    SpotState(SpotState),
85    /// `twapStates`: the account's running TWAPs on one dex.
86    TwapStates(TwapStates),
87    /// `userTwapSliceFills`.
88    TwapSliceFills(TwapSliceFills),
89    /// `userTwapHistory`.
90    TwapHistory(TwapHistory),
91    /// `notification`: a short text for the account, as sent.
92    Notification(String),
93    /// `webData3`: the account as Hyperliquid's own frontend reads it.
94    WebData3(WebData3),
95    /// Every perp dex's contexts, by dex name, the first `""`.
96    AllDexsAssetCtxs(Vec<(String, Vec<PerpCtx>)>),
97    /// `assetCtxs`: one perp dex's contexts.
98    AssetCtxs {
99        /// The dex, `""` for the first.
100        dex: String,
101        /// The contexts, in the dex's universe order.
102        ctxs: Vec<PerpCtx>,
103    },
104    /// `spotAssetCtxs`: every spot pair's and outcome side's context.
105    SpotAssetCtxs(Vec<SpotCtx>),
106    /// What changed in `outcomeMeta`, kept as sent: an array of one-key objects, such as
107    /// `{"outcomeSettled":23205}` or `{"outcomeCreated":{"outcome":49747,"name":..,
108    /// "description":..,"sideSpecs":[..],"quoteToken":"USDC",..}}`. Its arrival is the news; read
109    /// `outcomeMeta` again for the whole.
110    OutcomeMetaUpdates(Json),
111    /// `fastAssetCtxs`: base64 of raw DEFLATE (RFC 1951) over JSON, kept as sent. Inflating it
112    /// needs a decompressor this crate does not carry.
113    FastAssetCtxs(String),
114    /// `userHistoricalOrders`.
115    HistoricalOrders(HistoricalOrders),
116    /// `l2`: the book's snapshot, or a diff to it.
117    L2(L2),
118    /// `pac`: every perp dex's contexts as `[dex, ctxs]` pairs, the first dex `""`, each `ctxs` in
119    /// the dex's universe order. After the snapshot, a context holds only the fields that changed,
120    /// or is `{}`. Base64 of raw DEFLATE (RFC 1951) over JSON, kept as sent.
121    Pac(String),
122    /// `sac`: every spot pair's and outcome side's context by coin; after the snapshot, only the
123    /// coins and fields that changed. Base64 of raw DEFLATE (RFC 1951) over JSON, kept as sent.
124    Sac(String),
125    /// A channel this build does not read: its name, and its data as written (empty when the
126    /// frame has none).
127    Other {
128        /// The channel's name.
129        channel: String,
130        /// The frame's `data` as written JSON; empty when the frame has none.
131        data: String,
132    },
133}