Skip to content

Limits and the Order Guard

The Order Guard (geometer-markets guard) is a local process listening strictly on 127.0.0.1:7878. It sits between your trading bot (or AI agent) and your broker, holding the real daily broker session while giving each bot a scoped local key.

Binding to 0.0.0.0 or any non-loopback address is rejected at startup. When you host the guard on a cloud VM, you reach it through an authenticated SSH or IAP loopback tunnel (geometer-markets connect).

Every order submission (POST) and modification (PUT) runs through the same pre-trade gate. Each refusal produces a stable code, a plain-English message, the triggering limit, and a decision_id recorded in your hash chain.

Check Refusal code What it enforces
Stop switch stop_switch_active Global, per-account, per-strategy, or per-symbol switch. Modes: no_new_risk, cancel_all, close_positions, halted.
Fails flat limits_unconfigured Any mandatory limit field missing, null, or malformed refuses all new risk at startup.
Order rate order_rate Stays under the exchange’s 10-orders-per-second ceiling per account and exchange segment (default 8/s with a short wait queue, then refusal).
Order size & notional order_notional_cap, position_size_cap, open_orders Caps per-order quantity, per-order value in INR, and maximum simultaneous open orders.
Price band & market protection price_band Rejects limit prices outside the configured percentage/rupee band around the last traded price, and rejects unprotected market orders by default.
Allowlists symbol_not_allowed, product_not_allowed, segment_not_allowed Restricts trading to explicit symbols (e.g. NSE:NIFTYBEES), products (intraday, delivery, carry), and segments (NSE_EQ, NSE_FO, BSE_EQ, BSE_FO).
Daily brakes daily_loss_limit, daily_trade_count, losing_streak_cooloff Halts new risk for the day after reaching your daily loss cap or trade cap, or pauses for a cool-off window after consecutive losing trades. Risk-reducing orders remain permitted.
Options worst-case loss option_worst_case Refuses unbounded structures (naked short options) unless explicitly permitted, and reserves each order’s worst-case loss against max_option_worst_case_inr.
Margin check insufficient_margin Queries the broker’s margin estimate before sending the order.
Unknown outcome outcome_unknown If the broker stops answering mid-order and its fate is uncertain, blocks all new opening orders until reconciled by guard order tag (G...).
Duplicate protection idempotency_conflict, order_in_flight Same client_order_id with identical parameters replays the stored result without sending a second order; mismatched parameters fail with 409 Conflict.
Charges share charges_share Computes brokerage, STT, exchange fees, SEBI fee, stamp duty, GST, and break-even from the dated rate card; optionally refuses orders whose charges exceed max_charges_share_pct.

All monetary values, quantities, and percentages in limits.json are exact base-10 decimal strings. Unknown fields, JSON null values, and floating-point numbers are rejected on load so incomplete edits can never silently open risk.

{
"schema": 1,
"version": "my-limits-1",
"account_id": "default",
"max_order_qty": "100",
"max_order_value_inr": "50000",
"max_open_orders": 10,
"max_orders_per_second": 8,
"price_band_pct": "0.5",
"price_band_min_inr": "2",
"reject_unprotected_market": true,
"max_daily_loss_inr": "5000",
"max_daily_trades": 20,
"losing_streak_limit": 5,
"losing_streak_cooloff_minutes": 30,
"allowed_symbols": ["NSE:NIFTYBEES"],
"allowed_products": ["delivery", "intraday"],
"allowed_segments": ["NSE_EQ", "NSE_FO"],
"allow_naked_short_options": false,
"max_option_worst_case_inr": "10000",
"max_charges_share_pct": "2"
}

Optional fields include post_loss_pause_minutes, post_loss_min_inr, and max_charges_share_pct. Every time you update limits.json through the human control plane, the guard computes a new SHA-256 limits_hash, increments limits_version, records a limits_change entry in your signed chain, and stamps that version onto every subsequent decision.

If you already run a Python bot with kiteconnect, change only the root URL and replace the broker key with your local guard key:

from kiteconnect import KiteConnect
kite = KiteConnect(
api_key="gm_live_a1b2c3d4_your_local_bot_key",
root="http://127.0.0.1:7878/kite",
)
order_id = kite.place_order(
variety=kite.VARIETY_REGULAR,
exchange=kite.EXCHANGE_NSE,
tradingsymbol="NIFTYBEES",
transaction_type=kite.TRANSACTION_TYPE_BUY,
quantity=10,
product=kite.PRODUCT_MIS,
order_type=kite.ORDER_TYPE_LIMIT,
price=250.00,
)

