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, ...])Iterate over all balance update events.
Get quantity of all balance udpdates for this position.
How to refer this position in log output.
get_identifier
()Get the absolute amount of reserve tokens held.
Approximation of total equity of this reserve.
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
What is our reserve currency
How much reserves we have currently
When we processed deposits/withdraws last time
What was the US dollar exchange rate of our reserves
When we fetched the US dollar exchange rate of our reserves last time
What was the first deposit amount.
What was the first deposit exchange rate.
BalanceUpdate.id -> BalanceUpdate mapping
- asset: AssetIdentifier#
What is our reserve currency
- 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_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:
- 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.
- 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:
- 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