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>, read_only_state_copy=None)#
- Parameters:
last_refreshed_at (datetime) –
started_at (datetime) –
executor_running (bool) –
cycles (int) –
position_trigger_checks (int) –
position_revaluations (int) –
frozen_positions (int) –
exception (Optional[ExceptionData]) –
visualisation (Optional[LatestStateVisualisation]) –
summary_statistics (StrategySummaryStatistics) –
version (VersionInfo) –
read_only_state_copy (tradeexecutor.state.state.State | None) –
- 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 a JSON serializable copy.
on_save_hook
(state)Called by JSONStateStore.sync()
schema
(*[, infer_missing, only, exclude, ...])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
The last completed trading cycle
When the executor crashed
How many cycles we have completed since launch
If the exception has crashed, serialise the exception information here.
Reflect executor id back to the web interface, etc.
Is the main loop alive
How many frozen positions the strategy currently has.
Current hot wallet address
How much gas we have in the hot wallet
What's the balance level when we turn on the warning
Hot wallet gas warning for the remote monitors
Measure the lag of strategy thinking and the candle data feed.
How many position revaluations we have completed since the launch
How many position trigger checks we have completed since the last
A read only copy of the strategy state.
The strategy source code.
When the execution state was updated last time
When the executor was started
The strategy visualisation images
Store calculated summary statistics here
Docker image version information
- 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.
- 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
- read_only_state_copy: tradeexecutor.state.state.State | None = None#
A read only copy of the strategy state.
Used by API end points to display metrics on the state.
Created duing sync and start up
Static - the live state may be mutated in other threads, so web endpoints cannot read it.
- static serialise_exception()[source]#
Serialised the latest raised Python exception.
Uses
tblib
to convert the Python traceback to something that is serialisable.- Return type:
- 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:
- __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>, read_only_state_copy=None)#
- Parameters:
last_refreshed_at (datetime) –
started_at (datetime) –
executor_running (bool) –
cycles (int) –
position_trigger_checks (int) –
position_revaluations (int) –
frozen_positions (int) –
exception (Optional[ExceptionData]) –
visualisation (Optional[LatestStateVisualisation]) –
summary_statistics (StrategySummaryStatistics) –
version (VersionInfo) –
read_only_state_copy (tradeexecutor.state.state.State | None) –
- Return type:
None