UniswapV2LivePricing#
tradeexecutor.ethereum.uniswap_v2_live_pricing.UniswapV2LivePricing class.
- class UniswapV2LivePricing[source]#
Bases:
PricingModel
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
web3 (Web3) –
pair_universe (PandasPairUniverse) –
routing_model (UniswapV2SimpleRoutingModel) –
Methods
__init__
(web3, pair_universe, routing_model)check_supported_quote_token
(pair)get_buy_price
(ts, pair, reserve)Get live price on Uniswap.
get_pair_for_id
(internal_id)Look up a trading pair.
get_sell_price
(ts, pair, quantity)Get live price on Uniswap.
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
web3 (Web3) –
pair_universe (PandasPairUniverse) –
routing_model (UniswapV2SimpleRoutingModel) –
- get_pair_for_id(internal_id)[source]#
Look up a trading pair.
Useful if a strategy is only dealing with pair integer ids.
- Parameters
internal_id (int) –
- Return type
- get_sell_price(ts, pair, quantity)[source]#
Get live price on Uniswap.
- Parameters
ts (datetime) –
pair (TradingPairIdentifier) –
- Return type
- get_buy_price(ts, pair, reserve)[source]#
Get live price on Uniswap.
- Parameters
reserve (Optional[Decimal]) – The buy size in quote token e.g. in dollars
ts (datetime) –
pair (TradingPairIdentifier) –
- Returns
Price for one reserve unit e.g. a dollar
- Return type
- quantize_base_quantity(pair, quantity, rounding='ROUND_DOWN')[source]#
Convert any base token quantity to the native token units by its ERC-20 decimals.
- Parameters
pair (TradingPairIdentifier) –
quantity (Decimal) –
- Return type