BalanceUpdate#

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

Events are stored in TradingPosition and ReservePosition 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>, owner_address=None, tx_hash=None, log_index=None, position_id=None, notes=None, block_number=None)#
Parameters:
Return type:

None

Methods

__init__(balance_update_id, cause, ...[, ...])

from_dict(kvs, *[, infer_missing])

from_json(s, *[, parse_float, parse_int, ...])

is_reserve_update()

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

Block number related to the event.

log_index

Log that updated the balance

notes

Human-readable notes regarding this event

owner_address

Investor address that the balance update is related to

position_id

If this update was for open position

tx_hash

Transaction that updated the balance

balance_update_id

Allocated from portfolio

cause

What caused the balance update event to happen

position_type

What kind of position this event modified

asset

Asset that was updated

block_mined_at

When the balance event was generated

strategy_cycle_included_at

When balance event was included to the strategy's treasury.

chain_id

Chain that updated the balance

quantity

What was delta of the asset.

old_balance

What was the total of the asset in the position before this event was applied.

usd_value

How much this deposit/redemption was worth

created_at

Wall clock time when this event was created

balance_update_id: int#

Allocated from portfolio

This id is referred in tradeexecutor.state.position.TradingPosition and tradeexecutor.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

block_mined_at: datetime#

When the balance event was generated

The block mined timestamp

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.

chain_id: int#

Chain that updated the balance

quantity: Decimal#

What was delta of the asset.

Positive for deposits, negative for redemptions.

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

owner_address: Optional[str] = None#

Investor address that the balance update is related to

tx_hash: Optional[str] = None#

Transaction that updated the balance

Set None for interested calculation updates

log_index: Optional[int] = None#

Log that updated the balance

Set None for interest rate updates

position_id: Optional[int] = None#

If this update was for open position

Set None for reserve updates

notes: Optional[str] = None#

Human-readable notes regarding this event

block_number: int | None = None#

Block number related to the event.

Not always available.

is_reserve_update()[source]#

Return whether this event updates reserve balance or open position balance

Return type:

bool

__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>, owner_address=None, tx_hash=None, log_index=None, position_id=None, notes=None, block_number=None)#
Parameters:
Return type:

None