Agent Mode API Manual
A reference for your AI Agent to run the autonomous loop of strategy generation -> backtesting -> evaluation -> improvement using this system's API.
Concept»
Your AI Agent autonomously cycles through "strategy generation -> execution -> evaluation -> improvement."
* The AI Agent is provided and contracted by you; it is not included in this service.
generate a hawk-bt Strategy
auto-execute the STEP_NEXT loop
modify parameters / logic
assess and identify improvement areas
Quick Start»
* hawk-backtester on PyPI is a separate, unrelated package.
- サービスログイン後、with AI Agent タブをクリック
- Enable Agent Mode
- Agent Dashboard をブラウザで開いたままにする
- Execute instructions like the following to your AI Agent:
How It Works
The WASM simulation engine runs in the browser. After the Agent starts HawkEngine and registers a session via POST /v1/backtests, the Agent Dashboard automatically detects it and handles simulation -> analysis -> saving in one flow.
- Agent starts the WebSocket server in the background with
engine.start_background(strategy)and waits withengine.wait_ready() - Agent sends
POST /v1/backtests(session registration +ws_urlspecification) - Agent Dashboard (browser) automatically detects the session, starts the WASM engine, and establishes the WS connection
- After simulation completes, the browser automatically computes all analysis data (resultStats, ticketTraces + MFE/MAE, time series data) and saves it to the server
- Agent retrieves comprehensive analysis data via
GET /v1/backtests/{id}/results
- Agent Dashboard must be kept open — it serves as the WASM execution environment
- No manual operation required — the browser detects QUEUED sessions every 3 seconds and starts them automatically
- Must run on the same machine — the browser and Agent must operate on the same machine (
ws://127.0.0.1:8787)
Security»
API Key
- This is displayed only once upon generation. Be sure to copy and store it securely.
- Valid for 90 days. After expiration, please regenerate from the Dashboard.
- Revoking immediately invalidates the key.
Rate Limits
- API requests: 300 per minute (IP-based)
- Authentication failures: 10 failures from the same IP result in a 15-minute lockout.
WebSocket Connection
- hawk-bt's WS server binds to
127.0.0.1:8787. It is not exposed to external networks. - Origin header validation is performed on connection; connections from origins not on the allow list are rejected with
403 Forbidden. - The Agent and browser must be running on the same machine.
API Reference»
Base URL: https://app.hawk-backtester.com/v1/
Data API
Dataset list (with summary_stats and regime_hint)
Response
Dataset details
Response
Feature list (with category classification)
Response
Backtest API
Session registration + auto-start signal
The browser (Agent Dashboard) automatically detects QUEUED sessions and starts the simulation.
Request
Response (201)
Retrieve results (recommended) — get comprehensive analysis data saved by the browser
After the Agent detects simulation completion via
on_result, retrieve results from this endpoint.Response
Fully save session as SimulationResult
Request
| Field | Type | Required | Description |
|---|---|---|---|
| title | string | - | Save title (default: Agent #N: strategy_note) |
| memo | string | - | Memo (default: strategy_note) |
| strategy_name | string | - | Strategy name (e.g., "SMA_Crossover_v2") |
dataset_id specified at session creation.Leverage is automatically saved from
config.leverage specified at session creation.There is no need to change these — set them correctly in
POST /v1/backtests.
Response
Status API
Agent Mode status + recent sessions
Dashboard timeline (max 50)
WebSocket Protocol»
All WS communication (INIT, STEP_NEXT, orders, result reception) is automatically handled by hawk-bt.
The Agent only needs to be aware of the following 2 points.
Config
Simulation settings are applied to WASM from the browser side (Agent Dashboard).
Can be specified in the config field of POST /v1/backtests.
| Field | Type | Default | Description |
|---|---|---|---|
| leverage | float | 0 | Leverage multiplier (0 = unlimited) |
| commission | float | 0 | Commission rate per order |
| ticketLimitMargin | float | 0 | Required margin ratio |
| maxTicketLimits | int | 0 | Max concurrent positions (0 = unlimited) |
| start_step | int | 0 | シミュレーション開始ステップ (0 = 先頭から) |
| end_step | int | (全バー) | シミュレーション終了ステップ (未指定 = 最後まで) |
HawkEngine: single_run Mode
single_run=True を必ず指定してください。指定しない場合、シミュレーション完了後もプロセスが永久にハングし、Agent の自律ループが停止します。
single_run=True を指定すると、1 回のシミュレーション完了後にプロセスが自動終了し、次のイテレーションへ進めます。
Analysis Result
After simulation completes, the browser automatically computes all analysis data and saves it to the server.
- Receive
BacktestResult(balance/equity arrays) via hawk-bt'son_resultcallback - Simultaneously, the browser computes resultStats, ticketTraces (with MFE/MAE), and time series data (equity, drawdown, exposure, etc.)
- The browser saves comprehensive analysis data to the server via
POST /v1/backtests/report - Agent can retrieve all data via
GET /v1/backtests/{session_id}/results
詳細な分析データは Analysis Data Format を参照。
Analysis Data Format»
Analysis result JSON received after simulation completes.
outcome
| Field | Type | Note |
|---|---|---|
| totalSteps | int | Total Steps |
| endingAssets | float | Final Cash |
| endingEquity | float | Final Equity |
| totalReturn | float | 0.075 = 7.5% |
| maxDrawdown | float | Negative value |
| returnOverMaxDD | float | Return / Max DD |
| vsBuyHold | float | Difference vs. B&H |
exposure
| Field | Type | Note |
|---|---|---|
| avgGrossExposure | float | Average Gross Exposure |
| maxGrossExposure | float | Max Gross Exposure |
| avgNetExposure | float | Average Net Exposure |
| timeInMarket | float | Time in Position Ratio |
| longRatio | float | Long Ratio |
| shortRatio | float | Short Ratio |
| exposureEfficiency | float | totalReturn / avgGrossExposure |
attribution
| Field | Type | Note |
|---|---|---|
| longPnL | float | Cumulative Long PnL |
| shortPnL | float | Cumulative Short PnL |
| costPnL | float | Total Trading Costs |
| totalPnL | float | longPnL + shortPnL + costPnL |
| longContrib | float | longPnL / totalPnL |
| shortContrib | float | shortPnL / totalPnL |
| costContrib | float | costPnL / totalPnL |
| profitFactor | float | Gross Profit / Gross Loss |
| costBurden | float | |costPnL| / |longPnL + shortPnL| |
| winRate | float | 0.58 = 58% |
| winCount | int | Winning Trades |
| lossCount | int | Losing Trades |
| totalTickets | int | winCount + lossCount |
action
| Field | Type | Note |
|---|---|---|
| totalOrders | int | Total Orders |
| buyCount | int | Buy Orders |
| sellCount | int | Sell Orders |
| buySellRatio | float | buyCount / (buyCount + sellCount) |
| ordersPer1000 | float | Orders per 1000 Steps |
| medianHoldingTime | float | Median Holding Time (ms) |
| p90HoldingTime | float | 90th Percentile Holding Time (ms) |
| medianTicketSize | float | Median Trade Size |
| partialCloseCount | int | Partial Close Count |
ticketTraces
Details of each trade + MFE/MAE (Max Favorable/Adverse Excursion).
| Field | Type | Note |
|---|---|---|
| ticketId | int | Ticket ID |
| side | string | "long" or "short" |
| entryTime | float | Entry Time (ms) |
| exitTime | float | Exit Time (ms) |
| entryPrice | float | Entry Price |
| exitPrice | float | Exit Price |
| units | float | Trade Size |
| lifetime | float | Holding Time (exitTime - entryTime) |
| exitReason | int | 0=SL, 1=TP, 2=Strategy, 5=Force |
| pnl | float | PnL (units * price diff) |
| pnlPct | float | PnL Rate (%) |
| mfe | float | Max Favorable Excursion (amount) |
| mae | float | Max Adverse Excursion (amount) |
timeSeries
Time series data (downsampled to max 2000 points).
| Field | Type | Note |
|---|---|---|
| timestamps | float[] | Timestamp (ms) |
| equity | float[] | Equity (including unrealized PnL) |
| assets | float[] | Cash Balance |
| buyAndHold | float[] | Buy & Hold Comparison Curve |
| drawdown | float[] | Drawdown (negative value) |
| netExposure | float[] | Net Exposure |
| grossExposure | float[] | Gross Exposure |
| marginRatio | float[] | Margin Usage Ratio |
| cumulativeLongPnL | float[] | Cumulative Long PnL |
| cumulativeShortPnL | float[] | Cumulative Short PnL |
| ticketLongCount | float[] | Cumulative Long Ticket Count |
| ticketShortCount | float[] | Cumulative Short Ticket Count |
| tokenLongCount | float[] | Cumulative Long Token Count |
| tokenShortCount | float[] | Cumulative Short Token Count |
totalSteps / initialAssets
Example Code»
Below are code examples corresponding to each step of the Concept.
Your AI Agent executes these in order and runs the loop autonomously.