UniswapV2LivePricing#

tradeexecutor.ethereum.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'))[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. TODO: Fees are incorrectly calculated in the case of multipair routing :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_sell_price(ts, pair, quantity)

Get live price on Uniswap.

get_uniswap(target_pair)

Helper function to speed up Uniswap v2 deployment resolution.

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

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

__init__(web3, pair_universe, routing_model, very_small_amount=Decimal('0.10'))[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. TODO: Fees are incorrectly calculated in the case of multipair routing :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