Order, portfolio, and margin routes speak Kite Connect v3 JSON shapes and pass through every Order Guard check. Read-only routes (quotes, instruments, historical candles) forward directly and do not require static IP registration.

For new bots in any language, AI agents, or multi-broker portability, use the uniform /v1/ JSON API. Send Authorization: Bearer gm_live_<key_id>_<secret> (or gm_paper_...) and Content-Type: application/json (max body size 64 KiB, exact base-10 decimal strings for prices and quantities).

Method & Path Permission Purpose
POST /v1/orders orders:write Place an order (client_order_id, account_id, strategy_id, instrument, side, order_type, product, quantity, optional price, trigger_price, validity, reduce_only, reason).
PUT /v1/orders/{id} orders:write Modify an open order owned by this key’s strategy; runs the full pre-trade risk gate against the modified exposure.
DELETE /v1/orders/{id} orders:write Cancel an open order owned by this key’s strategy; allowed even under no_new_risk and cancel_all.
GET /v1/orders and GET /v1/orders/{id} orders:read Inspect orders for an allowed account (filterable by strategy_id, status, outside_only).
GET /v1/positions, /v1/holdings, /v1/funds portfolio:read Read reconciled positions, T+1 holdings, and broker margin plus reserved worst-case risk budget.
POST /v1/charges/preview charges:read Dry-run itemized India charges, break-even price, and risk evaluation without sending to the broker.
GET /v1/limits limits:read Read active limits.json, limits_version, limits_hash, and daily counters.
GET /v1/stop and POST /v1/stop limits:read, stop:engage Inspect stop switches or engage strategy-scoped no_new_risk / cancel_all (never re-arm).
GET /v1/record/head record:read Read current chain sequence number, head_hash, last checkpoint sequence, and signer_pub_key.

Every refusal responds with one consistent envelope:

{
"refused": {
"code": "price_band",
"message": "Limit price 290.00 INR is outside the 0.5% / 2 INR collar around last price 250.00 INR.",
"limit": "price_band",
"decision_id": "dec_019b8c7d6e5f4a3b2c1d0e9f8a7b6c5d"
}
}

Privilege separation is enforced at the transport layer:

  • Bot keys (gm_live_<key_id>_<secret> / gm_paper_<key_id>_<secret>):
    • Strictly mode-isolated (gm_paper_ cannot touch live accounts; gm_live_ cannot touch paper accounts).
    • Scoped to explicit allowed_accounts, allowed_strategies, a named limits profile, and explicit permissions (orders:write, orders:read, portfolio:read, charges:read, limits:read, stop:engage, record:read).
    • Stored in SQLite only as salted SHA-256 hashes and verified in constant time.
    • Can never re-arm or downgrade a stop switch, engage close_positions or halted, edit limits.json, create or revoke keys, modify another strategy’s or manual order, change static IP settings, or read broker credentials.
  • Human control plane (guard-admin.sock):
    • Local CLI commands (geometer-markets kill, key, login, address) connect over a 0600 Unix domain socket inside a 0700 runtime directory, verified via OS peer credentials (SO_PEERCRED on Linux, LOCAL_PEERCRED on macOS).
    • The embedded local Guard Console at http://127.0.0.1:7878/admin (served from the same binary with zero external network requests, behind local human-session authentication) surfaces live risk budget meters, stop switch controls, the first-live safety checklist, and module status. See Opt-in modules and Guard Console.

Stop switches operate at four scopes — global, account, strategy, and symbol — and four escalation modes:

Mode New opening orders Risk-reducing orders Open working orders
no_new_risk Refused Allowed Left open
cancel_all Refused Allowed Cancelled immediately
close_positions Refused Submitted to flatten Cancelled, then positions closed
halted Refused Refused All traffic halted

Engage or re-arm from your terminal:

Terminal window
# Halt new risk across one account
geometer-markets kill --scope account --target default --mode no_new_risk --reason "volatility check"
# Cancel all working orders for a single strategy
geometer-markets kill --scope strategy --target crossover --mode cancel_all --reason "bug detected"
# Re-arm back to normal (human control plane only)
geometer-markets kill --scope account --target default --mode normal --reason "verified"

The Order Guard cannot block orders placed directly through your broker’s web or mobile app or from another program holding your raw broker API key. While markets are open, it polls the broker’s order book every 5 seconds, records unrecognized orders as outside_order entries, counts them against your active daily limits, can trip your stop switch when configured, and lists them in your evening report. See What Geometer Markets does not do.