SyncModel#

tradeexecutor.strategy.sync_model.SyncModel Python class in Trading Strategy framework.

class SyncModel[source]#

Bases: ABC

Abstract class for syncing on-chain fund movements event to the strategy treasury.

__init__()#

Methods

__init__()

create_transaction_builder()

Creates a transaction builder instance to make trades against this asset management model.

get_hot_wallet()

Get the vault address we are using.

get_token_storage_address()

Get the address where tokens are stored.

get_vault_address()

Get the vault address we are using.

is_ready_for_live_trading(state)

Check that the state and sync model is ready for live trading.

resync_nonce()

Re-read hot wallet nonce before trade execution.

sync_initial(state, **kwargs)

Initialize the vault connection.

sync_treasury(strategy_cycle_ts, state[, ...])

Apply the balance sync before each strategy cycle.

get_vault_address()[source]#

Get the vault address we are using.

Returns:

None if the strategy is not vaulted

Return type:

Optional[str]

get_hot_wallet()[source]#

Get the vault address we are using.

Returns:

None if the executor is not using hot wallet (dummy, backtesting, etc.)

Return type:

Optional[HotWallet]

resync_nonce()[source]#

Re-read hot wallet nonce before trade execution.

Ensures that if the private key is used outside the trade executor, we are not getting wrong nonce error when broadcasting the transaction.

is_ready_for_live_trading(state)[source]#

Check that the state and sync model is ready for live trading.

Parameters:

state (State) –

Return type:

bool

abstract get_token_storage_address()[source]#

Get the address where tokens are stored.

Returns:

Vault address for enzyme, wallet address for hot wallet.

Return None for DummySyncModel e.g. in the case of unit and backtests.

Return type:

Optional[str]

abstract sync_initial(state, **kwargs)[source]#

Initialize the vault connection.

Parameters:
  • kwargs

    Extra hints for the initial sync.

    Because reading event from Ethereum blockchain is piss poor mess.

  • state (State) –

abstract sync_treasury(strategy_cycle_ts, state, supported_reserves=None)[source]#

Apply the balance sync before each strategy cycle.

Parameters:
  • strategy_cycle_ts (datetime) –

    The current strategy cycle.

    Resevers are synced before executing the strategy cycle.

  • state (State) – Current state of the execution.

  • supported_reverses

    List of assets the strategy module wants to use as its reserves.

    May be None in testing.

  • supported_reserves (Optional[List[AssetIdentifier]]) –

Returns:

List of balance updates detected.

  • Deposits

  • Redemptions

Return type:

List[BalanceUpdate]

abstract create_transaction_builder()[source]#

Creates a transaction builder instance to make trades against this asset management model.

Only needed when trades are being executed.

Returns:

Depending on the asset management mode.

Return type:

Optional[TransactionBuilder]