AssetWithTrackedValue#

API documentation for tradeexecutor.state.identifier.AssetWithTrackedValue Python class in Trading Strategy framework.

class AssetWithTrackedValue[source]#

Bases: object

Track one asset with a value.

  • Track asset quantity

  • The asset can be vToken/aToken for interest based tracking, in this case presentation is set

  • Any tracked asset must get USD oracle price from somewhere

__init__(asset, quantity, last_usd_price, last_pricing_at, created_at=<factory>, created_strategy_cycle_at=None, interest_rate_at_open=None, last_interest_rate=None)#
Parameters:
Return type:

None

Methods

__init__(asset, quantity, last_usd_price, ...)

change_quantity_and_value(delta, price, when)

The tracked asset amount is changing due to position increase/reduce.

from_dict(kvs, *[, infer_missing])

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

get_usd_value()

Rrturn the approximate value of this tracked asset.

reset(quantity)

Reset the loan quantity.

revalue(price, when)

Update the latest known price of the asset.

schema(*[, infer_missing, only, exclude, ...])

to_dict([encode_json])

to_json(*[, skipkeys, ensure_ascii, ...])

Attributes

asset

Asset we are tracking

quantity

How many token units we have.

last_usd_price

What was the last known USD price of a single unit of quantity

last_pricing_at

When the last pricing happened

created_at

Strategy cycle time stamp when the tracking was started

created_strategy_cycle_at

Strategy cycle time stamp when the tracking was started

interest_rate_at_open

Supply or borrow interest rate for this asset when the loan is created

last_interest_rate

Latest supply or borrow interest rate for this asset

asset: AssetIdentifier#

Asset we are tracking

The is aToken or vToken asset.

Use asset.underlying to get the token.

quantity: Decimal#

How many token units we have.

In the case of loans this represents the underlying asset (WETH), not any gained interest (vWETH).

last_usd_price: float#

What was the last known USD price of a single unit of quantity

last_pricing_at: datetime#

When the last pricing happened

created_at: datetime#

Strategy cycle time stamp when the tracking was started

created_strategy_cycle_at: datetime.datetime | None#

Strategy cycle time stamp when the tracking was started

interest_rate_at_open: float | None#

Supply or borrow interest rate for this asset when the loan is created

This is recorded using lending candles data when position is created

last_interest_rate: float | None#

Latest supply or borrow interest rate for this asset

This is recorded using lending candles data every time sync_interests is called

get_usd_value()[source]#

Rrturn the approximate value of this tracked asset.

Priced in the last_usd_price

Return type:

float

revalue(price, when)[source]#

Update the latest known price of the asset.

Parameters:
change_quantity_and_value(delta, price, when, allow_negative=False, available_accrued_interest=Decimal('0'), epsilon=Decimal('1.00000000000000007154242405462192450852805618492324772617063644020163337700068950653076171875E-18'), close_position=False)[source]#

The tracked asset amount is changing due to position increase/reduce.

Parameters:
  • allow_negative (bool) –

    Backtesting helper parameter.

    Bail out with an exception if delta is too high and balance would go negative.

  • available_accrued_interest (Decimal) –

    How much interest we have gained.

    To be used with allow_negative.

  • delta (Decimal) –

  • price (float) –

  • when (datetime) –

  • epsilon (Decimal) –

__init__(asset, quantity, last_usd_price, last_pricing_at, created_at=<factory>, created_strategy_cycle_at=None, interest_rate_at_open=None, last_interest_rate=None)#
Parameters:
Return type:

None

reset(quantity)[source]#

Reset the loan quantity.

See also tradeexecutor.strategy.lending_protocol_leverage.reset_credit_supply_loan().

Parameters:

quantity (Decimal) –