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: OrderSideThe direction of the trade from the base token perspective.
quantity_base: QuantityThe absolute quantity of the base token involved in the swap.
quantity_quote: QuantityThe absolute quantity of the quote token involved in the swap.
spot_price: PriceThe instantaneous pool price after the swap (quote per base).
execution_price: PriceThe average realized execution price for this swap (quote per base).
is_inverted: boolWhether 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
impl SwapTradeInfo
Sourcepub fn set_spot_price_before(&mut self, price: Price)
pub fn set_spot_price_before(&mut self, price: Price)
Sets the spot price before the swap for price impact and slippage calculations.
Sourcepub fn get_price_impact_bps(&self) -> Result<u32>
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
Sourcepub fn get_slippage_bps(&self) -> Result<u32>
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
impl Clone for SwapTradeInfo
Source§fn clone(&self) -> SwapTradeInfo
fn clone(&self) -> SwapTradeInfo
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SwapTradeInfo
impl Debug for SwapTradeInfo
Source§impl PartialEq for SwapTradeInfo
impl PartialEq for SwapTradeInfo
impl Eq for SwapTradeInfo
impl StructuralPartialEq for SwapTradeInfo
Auto Trait Implementations§
impl Freeze for SwapTradeInfo
impl RefUnwindSafe for SwapTradeInfo
impl Send for SwapTradeInfo
impl Sync for SwapTradeInfo
impl Unpin for SwapTradeInfo
impl UnwindSafe for SwapTradeInfo
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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