pub struct MarkPrice {
pub symbol: String,
pub mark_price: Decimal,
pub index_price: Option<Decimal>,
pub estimated_settle_price: Option<Decimal>,
pub last_funding_rate: Option<Decimal>,
pub next_funding_time: Option<i64>,
pub interest_rate: Option<Decimal>,
pub timestamp: i64,
}Expand description
Mark price data structure.
Represents the mark price and related information for futures contracts.
§Examples
use ccxt_core::types::MarkPrice;
use rust_decimal::Decimal;
use rust_decimal_macros::dec;
let mark_price = MarkPrice {
symbol: "BTC/USDT".to_string(),
mark_price: dec!(50000),
index_price: Some(dec!(49995)),
estimated_settle_price: Some(dec!(50005)),
last_funding_rate: Some(dec!(0.0001)),
next_funding_time: Some(1637000000000),
interest_rate: Some(dec!(0.0003)),
timestamp: 1637000000000,
};
println!("Basis (mark - index): {}", mark_price.basis().unwrap_or(Decimal::ZERO));Fields§
§symbol: StringTrading symbol (e.g., “BTC/USDT”).
mark_price: DecimalMark price (used for unrealized PnL calculation).
index_price: Option<Decimal>Index price (spot index).
estimated_settle_price: Option<Decimal>Estimated settlement price.
last_funding_rate: Option<Decimal>Latest funding rate.
next_funding_time: Option<i64>Next funding time timestamp in milliseconds.
interest_rate: Option<Decimal>Interest rate.
timestamp: i64Data timestamp in milliseconds.
Implementations§
Source§impl MarkPrice
impl MarkPrice
Sourcepub fn new(
symbol: String,
mark_price: Decimal,
index_price: Option<Decimal>,
estimated_settle_price: Option<Decimal>,
last_funding_rate: Option<Decimal>,
next_funding_time: Option<i64>,
interest_rate: Option<Decimal>,
timestamp: i64,
) -> MarkPrice
pub fn new( symbol: String, mark_price: Decimal, index_price: Option<Decimal>, estimated_settle_price: Option<Decimal>, last_funding_rate: Option<Decimal>, next_funding_time: Option<i64>, interest_rate: Option<Decimal>, timestamp: i64, ) -> MarkPrice
Creates a new mark price instance with all fields.
§Arguments
symbol- Trading symbolmark_price- Mark priceindex_price- Index priceestimated_settle_price- Estimated settlement pricelast_funding_rate- Latest funding ratenext_funding_time- Next funding time timestampinterest_rate- Interest ratetimestamp- Data timestamp
Sourcepub fn simple(symbol: String, mark_price: Decimal, timestamp: i64) -> MarkPrice
pub fn simple(symbol: String, mark_price: Decimal, timestamp: i64) -> MarkPrice
Creates a simplified mark price instance with only required fields.
§Arguments
symbol- Trading symbolmark_price- Mark pricetimestamp- Data timestamp
Sourcepub fn basis(&self) -> Option<Decimal>
pub fn basis(&self) -> Option<Decimal>
Calculates the basis (mark price - index price).
§Returns
The basis value, or None if index price is not available.
§Examples
let mark_price = MarkPrice::new(
"BTC/USDT".to_string(),
dec!(50000),
Some(dec!(49995)),
None, None, None, None,
1637000000000
);
assert_eq!(mark_price.basis(), Some(dec!(5)));Sourcepub fn basis_rate(&self) -> Option<Decimal>
pub fn basis_rate(&self) -> Option<Decimal>
Calculates the basis rate (percentage).
§Returns
The basis rate as a percentage, or None if index price is unavailable or zero.
§Examples
let mark_price = MarkPrice::new(
"BTC/USDT".to_string(),
dec!(50100),
Some(dec!(50000)),
None, None, None, None,
1637000000000
);
assert_eq!(mark_price.basis_rate(), Some(dec!(0.2)));Sourcepub fn funding_rate_percent(&self) -> Option<Decimal>
pub fn funding_rate_percent(&self) -> Option<Decimal>
Returns the funding rate as a percentage.
§Returns
The funding rate percentage, or None if not available.
Sourcepub fn time_to_next_funding(&self) -> Option<i64>
pub fn time_to_next_funding(&self) -> Option<i64>
Calculates the time until the next funding in seconds.
§Returns
The seconds until next funding, or None if not available.
Sourcepub fn is_deviation_excessive(&self, threshold_percent: Decimal) -> bool
pub fn is_deviation_excessive(&self, threshold_percent: Decimal) -> bool
Checks if the mark price is at a premium (mark price > index price).
§Returns
true if at premium, false if index price is unavailable.
Sourcepub fn is_discount(&self) -> bool
pub fn is_discount(&self) -> bool
Checks if the mark price is at a discount (mark price < index price).
§Returns
true if at discount, false if index price is unavailable.
Sourcepub fn is_funding_positive(&self) -> bool
pub fn is_funding_positive(&self) -> bool
Checks if the funding rate is positive.
§Returns
true if funding rate is positive, false if not available.