pub struct WsTrade {
pub timestamp: u64,
pub symbol: String,
pub side: String,
pub volume: f64,
pub price: f64,
pub tick_direction: TickDirection,
pub id: String,
pub buyer_is_maker: bool,
}Expand description
Structure for individual trade data in WebSocket trade updates.
Contains details of a single executed trade, such as price, volume, and side. Bots use this to monitor market activity and inform trading decisions.
Fields§
§timestamp: u64The timestamp of the trade in milliseconds.
Indicates when the trade was executed. Bots use this to align trade data with other time-series data.
symbol: StringThe trading pair symbol (e.g., “BTCUSDT”).
Identifies the perpetual futures contract for the trade. Bots use this to verify the correct market.
side: StringThe trade side (“Buy” or “Sell”).
Indicates whether the trade was initiated by a buyer or seller. Bots use this to assess market direction and momentum.
volume: f64The trade volume.
The quantity of the base asset traded. Bots use this to gauge trade size and market liquidity.
price: f64The trade price.
The price at which the trade was executed. Bots use this for price discovery and technical analysis.
tick_direction: TickDirectionThe tick direction of the trade.
Indicates whether the trade was an uptick, downtick, or neutral (e.g., “PlusTick”, “MinusTick”). Bots use this to analyze short-term price momentum.
id: StringThe unique trade ID.
A unique identifier for the trade execution. Bots use this to track specific trades and avoid duplicates.
buyer_is_maker: boolWhether the buyer was the maker.
If true, the buyer’s order was on the order book (maker); if false, the buyer took liquidity (taker). Bots use this to analyze market dynamics and order flow.
Implementations§
Source§impl WsTrade
impl WsTrade
Sourcepub fn new(
timestamp: u64,
symbol: &str,
side: &str,
volume: f64,
price: f64,
tick_direction: TickDirection,
id: &str,
buyer_is_maker: bool,
) -> Self
pub fn new( timestamp: u64, symbol: &str, side: &str, volume: f64, price: f64, tick_direction: TickDirection, id: &str, buyer_is_maker: bool, ) -> Self
Creates a new WsTrade instance.
Sourcepub fn timestamp_datetime(&self) -> DateTime<Utc>
pub fn timestamp_datetime(&self) -> DateTime<Utc>
Returns the timestamp as a chrono DateTime.
Sourcepub fn trade_type(&self) -> String
pub fn trade_type(&self) -> String
Returns the trade type as a string.
Sourcepub fn is_downtick(&self) -> bool
pub fn is_downtick(&self) -> bool
Returns true if this is a downtick trade.
Sourcepub fn is_neutral_tick(&self) -> bool
pub fn is_neutral_tick(&self) -> bool
Returns true if this is a neutral tick trade.
Sourcepub fn tick_direction_string(&self) -> &'static str
pub fn tick_direction_string(&self) -> &'static str
Returns the tick direction as a human-readable string.
Sourcepub fn to_summary_string(&self) -> String
pub fn to_summary_string(&self) -> String
Returns a summary string for this trade.
Sourcepub fn to_compact_string(&self) -> String
pub fn to_compact_string(&self) -> String
Returns a compact summary string for this trade.
Sourcepub fn size_category(&self) -> TradeSizeCategory
pub fn size_category(&self) -> TradeSizeCategory
Returns the trade size category.
Sourcepub fn size_category_string(&self) -> &'static str
pub fn size_category_string(&self) -> &'static str
Returns the trade size category as a string.
Sourcepub fn notional_value(&self) -> f64
pub fn notional_value(&self) -> f64
Returns the notional value in quote currency.
Sourcepub fn impact_ratio(&self) -> f64
pub fn impact_ratio(&self) -> f64
Returns the trade impact (volume / price). This can be used to estimate the price impact of the trade.
Sourcepub fn is_recent(&self, max_age_ms: u64) -> bool
pub fn is_recent(&self, max_age_ms: u64) -> bool
Returns true if this trade occurred within the last N milliseconds.
Sourcepub fn price_diff(&self, other: &WsTrade) -> Option<f64>
pub fn price_diff(&self, other: &WsTrade) -> Option<f64>
Compares this trade with another trade and returns the price difference.
Sourcepub fn price_diff_percentage(&self, other: &WsTrade) -> Option<f64>
pub fn price_diff_percentage(&self, other: &WsTrade) -> Option<f64>
Compares this trade with another trade and returns the price difference percentage.