UniswapV2LivePricing#

API documentation for tradeexecutor.ethereum.uniswap_v2.uniswap_v2_live_pricing.UniswapV2LivePricing Python class in Trading Strategy framework.

class UniswapV2LivePricing[source]#

Bases: EthereumPricingModel

Always pull the latest dollar price for an asset from Uniswap v2 deployment.

Supports

  • Two-way BUSD -> Cake

  • Three-way trades BUSD -> BNB -> Cake

… within a single exchange.

Note

If a trade quantity/currency amount is not given uses a “default small value” that is 0.1. Depending on the token, this value might be too much/too little, as Uniswap fixed point math starts to break for very small amounts. For example, for USDC trade 10 cents is already quite low.

More information

__init__(web3, pair_universe, routing_model, very_small_amount=Decimal('0.10'), epsilon=0.001)[source]#
Parameters:

Methods

__init__(web3, pair_universe, routing_model)

check_supported_quote_token(pair)

get_buy_price(ts, pair, reserve)

Get live price on Uniswap. :param reserve: The buy size in quote token e.g. in dollars :return: Price for one reserve unit e.g. a dollar.

get_mid_price(ts, pair)

Get the mid price from Uniswap pool.

get_pair_fee(ts, pair)

Estimate the trading/LP fees for a trading pair.

get_pair_for_id(internal_id)

Look up a trading pair.

get_quote_token_tvl(timestamp, pair)

Get the raw TVL of a trading pair.

get_sell_price(ts, pair, quantity)

Get live price on Uniswap.

get_uniswap(target_pair)

Helper function to speed up Uniswap v2 deployment resolution.

get_usd_tvl(timestamp, pair)

Get the TVL of a trading pair.

quantize_base_quantity(pair, quantity[, ...])

Convert any base token quantity to the native token units by its ERC-20 decimals.

set_trading_fee_override(trading_fee_override)

Set the trading fee override.

validate_mid_price_for_buy(lp_fee, price, ...)

Validate the mid price calculation for a buy trade.

validate_mid_price_for_sell(lp_fee, ...)

Validate the mid price calculation for a sell trade.

__init__(web3, pair_universe, routing_model, very_small_amount=Decimal('0.10'), epsilon=0.001)[source]#
Parameters:
get_uniswap(target_pair)[source]#

Helper function to speed up Uniswap v2 deployment resolution.

Parameters:

target_pair (TradingPairIdentifier) –

Return type:

UniswapV2Deployment

get_sell_price(ts, pair, quantity)[source]#

Get live price on Uniswap.

Parameters:
Return type:

TradePricing

get_buy_price(ts, pair, reserve)[source]#

Get live price on Uniswap. :param reserve:

The buy size in quote token e.g. in dollars

Returns:

Price for one reserve unit e.g. a dollar

Parameters:
Return type:

TradePricing