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)]
9pub enum TradeError {
10 /// The slippage is not a fraction from 0 to 0.5; the slippage given.
11 #[error("a slippage is a fraction from 0 to 0.5, which {0} is not")]
12 Slippage(Dec),
13 /// No valid price on the asset's grid comes from this price; the price given.
14 #[error("{0} leaves no price on the asset's grid")]
15 NoPrice(Dec),
16 /// This size is zero once cut to the asset's size decimals; the size given.
17 #[error("{0} leaves no size at the asset's size decimals")]
18 NoSize(Dec),
19 /// A TWAP's minutes are outside 5 to 1440; the minutes given.
20 #[error("a TWAP runs 5 to 1440 minutes, not {0}")]
21 TwapMinutes(u32),
22 /// The leverage is 0.
23 #[error("leverage is a whole number of at least 1")]
24 NoLeverage,
25 /// An isolated margin amount that is 0, finer than six places or too large.
26 #[error("isolated margin moves a non-zero amount of USDC: {0}")]
27 Margin(BadUnits),
28 /// A builder fee over what the market allows.
29 #[error(transparent)]
30 OverCap(#[from] OverCap),
31}