Rules
Rules hold a session or demo account to limits you set, such as a daily loss or a maximum drawdown. You send them with rules when you create it. They are copied on, fixed from then on, and returned when you read it.
"rules": [
{ "type": "daily_loss", "limit": 500, "on_breach": "block_order" },
{ "type": "max_drawdown", "limit": { "percent": 10 }, "mode": "trailing", "on_breach": "close_and_end" },
{ "type": "max_open_positions", "limit": 3 },
{ "type": "profit_target", "target": 1000 },
{ "type": "slippage", "ticks": 1 }
]Money limits are USD, or a percentage of the starting balance written { "percent": 10 }. Each rule can carry your own id; otherwise it is named after its type. Reading it back gives the full form, with every default filled in: { "day_reset": { "time": "17:00", "tz": "America/New_York" }, "rules": [ … ] }.
Rule types
Type | Fields | Breaches when |
|---|---|---|
|
| The loss since the day started reaches |
|
| Equity falls |
|
| One market's position grows past it |
|
| More positions are open at once |
|
| Equity reaches it, or an exit brings the closed balance to it |
|
| Never: every market and stop fill moves this many ticks against the trader. Limit orders never slip |
The trading day resets at 17:00 New York time, the FX rollover, which follows US daylight saving. To move it, send the object form: { "day_reset": { "time": "00:00", "tz": "Europe/London" }, "rules": [ … ] }. One day reset covers the whole set. A trailing drawdown follows the peak on every price change; stop_at_starting_balance: true stops the floor rising once it reaches the starting balance.
What a breach does
| Then |
|---|---|
| The breach is stored and you get |
| New orders are refused; exits stay allowed. A |
| Everything is closed and it ends with status |
A profit target has no on_breach: reaching it closes everything, locks it and ends it as completed_to_target. The result is the closed balance, which can land a little either side of the target.
Every breach acts as its rule says. The one exception is an emergency stop: if Chartnaut pauses rule actions for you, breaches are still stored and sent, with action_applied: false, and nothing is done.
When it's checked
Backtests check rules in the replay at every bar the user reveals, against the worst point inside the bar: its high and low against open positions. The breach is stamped with the bar's time (at_precision: "bar").
Demo accounts are checked against every price change while positions are open, and against fills and closes otherwise. The breach records the exact time of the price that crossed the limit. Acting on it normally takes a few seconds and is designed to finish within 10 minutes. If Chartnaut's price records have a gap, the breach says it happened between two times (at_precision: "between", with window_start and window_end).
Reading breaches
GET /sessions/{id}/breaches and GET /accounts/{id}/breaches list each breach with its rule, the limit and the value seen, the time and how exact it is, and what was done. Session breaches come oldest first, demo account breaches newest first.
unit says how to read limit and value, the same for both: money is a decimal in the account currency, units is lots, contracts, coins or shares for max_position_size, and count is a whole number for max_open_positions. Demo account breaches also carry the bid and ask at the crossing in prices.
