TradeSuccess

Documentation for eth_defi.trade.TradeSuccess Python class.

class TradeSuccess[source]

Describe the result of a successful Uniswap swap.

See eth_defi.uniswap_v2.analysis.analyse_trade_by_receipt()

Attributes summary

path

Routing path that was used for this trade

amount_in

amount_out_min

amount_out

price

The price of the trade in some order.

amount_in_decimals

Token information bookkeeping

amount_out_decimals

Token information bookkeeping

token0

Uniswap v3 pool token 0

token1

Uniswap v3 pool token 1

lp_fee_paid

How much was the LP fee

Methods summary

__init__(gas_used, effective_gas_price, ...)

get_cost_of_gas()

This will return the gas cost of the transaction in blockchain's native currency e.g.

get_effective_gas_price_gwei()

get_human_price([reverse_token_order])

Get the executed price of this trade in a human-readable form.

path: Optional[List[eth_typing.evm.HexAddress]]

Routing path that was used for this trade

price: decimal.Decimal

The price of the trade in some order.

  • Uniswap v2: Overall price paid as in token (first in the path) to out token (last in the path).

  • Uniswap v3: depends on ticks and order of token0 and token1 in the underlying pool smart contract

Price includes any fees paid during the order routing path.

Note that you get inverse price, if you route ETH-USD or USD-ETH e.g. are you doing buy or sell.

See also get_human_price()

amount_in_decimals: int

Token information bookkeeping

amount_out_decimals: int

Token information bookkeeping

token0: eth_defi.token.TokenDetails | None

Uniswap v3 pool token 0

Needed to calculate reverse token order.

token1: eth_defi.token.TokenDetails | None

Uniswap v3 pool token 1

Needed to calculate reverse token order.

lp_fee_paid: float | None

How much was the LP fee

Note: this is the raw amount in terms of the amount in token

get_human_price(reverse_token_order=False)[source]

Get the executed price of this trade in a human-readable form.

This depends on:

  • If we are on Uniswap v2 or v3

  • If we do buy or sell

  • If quote token is token0 or token1 in Uniswap v3 pool

Example:

# TODO
pass
Parameters

reverse_token_order

Base and quote token order.

Quote token should be natural quote token like USD or ETH based token of the trade. If reverse_token_order is set quote token is token0 of the pool, otherwise token1.

Return type

decimal.Decimal

__init__(gas_used, effective_gas_price, path, amount_in, amount_out_min, amount_out, price, amount_in_decimals, amount_out_decimals, token0, token1, lp_fee_paid)
Parameters
Return type

None