TradePricing#

API documentation for tradeexecutor.strategy.trade_pricing.TradePricing Python class in Trading Strategy framework.

class TradePricing[source]#

Bases: object

Describe price results for a price query.

  • Each price result is tied to quantiy/amount

  • Each price result gets a split that describes liquidity provider fees

A helper class to deal with problems of accounting and estimation of prices on Uniswap like exchange.

__init__(price, mid_price, lp_fee=None, pair_fee=None, market_feed_delay=None, side=None, path=None, read_at=None, block_number=None, token_in=None, token_out=None)#
Parameters:
Return type:

None

Methods

__init__(price, mid_price[, lp_fee, ...])

from_dict(kvs, *[, infer_missing])

from_json(s, *[, parse_float, parse_int, ...])

get_fee_percentage()

Returns a single decimal value for the percentage of fees paid.

get_total_lp_fees()

Returns the total lp fees paid (dollars) for the trade.

schema(*[, infer_missing, only, exclude, ...])

to_dict([encode_json])

to_json(*[, skipkeys, ensure_ascii, ...])

Attributes

price

The price we expect this transaction to clear.

mid_price

The theoretical market price during the transaction.

lp_fee

How much liquidity provider fees we are going to pay on this trade.

pair_fee

What was the LP fee % used as the base of the calculations.

market_feed_delay

How old price data we used for this estimate

side

Is this buy or sell trade.

path

Path of the trade One trade can have multiple swaps if there is an intermediary pair.

read_at

When the price read was performed

block_number

What was the block number when the read was performed

token_in

Amount of tokens we put in

token_out

Amount of tokens we got out

price: float#

The price we expect this transaction to clear.

  • LP fees included

  • Price impact included

  • Slippage = 0

mid_price: float#

The theoretical market price during the transaction.

This is the (ask price + bid price) / 2 order book price that no one can obtain.

No LP fees, price impact, etc. are included in this price. It can be used as a basis for other fee estimation calculations.

See mid price for more information.

lp_fee: Optional[list[float]]#

How much liquidity provider fees we are going to pay on this trade.

Set to None if data is not available.

Each trading pair on path will have its own fees. The list is the per path fees.

pair_fee: Optional[list[float]]#

What was the LP fee % used as the base of the calculations.

market_feed_delay: Optional[timedelta]#

How old price data we used for this estimate

side: Optional[bool]#

Is this buy or sell trade.

True for buy. False for sell. None for Unknown.

path: Optional[List[TradingPairIdentifier]]#

Path of the trade One trade can have multiple swaps if there is an intermediary pair.

read_at: Optional[datetime]#

When the price read was performed

block_number: Optional[int]#

What was the block number when the read was performed

token_in: Optional[Decimal]#

Amount of tokens we put in

Tracked for debugging

token_out: Optional[Decimal]#

Amount of tokens we got out

Tracked for debugging

get_total_lp_fees()[source]#

Returns the total lp fees paid (dollars) for the trade.

Return type:

float

get_fee_percentage()[source]#

Returns a single decimal value for the percentage of fees paid. This calculation represents the average of all the pair fees. Calculation is the same for v2 and v3.

Calculation:

-> x(1 - fee0)(1 - fee1) = x(1 - fee) -> (1 - fee0)(1 - fee1) = (1 - fee) -> fee = 1 - (1 - fee0)(1 - fee1)

__init__(price, mid_price, lp_fee=None, pair_fee=None, market_feed_delay=None, side=None, path=None, read_at=None, block_number=None, token_in=None, token_out=None)#
Parameters:
Return type:

None