PriceEntry
Documentation for eth_defi.price_oracle.oracle.PriceEntry Python class.
- class PriceEntry[source]
A single source entry for price calculations.
PriceOracle
maintains a buffer of these to calculate a smoothed out price, like py:func:time_weighted_average_price.Price entry can be sourced from:
Manually entered price
Price from Uniswap v2 sync events
Price from some other event
Attributes summary
Hash of the block where this price was picked in.
Block number where this transaction happened
Chain reorganisation helper.
Uni v2 pair contract address or similar
Transaction where did we pick the event logs
How much volume this trade carried (if available) Expressed in the quote token.
When price entry was booked.
When price entry was booked.
What was the source of this price entry
Methods summary
__init__
(timestamp, price, source[, volume, ...])update_chain_reorg
(new_entry)Update entry data in the case of chain reorganisation.
- timestamp: datetime.datetime
When price entry was booked. All timestamps must be UTC, Python naive datetimes.
- price: decimal.Decimal
When price entry was booked. This should be base token / quote token, in its human readable format, all decimals converted correctly.
- source: eth_defi.price_oracle.oracle.PriceSource
What was the source of this price entry
- volume: Optional[decimal.Decimal] = None
How much volume this trade carried (if available) Expressed in the quote token.
- block_hash: Optional[str] = None
Hash of the block where this price was picked in. Can be used to remove data for blocks in unstable chain tip.
- first_seen_at_block_number: Optional[int] = None
Chain reorganisation helper. This is set on the old event when we detect duplicate entry. We never remove items from heap, but mark them deprecated. Items are eventually cleaned up when they expire.
- update_chain_reorg(new_entry)[source]
Update entry data in the case of chain reorganisation.
TODO: We are not yet dealing with the situation if the transaction gets reorganisated and rejected.
- Parameters
new_entry (eth_defi.price_oracle.oracle.PriceEntry) –
- __init__(timestamp, price, source, volume=None, pool_contract_address=None, block_number=None, tx_hash=None, block_hash=None, first_seen_at_block_number=None)
- Parameters
timestamp (datetime.datetime) –
price (decimal.Decimal) –
source (eth_defi.price_oracle.oracle.PriceSource) –
volume (Optional[decimal.Decimal]) –
- Return type
None