ReservePosition#
API documentation for 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
See
tradeexecutor.state.portfolio.Portfolio.reserves
.Migration code for old strategies:
source scripts/set-latest-tag.sh docker-compose run -it polygon-momentum-multipair console
assert len(state.portfolio.reserves) == 2, f"Double reserves due to asset id migration: {state.portfolio.reserves}" del state.portfolio.reserves["0x2791bca1f2de4661ed88a30c99a7a9449aa84174"] # Remove old USDC id store.sync(state)
- __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.
Get all assets on-chain wallet should hold 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_base_token_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) –
- get_held_assets()[source]#
Get all assets on-chain wallet should hold for this position.
A position may hold multiple on-chain assets
Multiple positions can share the same on-chain asset
Any on-chain accrued interest is included in
quantity
- Returns:
Iterable (asset, quantity) tuples
- Return type:
- __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