EthereumPricingModel#
API documentation for tradeexecutor.ethereum.eth_pricing_model.EthereumPricingModel Python class in Trading Strategy framework.
- class EthereumPricingModel[source]#
Bases:
PricingModel
Get a price for the asset.
Needed for various aspects
Revaluate portfolio positiosn
Estimate buy/sell price for the live trading so we can calculate slippage
Get the historical price in backtesting
Timestamp is passed to the pricing method. However we expect it only be honoured during the backtesting - live execution may always use the latest price.
Note
For example, in futures markets there could be different fees on buy/sell transctions.
Used by UniswapV2LivePricing and UniswapV3LivePricing
- __init__(web3, pair_universe, routing_model, very_small_amount, epsilon=0.001)[source]#
- Parameters:
web3 (Web3) –
pair_universe (PandasPairUniverse) –
routing_model (EthereumRoutingModel) –
very_small_amount (Decimal) –
Methods
__init__
(web3, pair_universe, routing_model, ...)check_supported_quote_token
(pair)get_buy_price
(ts, pair, reserve)Get the sell price for an asset.
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 the sell price for an asset.
get_uniswap
(target_pair)Helper function to speed up Uniswap v2 or v3 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, epsilon=0.001)[source]#
- Parameters:
web3 (Web3) –
pair_universe (PandasPairUniverse) –
routing_model (EthereumRoutingModel) –
very_small_amount (Decimal) –
- get_pair_for_id(internal_id)[source]#
Look up a trading pair.
Useful if a strategy is only dealing with pair integer ids.
- Returns:
None if the price data is not available
- Parameters:
internal_id (int) –
- Return type:
- get_mid_price(ts, pair)[source]#
Get the mid price from Uniswap pool.
Gets tricky, because we calculate dollar mid-price, not quote token midprice.
Mid price is an non-trddeable price between the best ask and the best pid.
- Parameters:
ts (datetime) – Timestamp. Ignored for live pricing models.
pair (TradingPairIdentifier) – Which trading pair price we query.
- Returns:
The mid price for the pair at a timestamp.
- Return type:
- get_pair_fee(ts, pair)[source]#
Estimate the trading/LP fees for a trading pair.
This information can come either from the exchange itself (Uni v2 compatibles), or from the trading pair (Uni v3).
The return value is used to fill the fee values for any newly opened trades.
- Parameters:
ts (datetime) – Timestamp of the trade. Note that currently fees do not vary over time, but might do so in the future.
pair (TradingPairIdentifier) –
Trading pair for which we want to have the fee.
Can be left empty if the underlying exchange is always offering the same fee.
- Returns:
The estimated trading fee, expressed as %.
Returns None if the fee information is not available. This can be different from zero fees.
- Return type:
- validate_mid_price_for_sell(lp_fee, mid_price, price, quantity)[source]#
Validate the mid price calculation for a sell trade.
- Should basically have:
lp_fee = (mid_price - price)/mid_price * float(quantity)
- Parameters:
lp_fee – The fee that is paid to the LPs.
mid_price – The mid price of the pair.
price – The price of the trade.
quantity – The quantity of the trade.
- validate_mid_price_for_buy(lp_fee, price, mid_price, reserve)[source]#
Validate the mid price calculation for a buy trade.
- Should basically have:
lp_fee = (price - mid_price)/price * float(reserve)
- Parameters:
lp_fee – The fee that is paid to the LPs.
price – The price of the trade.
mid_price – The mid price of the pair.
reserve – The reserve of the trade.
- abstract get_uniswap(target_pair)[source]#
Helper function to speed up Uniswap v2 or v3 deployment resolution.
- Parameters:
target_pair (TradingPairIdentifier) –
- Return type:
eth_defi.uniswap_v2.deployment.UniswapV2Deployment | eth_defi.uniswap_v3.deployment.UniswapV3Deployment
- abstract get_sell_price(ts, pair, quantity)[source]#
Get the sell price for an asset.
- Parameters:
ts (datetime) – When to get the price. Used in backtesting. Live models may ignore.
pair (TradingPairIdentifier) – Trading pair we are intereted in
quantity (Optional[Decimal]) – If the sel quantity is known, get the price with price impact.
- Returns:
Price structure for the trade.
- Return type:
- abstract get_buy_price(ts, pair, reserve)[source]#
Get the sell price for an asset.
- Parameters:
ts (datetime) – When to get the price. Used in backtesting. Live models may ignore.
pair (TradingPairIdentifier) – Trading pair we are intereted in
reserve (Optional[Decimal]) – If the buy token quantity quantity is known, get the buy price with price impact.
- Returns:
Price structure for the trade.
- Return type: