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