PriceEntry

Documentation for eth_defi.price_oracle.oracle.PriceEntry 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

block_hash

Hash of the block where this price was picked in.

block_number

Block number where this transaction happened

first_seen_at_block_number

Chain reorganisation helper.

pool_contract_address

Uni v2 pair contract address or similar

tx_hash

Transaction where did we pick the event logs

volume

How much volume this trade carried (if available) Expressed in the quote token.

timestamp

When price entry was booked.

price

When price entry was booked.

source

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.

pool_contract_address: Optional[str] = None

Uni v2 pair contract address or similar

block_number: Optional[int] = None

Block number where this transaction happened

tx_hash: Optional[str] = None

Transaction where did we pick the event logs

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
Return type

None