Skip to main content

df_hyperliquid_core/account/
fill.rs

1//! An account's fills, the same shape whether `userFills`, `userFillsByTime` and
2//! `userTwapSliceFills` answer them or `userFills`, `userEvents` and the TWAP feeds send them.
3//! Perp, spot and outcome fills come in the same answer.
4
5use serde::Deserialize;
6
7use crate::markets::side::Side;
8use crate::utils::address::Address;
9use crate::utils::dec::Dec;
10
11/// One fill. `fee` is everything the fill cost, a builder's share included, in `fee_token`:
12/// USDC, or on a spot buy the token bought.
13#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
14#[serde(rename_all = "camelCase")]
15pub struct Fill {
16    /// `BTC`, `xyz:XYZ100`, `@107`, `#14730`.
17    pub coin: String,
18    pub px: Dec,
19    pub sz: Dec,
20    /// The account's side.
21    pub side: Side,
22    /// Milliseconds.
23    pub time: u64,
24    /// The account's position in the coin before this fill, signed.
25    pub start_position: Dec,
26    /// For display: `Open Long`, `Close Short`, `Buy`, `Spot Dust Conversion`, `Settlement`...
27    pub dir: String,
28    pub closed_pnl: Dec,
29    /// The L1 transaction hash; all zeros for a TWAP slice.
30    pub hash: String,
31    pub oid: u64,
32    /// Took liquidity.
33    pub crossed: bool,
34    /// Negative is a rebate. Includes `builder_fee`.
35    pub fee: Dec,
36    pub tid: u64,
37    /// The order's client id as written (`0x` and 32 hex digits), kept as a string so a fill reads
38    /// whatever its order was tagged with.
39    #[serde(default)]
40    pub cloid: Option<String>,
41    pub fee_token: String,
42    /// What the order's builder took; the venue leaves it out when nothing.
43    #[serde(default)]
44    pub builder_fee: Option<Dec>,
45    /// Only on a fill that was part of a liquidation.
46    #[serde(default)]
47    pub liquidation: Option<FillLiquidation>,
48    #[serde(default)]
49    pub twap_id: Option<u64>,
50}
51
52/// On a fill that was part of a liquidation, on either side of it.
53#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
54#[serde(rename_all = "camelCase")]
55pub struct FillLiquidation {
56    #[serde(default)]
57    pub liquidated_user: Option<Address>,
58    pub mark_px: Dec,
59    /// `market` or `backstop`.
60    pub method: String,
61}
62
63/// A fill of one of a TWAP's slices.
64#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
65#[serde(rename_all = "camelCase")]
66pub struct TwapSliceFill {
67    pub fill: Fill,
68    pub twap_id: u64,
69}
70
71#[cfg(test)]
72#[path = "tests/fill.rs"]
73mod tests;