RunState#

API documentation for tradeexecutor.strategy.run_state.RunState Python class in Trading Strategy framework.

class RunState[source]#

Bases: object

Run state.

The status of a single trade-executor launch.

  • Anything here is not persistent, but only kept in memory while trade-executor is running

A singleton instance communicates the state between the trade executor main loop and the webhook.

The webhook can display the exception that caused the trade executor crash.

Partially returned by different endpoints in API

  • /status

  • /source

  • /visualisation

  • /summary

__init__(executor_id=None, last_refreshed_at=<factory>, started_at=<factory>, executor_running=True, completed_cycle=None, cycles=0, position_trigger_checks=0, position_revaluations=0, frozen_positions=0, crashed_at=None, exception=None, hot_wallet_address=None, hot_wallet_gas=None, hot_wallet_gas_warning_level=None, hot_wallet_gas_warning_message=None, source_code=None, visualisation=<factory>, summary_statistics=<factory>, market_data_feed_lag=None, version=<factory>)#
Parameters:
Return type:

None

Methods

__init__([executor_id, last_refreshed_at, ...])

bumb_refreshed()

from_dict(kvs, *[, infer_missing])

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

make_exportable_copy()

Make a JSON serializable copy.

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

serialise_exception()

Serialised the latest raised Python exception.

set_fail()

Set the trade-executor main loop to a failed state.

to_dict([encode_json])

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

update_complete_cycle(cycle)

Attributes

completed_cycle

The last completed trading cycle

crashed_at

When the executor crashed

cycles

How many cycles we have completed since launch

exception

If the exception has crashed, serialise the exception information here.

executor_id

Reflect executor id back to the web interface, etc.

executor_running

Is the main loop alive

frozen_positions

How many frozen positions the strategy currently has.

hot_wallet_address

Current hot wallet address

hot_wallet_gas

How much gas we have in the hot wallet

hot_wallet_gas_warning_level

What's the balance level when we turn on the warning

hot_wallet_gas_warning_message

Hot wallet gas warning for the remote monitors

market_data_feed_lag

Measure the lag of strategy thinking and the candle data feed.

position_revaluations

How many position revaluations we have completed since the launch

position_trigger_checks

How many position trigger checks we have completed since the last

source_code

The strategy source code.

last_refreshed_at

When the execution state was updated last time

started_at

When the executor was started

visualisation

The strategy visualisation images

summary_statistics

Store calculated summary statistics here

version

Docker image version information

executor_id: Optional[str] = None#

Reflect executor id back to the web interface, etc.

last_refreshed_at: datetime#

When the execution state was updated last time

started_at: datetime#

When the executor was started

executor_running: bool = True#

Is the main loop alive

Set to false on the crashing exception

completed_cycle: Optional[int] = None#

The last completed trading cycle

cycles: int = 0#

How many cycles we have completed since launch

position_trigger_checks: int = 0#

How many position trigger checks we have completed since the last

position_revaluations: int = 0#

How many position revaluations we have completed since the launch

frozen_positions: int = 0#

How many frozen positions the strategy currently has.

  • 0 = things look good

> 0 = manual intervention needed

crashed_at: Optional[datetime] = None#

When the executor crashed

Trade execution main loop was halted by a Python exception.

exception: Optional[ExceptionData] = None#

If the exception has crashed, serialise the exception information here.

See serialise_exception()

hot_wallet_address: Optional[str] = None#

Current hot wallet address

hot_wallet_gas: Optional[Decimal] = None#

How much gas we have in the hot wallet

hot_wallet_gas_warning_level: Optional[Decimal] = None#

What’s the balance level when we turn on the warning

hot_wallet_gas_warning_message: Optional[str] = None#

Hot wallet gas warning for the remote monitors

Pre-rendered for the convenience.

source_code: Optional[str] = None#

The strategy source code.

TODO: Move this to somewhere else long term. Use /source API endpoint to get this.

visualisation: Optional[LatestStateVisualisation]#

The strategy visualisation images

summary_statistics: StrategySummaryStatistics#

Store calculated summary statistics here

market_data_feed_lag: Optional[timedelta] = None#

Measure the lag of strategy thinking and the candle data feed.

What’s the lag of candle creation time and when the data is processed.

Regarding the candle data timestamps

  • The last candle should be the “real time candle” that is unfinished and started at the last minute XX:00

  • The candle before the last candle should be last “fully completed candle” that finished at XX:00 and no more new trades come to this candle

  • TimescaleDB should give us real-time data, but how much internal lag we have before a new swap hits to our database and is rolled up the TimescaleDB hypertable is a subject to measurement, to give an idea how close to fee of lag strategies can operate

version: VersionInfo#

Docker image version information

static serialise_exception()[source]#

Serialised the latest raised Python exception.

Uses tblib to convert the Python traceback to something that is serialisable.

Return type:

ExceptionData

set_fail()[source]#

Set the trade-executor main loop to a failed state.

Reads the latest exception from Python stack and generates as exceptino data for it so webhook can export it.

make_exportable_copy()[source]#

Make a JSON serializable copy.

Special fields like source code and images are not exported.

Return type:

RunState

__init__(executor_id=None, last_refreshed_at=<factory>, started_at=<factory>, executor_running=True, completed_cycle=None, cycles=0, position_trigger_checks=0, position_revaluations=0, frozen_positions=0, crashed_at=None, exception=None, hot_wallet_address=None, hot_wallet_gas=None, hot_wallet_gas_warning_level=None, hot_wallet_gas_warning_message=None, source_code=None, visualisation=<factory>, summary_statistics=<factory>, market_data_feed_lag=None, version=<factory>)#
Parameters:
Return type:

None