Skip to main content

WsTrade

Struct WsTrade 

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

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

The trading pair symbol (e.g., “BTCUSDT”).

Identifies the perpetual futures contract for the trade. Bots use this to verify the correct market.

§side: String

The 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: f64

The trade volume.

The quantity of the base asset traded. Bots use this to gauge trade size and market liquidity.

§price: f64

The trade price.

The price at which the trade was executed. Bots use this for price discovery and technical analysis.

§tick_direction: TickDirection

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

The unique trade ID.

A unique identifier for the trade execution. Bots use this to track specific trades and avoid duplicates.

§buyer_is_maker: bool

Whether 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

Source

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.

Source

pub fn is_buy(&self) -> bool

Returns true if this is a buy trade.

Source

pub fn is_sell(&self) -> bool

Returns true if this is a sell trade.

Source

pub fn timestamp_datetime(&self) -> DateTime<Utc>

Returns the timestamp as a chrono DateTime.

Source

pub fn age_ms(&self) -> u64

Returns the age of the trade in milliseconds.

Source

pub fn is_stale(&self) -> bool

Returns true if the trade is stale (older than 5 seconds).

Source

pub fn value(&self) -> f64

Returns the trade value (price * volume).

Source

pub fn is_taker(&self) -> bool

Returns true if this is a taker trade (buyer is not maker).

Source

pub fn is_maker(&self) -> bool

Returns true if this is a maker trade (buyer is maker).

Source

pub fn trade_type(&self) -> String

Returns the trade type as a string.

Source

pub fn is_uptick(&self) -> bool

Returns true if this is an uptick trade.

Source

pub fn is_downtick(&self) -> bool

Returns true if this is a downtick trade.

Source

pub fn is_neutral_tick(&self) -> bool

Returns true if this is a neutral tick trade.

Source

pub fn tick_direction_string(&self) -> &'static str

Returns the tick direction as a human-readable string.

Source

pub fn is_valid(&self) -> bool

Returns true if the trade is valid for analysis.

Source

pub fn to_summary_string(&self) -> String

Returns a summary string for this trade.

Source

pub fn to_compact_string(&self) -> String

Returns a compact summary string for this trade.

Source

pub fn size_category(&self) -> TradeSizeCategory

Returns the trade size category.

Source

pub fn size_category_string(&self) -> &'static str

Returns the trade size category as a string.

Source

pub fn notional_value(&self) -> f64

Returns the notional value in quote currency.

Source

pub fn impact_ratio(&self) -> f64

Returns the trade impact (volume / price). This can be used to estimate the price impact of the trade.

Source

pub fn is_recent(&self, max_age_ms: u64) -> bool

Returns true if this trade occurred within the last N milliseconds.

Source

pub fn price_diff(&self, other: &WsTrade) -> Option<f64>

Compares this trade with another trade and returns the price difference.

Source

pub fn price_diff_percentage(&self, other: &WsTrade) -> Option<f64>

Compares this trade with another trade and returns the price difference percentage.

Source

pub fn as_tuple(&self) -> (u64, &str, &str, f64, f64, TickDirection, &str, bool)

Returns the trade data as a tuple for easy pattern matching.

Trait Implementations§

Source§

impl Clone for WsTrade

Source§

fn clone(&self) -> WsTrade

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 WsTrade

Source§

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

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

impl<'de> Deserialize<'de> for WsTrade

Source§

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

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

impl Serialize for WsTrade

Source§

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

Serialize this value into the given Serde serializer. Read more

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