GenericPosition#

API documentation for tradeexecutor.state.generic_position.GenericPosition Python class in Trading Strategy framework.

class GenericPosition[source]#

Bases: ABC

Base class for trading and reserve positions.

Implements common method all positions need to implement.

TODO: How to define generic balance_updates mapping.

See also

  • tradeexecutor.state.state.position.TradingPosition

  • tradeexecutor.state.state.reserve.ReservePosition

__init__()#

Methods

__init__()

add_balance_update_event(event)

Include a new balance update event

calculate_quantity_usd_value(quantity)

Price token amount in this position in US dollar.

get_balance_update_events()

Iterate over all balance update events.

get_base_token_balance_update_quantity()

Get quantity of all balance updates for this position.

get_held_assets()

Get all assets on-chain wallet should hold for this position.

get_human_readable_name()

How to refer this position in log output.

get_quantity()

Get the number of tokens held in this position.

abstract get_human_readable_name()[source]#

How to refer this position in log output.

Return type:

str

abstract get_quantity()[source]#

Get the number of tokens held in this position.

Return type:

Decimal

abstract calculate_quantity_usd_value(quantity)[source]#

Price token amount in this position in US dollar.

An estimation. Use whatever latest exchange rate that is appropriate.

Returns:

Dollar amount

Parameters:

quantity (Decimal) –

Return type:

float

abstract get_base_token_balance_update_quantity()[source]#

Get quantity of all balance updates for this position.

Balance update events are

  • Deposits

  • Redemptions

  • Accounting corrections

… but not trades.

Returns:

What’s the total value of non-trade events affecting the balances of this position.

Return type:

Decimal

abstract 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]

abstract 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) –

abstract 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:

Iterable[Tuple[AssetIdentifier, Decimal]]