Monitoring
During a live trading session you may want to monitor certain variables or the state of your strategy in real-time. You can do this by using the monitoring function of Super Algorithm. Let's look at a simple example to monitor the current state of our strategy.
1. Import the required methods
Add an import for monitor
from the logging module
python
from superalgorithm.utils.logging import set_chart_schema, chart, monitor
Add a class variable that will hold our state which can be IDLE
or OPEN
.
2. Configure the state variable
python
class SMAStrategy(BaseStrategy):
def init(self):
self.state = "IDLE"
...
3. Updating and monitoring the state
Modify the trade_logic
function to set the state when we open or close the position. On each iteration call the monitor
function.
python
async def trade_logic(self):
...
if buy:
await self.open("BTC/USDT", PositionType.LONG, 0.1, OrderType.LIMIT, close)
chart("long", close)
self.state = "OPEN"
if sell:
await self.close("BTC/USDT", PositionType.LONG, 0.1, OrderType.LIMIT, close)
chart("short", close)
self.state = "IDLE"
monitor("state", self.state)
4. Viewing the monitored variables
When you run your backtest only the last state will be visible. During live trading all monitored variables will update on the dashboard or the session details page in real-time.