Agents
Agents are Python classes that define your trading strategy. The same code works across backtesting, paper trading, and live execution.
Creating an agent
Click "New Agent" on the Agents page and choose from one of four templates:
- Blank Agent -- Minimal skeleton to start from scratch.
- SMA Crossover -- Classic moving average crossover. Buys when fast SMA crosses above slow SMA.
- RSI Mean Reversion -- Buys when RSI is oversold, sells when overbought.
- Breakout with SL/TP -- Buys breakouts above recent highs with automatic stop loss and take profit.
Give your agent a name and optional description, then start editing the code.
Editing agents
The agent editor provides a full Python code editing experience:
- Ctrl+S / Cmd+S to save your code
- Tab key inserts 4 spaces for proper indentation
- Copy button to copy the full agent code
- Indicator preview -- collapsible chart showing sample data with up to 5 technical indicators overlaid
- Version history -- every save creates a version. Browse and restore any previous version.
Forking agents
Fork an agent to create a copy while preserving the original. This is useful for experimenting with variations of a strategy without losing your working version. You can fork from:
- The agent editor page
- Any backtest results page
Agent Python API
Your agent file must define a class called Agent with these methods:
initialize(self, context)
Called once when the agent starts. Use it to set up instance variables, parameters, and state.
The context dict contains:
-
"mode"--"backtest"or"dry-run" -
"symbol"-- e.g."BTC-USD" -
"initial_capital"-- starting cash (backtest mode only) -
"fee_rate"-- fee as decimal, e.g. 0.001 for 0.1% (backtest mode only)
on_bar(self, bar)
Called on each new price bar. This is where your strategy logic lives.
The bar dict contains:
-
"timestamp","open","high","low","close","volume"
Must return a dict with:
-
"action"--"buy","sell","short","cover", or"hold" -
"quantity"-- float (used in dry-run mode; backtest auto-sizes from capital)
Optional fields on buy and short signals:
-
"stop_loss"-- price level to auto-exit at a loss -
"take_profit"-- price level to auto-exit at a profit
Optional fields on sell and cover signals:
-
"fraction"-- partial exit (e.g. 0.3 = sell 30% of position) -
"quantity"-- exact number of units to exit -
"exit_reason"-- custom label (e.g. "trailing_stop")
If neither fraction nor quantity is specified, the entire position is closed.
get_state(self)
Return a dict of agent state for logging and debugging snapshots. This is optional but helpful for understanding agent behavior during backtests.
Minimal example
class Agent:
def initialize(self, context):
self.symbol = context.get("symbol", "BTC-USD")
self.prices = []
def on_bar(self, bar):
self.prices.append(bar["close"])
if len(self.prices) < 20:
return {"action": "hold"}
# Your strategy logic here
return {"action": "hold"}
def get_state(self):
return {"prices_count": len(self.prices)}
Using indicators
Import built-in indicators to use in your agent:
from augy_indicators import sma, ema, rsi, macd, bollinger_bands
All indicator functions take a list of price values and return the current indicator value. Call them on each bar after appending the latest price to your history list. See Indicators for the full list of 21 built-in indicators and how to create custom ones.
Agent statuses
- Draft -- Agent created, not yet run
- Ready -- Code saved and ready to backtest
- Running -- Currently executing a backtest or dry run
- Stopped -- Execution completed or manually stopped
- Error -- Execution failed (check logs for details)