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