Tagging orders by strategy
Once you run more than one strategy on the same account, you need a way to answer "which strategy placed this order/holds this position?" without maintaining a fragile side-lookup. tag (introduced in chapter 43, used for idempotency in chapter 58) is the mechanism.
Tagging convention
def make_tag(strategy_name: str, run_id: str) -> str:
# Kite tags: alphanumeric + limited special chars, short max length — check current docs
raw = f"{strategy_name}-{run_id}"
return raw[:20]
tag = make_tag("orb-nifty", "20260913-001")
kite.place_order(..., tag=tag)
Given the short max length, prefer a scheme that's *decodable* rather than fully descriptive: a short strategy code + a run/date suffix, with the full mapping (code -> strategy name, run_id -> parameters used) kept in your own local database, not encoded entirely in the tag string itself.
# strategy_registry.py
STRATEGY_CODES = {
"orb-nifty": "Opening Range Breakout — NIFTY futures",
"mr-bnf": "Mean reversion — BANKNIFTY options",
}
Filtering the order/trade book by strategy
def orders_for_strategy(kite, strategy_code: str) -> list[dict]:
return [o for o in kite.orders() if o.get("tag", "").startswith(strategy_code)]
def positions_for_strategy(kite, strategy_code: str, order_log: dict) -> list[dict]:
"""order_log: your own local record of order_id -> strategy_code, since
positions() doesn't carry tags — only orders do."""
my_order_ids = {oid for oid, code in order_log.items() if code == strategy_code}
# cross-reference against trades() to attribute fills to positions
...
Note the caveat in that last function: positions() and holdings() do not carry your order tags — tags only appear on orders. To attribute an open position back to the strategy that created it, you must maintain your own local mapping from filled orders to positions, updated as orders complete (chapter 66 covers this reconciliation).
Why this matters early, not just at scale
Even running one strategy today, tagging from day one means chapter 89's trade journal and chapter 97's tax record-keeping have clean strategy attribution built in from the start, instead of needing a messy retrofit once you add a second strategy.