pub struct PerpBasis {
pub symbol: String,
pub perp_price: f64,
pub spot_price: f64,
pub basis_pct: f64,
pub timestamp_ms: u64,
}Expand description
Perpetual-futures basis: the percentage spread between perp and spot prices.
Positive basis → perp trades at a premium to spot (contango). Negative basis → perp trades at a discount (backwardation).
Fields§
§symbol: StringTrading pair symbol.
perp_price: f64Perpetual futures price.
spot_price: f64Spot price.
basis_pct: f64Basis as a percentage: (perp - spot) / spot × 100.
timestamp_ms: u64Unix timestamp in milliseconds.
Implementations§
Source§impl PerpBasis
impl PerpBasis
Sourcepub fn new(
symbol: impl Into<String>,
perp_price: f64,
spot_price: f64,
timestamp_ms: u64,
) -> Self
pub fn new( symbol: impl Into<String>, perp_price: f64, spot_price: f64, timestamp_ms: u64, ) -> Self
Construct a new PerpBasis, computing basis_pct automatically.
Returns basis_pct = 0.0 if spot_price is zero.
Sourcepub fn is_contango(&self) -> bool
pub fn is_contango(&self) -> bool
Returns true if the perpetual trades at a premium to spot (contango).
Sourcepub fn annualized_carry(&self, days_to_expiry: f64) -> f64
pub fn annualized_carry(&self, days_to_expiry: f64) -> f64
Annualised carry yield for a fixed-expiry contract.
annualized_carry = (basis_pct / 100) / (days_to_expiry / 365)
Returns 0.0 if days_to_expiry ≤ 0.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PerpBasis
impl RefUnwindSafe for PerpBasis
impl Send for PerpBasis
impl Sync for PerpBasis
impl Unpin for PerpBasis
impl UnsafeUnpin for PerpBasis
impl UnwindSafe for PerpBasis
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more