Skip to main content

df_hyperliquid_core/trade/
error.rs

1//! Checks on a trading action that fail before anything is signed ([`TradeError`]).
2
3use crate::trade::builder::OverCap;
4use crate::utils::{BadUnits, Dec};
5
6/// What would be refused, or would trade the wrong way, before anything is
7/// signed.
8#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
9#[non_exhaustive]
10pub enum TradeError {
11    /// The slippage is not a fraction from 0 to 0.5; the slippage given.
12    #[error("a slippage is a fraction from 0 to 0.5, which {0} is not")]
13    Slippage(Dec),
14    /// No valid price on the asset's grid comes from this price; the price given.
15    #[error("{0} leaves no price on the asset's grid")]
16    NoPrice(Dec),
17    /// This size is zero once cut to the asset's size decimals; the size given.
18    #[error("{0} leaves no size at the asset's size decimals")]
19    NoSize(Dec),
20    /// A TWAP's minutes are outside 5 to 1440; the minutes given.
21    #[error("a TWAP runs 5 to 1440 minutes, not {0}")]
22    TwapMinutes(u32),
23    /// The leverage is 0.
24    #[error("leverage is a whole number of at least 1")]
25    NoLeverage,
26    /// An isolated margin amount that is 0, finer than six places or too large.
27    #[error("isolated margin moves a non-zero amount of USDC: {0}")]
28    Margin(BadUnits),
29    /// A builder fee over what the market allows.
30    #[error(transparent)]
31    OverCap(#[from] OverCap),
32}