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: StringTrading pair symbol (e.g., “BTC/USDT”).
bid_price: DecimalBest bid price.
bid_quantity: DecimalBest bid quantity.
ask_price: DecimalBest ask price.
ask_quantity: DecimalBest ask quantity.
timestamp: i64Data timestamp in milliseconds (Unix timestamp).
Implementations§
Source§impl BidAsk
impl BidAsk
Sourcepub fn new(
symbol: String,
bid_price: Decimal,
bid_quantity: Decimal,
ask_price: Decimal,
ask_quantity: Decimal,
timestamp: i64,
) -> BidAsk
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 symbolbid_price- Best bid pricebid_quantity- Best bid quantityask_price- Best ask priceask_quantity- Best ask quantitytimestamp- Data timestamp
Sourcepub fn spread_percent(&self) -> Decimal
pub fn spread_percent(&self) -> Decimal
Sourcepub fn quantity_ratio(&self) -> Decimal
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for BidAsk
impl<'de> Deserialize<'de> for BidAsk
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<BidAsk, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
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 Serialize for BidAsk
impl Serialize for BidAsk
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
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> 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