Source code for tradeexecutor.state.valuation

"""Position valuations."""
import datetime
from dataclasses import dataclass

from dataclasses_json import dataclass_json

from tradeexecutor.state.types import USDollarPrice, BlockNumber
from tradingstrategy.types import PrimaryKey, USDollarAmount

[docs]@dataclass_json @dataclass class ValuationUpdate: """Valuation update events. Generated by :py:class:`tradeexecutor.strategy.valuation.ValuationModel` """ position_id: PrimaryKey #: When this valuation was updated. #: #: Valuation can be based on old data, #: this is the strategy cycle timestamp or wall-clock timestmap #: when this event was generated. #: #: See also :py:attr:`valued_at` #: created_at: datetime.datetime #: The block timestamp this valuation is based on. #: #: If not available then wall clock time of the valuation. #: Note that block timestamp may lag :py:attr:`created_at` #: because we cannot use the last block due to #: chain tip instability. #: #: See also :py:attr:`event_generated_at` #: valued_at: datetime.datetime new_value: USDollarAmount #: The new price of the base asset of the position. #: #: Note that position value depends also on gained #: interest and the price of the quote asset. #: new_price: USDollarPrice #: What was the position value before this update. #: old_value: USDollarAmount | None = None #: What was the position base asset price before this update. #: old_price: USDollarPrice | None = None #: What is the block number is valuation is based on. #: #: Must match :py:attr:`valued_at`. #: block_number: BlockNumber | None = None