MarkPrice

Struct MarkPrice 

Source
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: String

Trading symbol (e.g., “BTC/USDT”).

§mark_price: Decimal

Mark 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: i64

Data timestamp in milliseconds.

Implementations§

Source§

impl MarkPrice

Source

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 symbol
  • mark_price - Mark price
  • index_price - Index price
  • estimated_settle_price - Estimated settlement price
  • last_funding_rate - Latest funding rate
  • next_funding_time - Next funding time timestamp
  • interest_rate - Interest rate
  • timestamp - Data timestamp
Source

pub fn simple(symbol: String, mark_price: Decimal, timestamp: i64) -> MarkPrice

Creates a simplified mark price instance with only required fields.

§Arguments
  • symbol - Trading symbol
  • mark_price - Mark price
  • timestamp - Data timestamp
Source

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)));
Source

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)));
Source

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.

Source

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.

Source

pub fn is_deviation_excessive(&self, threshold_percent: Decimal) -> bool

Checks if the mark price deviation from index price exceeds a threshold.

§Arguments
  • threshold_percent - Threshold percentage (e.g., dec!(1) for 1%)
§Returns

true if deviation exceeds threshold, false if index price is unavailable.

Source

pub fn is_premium(&self) -> 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.

Source

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.

Source

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.

Source

pub fn is_valid(&self) -> bool

Checks if the data is valid.

§Returns

true if mark price is greater than zero.

Trait Implementations§

Source§

impl Clone for MarkPrice

Source§

fn clone(&self) -> MarkPrice

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MarkPrice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for MarkPrice

Source§

fn default() -> MarkPrice

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for MarkPrice

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<MarkPrice, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for MarkPrice

Source§

fn eq(&self, other: &MarkPrice) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for MarkPrice

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for MarkPrice

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,