ReservePosition#

tradeexecutor.state.reserve.ReservePosition Python class in Trading Strategy framework.

class ReservePosition[source]#

Bases: GenericPosition

Manage reserve currency of a portfolio.

  • One portfolio can have multiple reserve currencies, but currently the code is simplified to handle only one reserve currency

__init__(asset, quantity, last_sync_at, reserve_token_price, last_pricing_at, initial_deposit=None, initial_deposit_reserve_token_price=None, balance_updates=<factory>)#
Parameters:
Return type:

None

Methods

__init__(asset, quantity, last_sync_at, ...)

add_balance_update_event(event)

Include a new balance update event

calculate_quantity_usd_value(quantity)

Return the quantity

from_dict(kvs, *[, infer_missing])

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

get_balance_update_events()

Iterate over all balance update events.

get_balance_update_quantity()

Get quantity of all balance udpdates for this position.

get_human_readable_name()

How to refer this position in log output.

get_identifier()

get_quantity()

Get the absolute amount of reserve tokens held.

get_total_equity()

Approximation of total equity of this reserve.

get_value()

Approximation of current value of this reserve.

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

to_dict([encode_json])

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

update_value([exchange_rate])

Updated portfolio's reserve balance.

Attributes

asset

What is our reserve currency

quantity

How much reserves we have currently

last_sync_at

When we processed deposits/withdraws last time

reserve_token_price

What was the US dollar exchange rate of our reserves

last_pricing_at

When we fetched the US dollar exchange rate of our reserves last time

initial_deposit

What was the first deposit amount.

initial_deposit_reserve_token_price

What was the first deposit exchange rate.

balance_updates

BalanceUpdate.id -> BalanceUpdate mapping

asset: AssetIdentifier#

What is our reserve currency

quantity: Decimal#

How much reserves we have currently

last_sync_at: datetime#

When we processed deposits/withdraws last time

reserve_token_price: Optional[float]#

What was the US dollar exchange rate of our reserves

last_pricing_at: Optional[datetime]#

When we fetched the US dollar exchange rate of our reserves last time

initial_deposit: Optional[Decimal]#

What was the first deposit amount.

Used to shortcut the backtest performance benchmark.

TODO: Remove in future versions as SyncModel has been rewritten.

initial_deposit_reserve_token_price: Optional[float]#

What was the first deposit exchange rate.

Used to shortcut the backtest performance benchmark.

TODO: Remove in future versions as SyncModel has been rewritten.

balance_updates: Dict[int, BalanceUpdate]#

BalanceUpdate.id -> BalanceUpdate mapping

get_human_readable_name()[source]#

How to refer this position in log output.

Return type:

str

get_value()[source]#

Approximation of current value of this reserve.

Return type:

float

get_quantity()[source]#

Get the absolute amount of reserve tokens held.

Return type:

Decimal

get_total_equity()[source]#

Approximation of total equity of this reserve.

Return type:

float

get_balance_update_quantity()[source]#

Get quantity of all balance udpdates for this position.

Returns:

How much deposit and in-kind redemptions events have affected this position.

Decimal zero epsilon noted.

Return type:

Decimal

update_value(exchange_rate=1)[source]#

Updated portfolio’s reserve balance.

Read all balance update events and sets the current denormalised value of the reserves.

This is read in tradeeexecutor.state.portfolio.Portfolio.get_default_reserve() and used by strategy in various positions.

Parameters:

exchange_rate (float) – USD exchange rate of the reserve asset

calculate_quantity_usd_value(quantity)[source]#

Return the quantity

Now hardwired all reserves are 1:1 USDC.

Returns:

Dollar amount

Parameters:

quantity (Decimal) –

Return type:

float

get_balance_update_events()[source]#

Iterate over all balance update events.

Balance updates describe external events affecting the balance of this position: the update was not triggered by the trade executor itself.

  • Deposits

  • Redemptions

  • Account corrections

  • Trades are not included here

Return type:

Iterable[BalanceUpdate]

add_balance_update_event(event)[source]#

Include a new balance update event

Raises:

BalanceUpdateEventAlreadyAdded – In the case of a duplicate and event id is already used.

Parameters:

event (BalanceUpdate) –

__init__(asset, quantity, last_sync_at, reserve_token_price, last_pricing_at, initial_deposit=None, initial_deposit_reserve_token_price=None, balance_updates=<factory>)#
Parameters:
Return type:

None