BalanceUpdate#
API documentation for tradeexecutor.state.balance_update.BalanceUpdate Python class in Trading Strategy framework.
- class BalanceUpdate[source]#
Bases:
object
Processed balance update event.
Events that are generated on
Deposits
Redemptions
Interest payments. There will be one event per rebase asset per a trading position. See
tradeexecutor.strategy.sync_model.SyncModel.sync_interests()
.
Events are stored in
TradingPosition
andReservePosition
by their id.Events are referred in
tradeexecutor.sync.Treasury
.- __init__(balance_update_id, cause, position_type, asset, block_mined_at, strategy_cycle_included_at, chain_id, quantity, old_balance, usd_value, created_at=<factory>, previous_update_at=None, owner_address=None, tx_hash=None, log_index=None, position_id=None, notes=None, block_number=None)#
- Parameters:
balance_update_id (int) –
cause (BalanceUpdateCause) –
position_type (BalanceUpdatePositionType) –
asset (AssetIdentifier) –
block_mined_at (datetime) –
strategy_cycle_included_at (datetime.datetime | None) –
chain_id (int) –
quantity (Decimal) –
old_balance (Decimal) –
usd_value (float) –
created_at (datetime.datetime | None) –
previous_update_at (datetime.datetime | None) –
block_number (int | None) –
- Return type:
None
Methods
__init__
(balance_update_id, cause, ...[, ...])from_dict
(kvs, *[, infer_missing])from_json
(s, *[, parse_float, parse_int, ...])get_effective_yearly_yield
([year])How much we are gaining % yearly.
How long it was between this event and previous sync event.
Return whether this event updates reserve balance or open position balance
schema
(*[, infer_missing, only, exclude, ...])to_dict
([encode_json])to_json
(*[, skipkeys, ensure_ascii, ...])Attributes
Block number related to the event.
Log that updated the balance
Human-readable notes regarding this event
Investor address that the balance update is related to
If this update was for open position
What was the event time of the previous update.
Transaction that updated the balance
Allocated from portfolio
What caused the balance update event to happen
What kind of position this event modified
Asset that was updated
When the balance event was generated
When balance event was included to the strategy's treasury.
Chain that updated the balance
What was delta of the asset.
What was the total of the asset in the position before this event was applied.
How much this deposit/redemption was worth
Wall clock time when this event was created
- balance_update_id: int#
Allocated from portfolio
This id is referred in
tradeexecutor.state.position.TradingPosition
andtradeexecutor.state.reserve.ReservePosition
- cause: BalanceUpdateCause#
What caused the balance update event to happen
- position_type: BalanceUpdatePositionType#
What kind of position this event modified
- asset: AssetIdentifier#
Asset that was updated
If this an interest event, this is aToken/vToken asset
- strategy_cycle_included_at: datetime.datetime | None#
When balance event was included to the strategy’s treasury.
The strategy cycle timestamp.
It might be outside the cycle frequency if treasuries were processed in a cron job outside the cycle for slow moving strategies.
For accounting corrections this is set to None.
- old_balance: Decimal#
What was the total of the asset in the position before this event was applied.
- usd_value: float#
How much this deposit/redemption was worth
Used for deposit/redemption inflow/outflow calculation. This is the asset value from our internal price keeping at the time of the event.
- created_at: datetime.datetime | None#
Wall clock time when this event was created
- previous_update_at: datetime.datetime | None = None#
What was the event time of the previous update.
This allows us to calculate the effective interest rate between the update cycles.
This is the same as
block_mined_at
of the previous event.
- tx_hash: Optional[str] = None#
Transaction that updated the balance
Set None for interested calculation updates
- position_id: Optional[int] = None#
If this update was for open position
Set None for reserve updates
- is_reserve_update()[source]#
Return whether this event updates reserve balance or open position balance
- Return type:
- get_update_period()[source]#
How long it was between this event and previous sync event.
- Returns:
None if only inital update made
- Return type:
datetime.timedelta | None
- get_effective_yearly_yield(year=datetime.timedelta(days=365))[source]#
How much we are gaining % yearly.
Based on the this balance update and the previous balance update
Mostly useful for interest rate events
Calculated in tokens (exchange rate immune)
- Returns:
1-based interest.
E.g. 1.02 for 2% yearly gained interest. 0.9 for 10% yearly paid interest.
Positive if we are gaining interest, negative if we are paying interest.
None
if no update period available- Return type:
float | None
- __init__(balance_update_id, cause, position_type, asset, block_mined_at, strategy_cycle_included_at, chain_id, quantity, old_balance, usd_value, created_at=<factory>, previous_update_at=None, owner_address=None, tx_hash=None, log_index=None, position_id=None, notes=None, block_number=None)#
- Parameters:
balance_update_id (int) –
cause (BalanceUpdateCause) –
position_type (BalanceUpdatePositionType) –
asset (AssetIdentifier) –
block_mined_at (datetime) –
strategy_cycle_included_at (datetime.datetime | None) –
chain_id (int) –
quantity (Decimal) –
old_balance (Decimal) –
usd_value (float) –
created_at (datetime.datetime | None) –
previous_update_at (datetime.datetime | None) –
block_number (int | None) –
- Return type:
None