SwapTradeInfo

Struct SwapTradeInfo 

Source
pub struct SwapTradeInfo {
    pub order_side: OrderSide,
    pub quantity_base: Quantity,
    pub quantity_quote: Quantity,
    pub spot_price: Price,
    pub execution_price: Price,
    pub is_inverted: bool,
    pub spot_price_before: Option<Price>,
}
Expand description

Trade information derived from raw swap data, normalized to market conventions.

This structure represents a Uniswap V3 swap translated into standard trading terminology (base/quote, buy/sell) for consistency with traditional financial data systems.

§Base/Quote Token Convention

Tokens are assigned base/quote roles based on their priority:

  • Higher priority token → base (asset being traded)
  • Lower priority token → quote (pricing currency)

This may differ from the pool’s token0/token1 ordering. When token priority differs from pool ordering, we say the market is “inverted”:

  • NOT inverted: token0=base, token1=quote
  • Inverted: token0=quote, token1=base

§Prices

  • spot_price: Instantaneous pool price after the swap (from sqrt_price_x96)
  • execution_price: Average realized price for this swap (from amount ratio)

Both prices are in quote/base direction (e.g., USDC per WETH) and adjusted for token decimals.

Fields§

§order_side: OrderSide

The direction of the trade from the base token perspective.

§quantity_base: Quantity

The absolute quantity of the base token involved in the swap.

§quantity_quote: Quantity

The absolute quantity of the quote token involved in the swap.

§spot_price: Price

The instantaneous pool price after the swap (quote per base).

§execution_price: Price

The average realized execution price for this swap (quote per base).

§is_inverted: bool

Whether the base/quote assignment differs from token0/token1 ordering.

§spot_price_before: Option<Price>

The pool price before that swap executed(optional).

Implementations§

Source§

impl SwapTradeInfo

Source

pub fn set_spot_price_before(&mut self, price: Price)

Sets the spot price before the swap for price impact and slippage calculations.

Source

pub fn get_price_impact_bps(&self) -> Result<u32>

Calculates price impact in basis points (requires token references for decimal adjustment).

Price impact measures the market movement caused by the swap size, excluding fees. This is the percentage change in spot price from before to after the swap.

§Returns

Price impact in basis points (10000 = 100%)

§Errors

Returns error if price calculations fail

Source

pub fn get_slippage_bps(&self) -> Result<u32>

Calculates slippage in basis points (requires token references for decimal adjustment).

Slippage includes both price impact and fees, representing the total deviation from the spot price before the swap. This measures the total cost to the trader.

§Returns

Total slippage in basis points (10000 = 100%)

§Errors

Returns error if price calculations fail

Trait Implementations§

Source§

impl Clone for SwapTradeInfo

Source§

fn clone(&self) -> SwapTradeInfo

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SwapTradeInfo

Source§

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

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

impl PartialEq for SwapTradeInfo

Source§

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

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

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 Eq for SwapTradeInfo

Source§

impl StructuralPartialEq for SwapTradeInfo

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> Ungil for T
where T: Send,