BidAsk

Struct BidAsk 

Source
pub struct BidAsk {
    pub symbol: String,
    pub bid_price: Decimal,
    pub bid_quantity: Decimal,
    pub ask_price: Decimal,
    pub ask_quantity: Decimal,
    pub timestamp: i64,
}
Expand description

Best bid and ask prices data structure.

Represents the current best bid and ask prices for a trading pair. Uses Decimal for precise financial calculations.

§Examples

use ccxt_core::types::BidAsk;
use rust_decimal_macros::dec;

let bid_ask = BidAsk {
    symbol: "BTC/USDT".to_string(),
    bid_price: dec!(50000),
    bid_quantity: dec!(1.5),
    ask_price: dec!(50010),
    ask_quantity: dec!(2.0),
    timestamp: 1637000000000,
};

println!("Spread: {}", bid_ask.spread());

Fields§

§symbol: String

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

§bid_price: Decimal

Best bid price.

§bid_quantity: Decimal

Best bid quantity.

§ask_price: Decimal

Best ask price.

§ask_quantity: Decimal

Best ask quantity.

§timestamp: i64

Data timestamp in milliseconds (Unix timestamp).

Implementations§

Source§

impl BidAsk

Source

pub fn new( symbol: String, bid_price: Decimal, bid_quantity: Decimal, ask_price: Decimal, ask_quantity: Decimal, timestamp: i64, ) -> BidAsk

Creates a new BidAsk instance.

§Arguments
  • symbol - Trading pair symbol
  • bid_price - Best bid price
  • bid_quantity - Best bid quantity
  • ask_price - Best ask price
  • ask_quantity - Best ask quantity
  • timestamp - Data timestamp
Source

pub fn spread(&self) -> Decimal

Calculates the bid-ask spread (absolute value).

§Returns

The spread (ask_price - bid_price).

§Examples
let bid_ask = BidAsk::new(
    "BTC/USDT".to_string(),
    dec!(50000), dec!(1.5),
    dec!(50010), dec!(2.0),
    1637000000000
);
assert_eq!(bid_ask.spread(), dec!(10));
Source

pub fn spread_percent(&self) -> Decimal

Calculates the bid-ask spread as a percentage.

§Returns

The spread percentage, or Decimal::ZERO if bid_price is 0.

§Examples
let bid_ask = BidAsk::new(
    "BTC/USDT".to_string(),
    dec!(50000), dec!(1.5),
    dec!(50100), dec!(2.0),
    1637000000000
);
assert_eq!(bid_ask.spread_percent(), dec!(0.2));
Source

pub fn mid_price(&self) -> Decimal

Calculates the mid price (average of bid and ask prices).

§Returns

The mid price.

§Examples
let bid_ask = BidAsk::new(
    "BTC/USDT".to_string(),
    dec!(50000), dec!(1.5),
    dec!(50100), dec!(2.0),
    1637000000000
);
assert_eq!(bid_ask.mid_price(), dec!(50050));
Source

pub fn bid_value(&self) -> Decimal

Calculates the total bid value (bid_price × bid_quantity).

§Returns

The total bid value.

Source

pub fn ask_value(&self) -> Decimal

Calculates the total ask value (ask_price × ask_quantity).

§Returns

The total ask value.

Source

pub fn quantity_ratio(&self) -> Decimal

Calculates the bid-to-ask quantity ratio.

§Returns

The bid-to-ask quantity ratio (bid_quantity / ask_quantity), or Decimal::ZERO if ask_quantity is 0.

Source

pub fn is_valid(&self) -> bool

Checks if the data is valid.

§Returns

Returns true if all prices and quantities are greater than 0 and ask_price >= bid_price.

Trait Implementations§

Source§

impl Clone for BidAsk

Source§

fn clone(&self) -> BidAsk

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 BidAsk

Source§

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

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

impl Default for BidAsk

Source§

fn default() -> BidAsk

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

impl<'de> Deserialize<'de> for BidAsk

Source§

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

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

impl PartialEq for BidAsk

Source§

fn eq(&self, other: &BidAsk) -> 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 BidAsk

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 BidAsk

Auto Trait Implementations§

§

impl Freeze for BidAsk

§

impl RefUnwindSafe for BidAsk

§

impl Send for BidAsk

§

impl Sync for BidAsk

§

impl Unpin for BidAsk

§

impl UnwindSafe for BidAsk

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>,