ZEME Bot Rules API
The rule book an execution bot reads before the Pakistan Stock Exchange opens: which shares to buy, the highest price at which to buy them, where to rest the sell, and what to do with every position already held. Every price and date is computed by ZEME the night before. Your bot only reads and executes.
What it is, and what it is not
- Signals only. ZEME never places orders, never connects to a trading account and never holds credentials for one. Your broker system or bot executes; ZEME publishes rules.
- One rule may buy: the IMMINENT +5% rule. A share is listed when ZEME's operator radar flags it as imminent and it closed up at least 3% that session. It is bought at the next open only below a precomputed price, sold at +5% or by the exit rules below.
- No intraday trading. The rule book says so explicitly (
intraday.allowed = false) and carries the evidence for that decision. - Computed once, served as-is. The endpoint does not calculate. If the night's computation
did not run, the API says
do_not_traderather than serving yesterday's orders as today's.
Authentication
Send the key in the X-Bot-Key header on every request. A key in the URL is refused
(400), because URLs end up in logs.
curl -H "X-Bot-Key: YOUR_KEY" "https://zeme.app/api/v1/bot.php?action=orders"
Who can read it: the scope bot_rules:read
- The account owner holds the scope with his own key. He never needs to share that key.
- A broker gets its own key, issued by the account owner, carrying the scope
bot_rules:readexplicitly. If your firm already holds a ZEME Intelligence API key (zk_...), the owner can add the scope to that key; otherwise he issues a newzb_...key, shown to him once and stored by ZEME only as a hash. - A key without the scope is refused (
403), including every ZEME Intelligence API key that was not granted it. A revoked key gets401. - Partner access is read-only (orders, rules, record, simulator), rate-limited per key, and every call is logged (time, key, endpoint, result) so the owner can see what was read.
- Responses to a partner key carry, in
partner_noticeand indisclaimer: "Signals only. Executing on third-party/customer accounts requires the broker's SECP-licensed process and client consent."
Base URL
https://zeme.app/api/v1/bot.php?action=orders | rules | record | sim
HTTPS, GET only, JSON (UTF-8). Every response carries Cache-Control: no-store.
All dates are PSX session dates (YYYY-MM-DD); all times are Pakistan time (PKT, UTC+5).
Every successful response starts with the same block:
| Field | Type | Meaning |
|---|---|---|
ok | boolean | The request was served. |
rule_sha | string | Fingerprint of the rule's parameters. A different value means a different rule. |
freshness.today_pkt | string | Today's date in PKT, as the server sees it. |
freshness.valid_for_session | string | The one session these orders are for. |
freshness.as_of_session | string | The last completed session the computation used. |
freshness.generated_at_pkt | string | When the rule book was computed. |
freshness.do_not_trade | boolean | true = open no new position today. |
freshness.do_not_trade_reasons | array | Plain-language reasons, empty when trading is allowed. |
disclaimer | string | Carried on every response. |
Orders
Today's new orders and the instruction for every position already held. Call it before the pre-open (09:15 Monday to Thursday, 09:00 Friday).
Example response (illustrative values, not a live pick)
{
"ok": true,
"rule_sha": "0123456789ab",
"do_not_trade": false,
"trading_halted": false,
"freshness": {"today_pkt": "2026-01-12", "valid_for_session": "2026-01-12", "do_not_trade": false, "...": "..."},
"orders": {
"valid_for_session": "2026-01-12",
"slots_free_today": 4,
"orders": [{
"sym": "ABCD", "side": "BUY", "action": "ORDER", "priority": 1,
"prev_close": 50.00, "max_entry": 51.50, "limit_price": 51.49,
"shares": 194, "capital_rs": 9991.00,
"target_formula": "ceil_to_0.01(fill_price x 1.05)", "target_if_filled_at_limit": 54.07,
"upper_circuit_price": 55.00,
"exit_session": "2026-01-16", "exit_at_close_pkt": "2026-01-16 16:30",
"skip_reasons": []
}],
"manage_open_positions": [{
"sym": "WXYZ", "entered": "2026-01-08", "fill_open": 20.00, "resting_sell": 21.00,
"stop_trigger_close": 19.00, "last_close": 18.90,
"next_session": "2026-01-12", "next_action": "SELL_AT_OPEN", "actionable_today": true,
"exit_session": "2026-01-14"
}]
}
}
Top level
| Field | Type | Meaning |
|---|---|---|
do_not_trade | boolean | The final word for new entries today. When true, every order row reads SKIP. |
do_not_trade_reasons | array | Why. |
trading_halted | boolean | The kill switch has tripped (see execution rules). |
orders.valid_for_session | string | The session the rows below are for. |
orders.do_not_trade_scope | string | States that do_not_trade stops NEW entries only. |
orders.slots_free_today | integer | New positions the rule allows today. |
orders.open_positions_per_record | integer | Positions the rule's own record holds. |
orders.tiebreak | string | How rows are ranked when they outnumber free slots. |
Each order row: orders.orders[]
| Field | Type | Meaning |
|---|---|---|
sym | string | PSX symbol. |
side | string | Always BUY. |
action | string | ORDER = act on it. SKIP = do not; see skip_reasons. |
skip_reasons | array | Empty on an ORDER row. |
prev_close | number | The signal session's close, Rs. |
max_entry | number | prev_close x 1.03. Buy only if the open is BELOW it. |
limit_price | number | The highest 0.01 tick strictly below max_entry: the buy limit to submit. |
upper_circuit_price | number | The session's upper circuit. Never buy a share locked there (the limit already rules it out). |
shares | integer | floor(per-stock cap / max_entry), whole shares. |
capital_rs | number | shares x max_entry: the most this order can cost. |
target_formula | string | The sell price from your actual fill. |
target_if_filled_at_limit | number | The sell price if the fill is at limit_price. |
exit_session | string | The 5th session counting the entry session (weekends and PSX holidays skipped). |
exit_at_close_pkt | string | That session's closing time. |
window | array | The five session dates the position may live. |
turnover_mn_20d_avg | number | 20-session average traded value, Rs million (liquidity floor input). |
cost_pct_round_trip_info | number or empty | Estimated round-trip broker cost, information only. |
priority (integer) appears on ORDER rows: act on them in that order while slots remain.
Each held position: orders.manage_open_positions[]
| Field | Type | Meaning |
|---|---|---|
sym | string | PSX symbol. |
entered | string | Entry session. |
fill_open | number | The rule's fill (that session's open). ZEME cannot see your real fill. |
resting_sell | number | The +5% sell on that fill. |
stop_trigger_close | number or empty | A CLOSE at or below this triggers a sell at the next open. |
last_close | number or empty | The latest close the instruction used. |
next_session | string | The session the instruction is for. |
next_action | string | HOLD, SELL_AT_OPEN or SELL_AT_CLOSE. |
actionable_today | boolean | true only when next_session is today. |
exit_session | string | The day-5 exit session. |
Rules
The rule text, its parameters, the risk limits your bot must enforce, the intraday decision, session hours and upcoming PSX holidays.
| Field | Type | Meaning |
|---|---|---|
rules.buy_rule.name | string | The one rule allowed to buy. |
rules.buy_rule.text | string | The rule in one paragraph. |
rules.buy_rule.params.max_gap_pct | number | The gap filter, percent over the previous close. |
rules.buy_rule.params.target_pct | number | The resting sell, percent over the fill. |
rules.buy_rule.params.horizon_sessions | integer | Sessions a position may live. |
rules.stop_rule.mode | string | close: judged on the closing price only. |
rules.stop_rule.pct | number | Percent under the fill that a close must reach. |
rules.intraday.allowed | boolean | Always false today. |
rules.intraday.reason | string | Why. |
rules.intraday.evidence | array | The measurements behind the decision. |
rules.risk.max_capital_per_stock_per_day_rs | number | Per-stock cap used for shares. |
rules.risk.max_open_positions | integer | Never hold more. |
rules.risk.kill_switch.consecutive_losses | integer | Losing trades in a row that halt new entries. |
rules.risk.kill_switch.cumulative_loss_rs | number | Realised loss, Rs, that halts new entries. |
rules.risk.include_costs | boolean | Whether the record deducts trading costs. |
rules.risk.liquidity_floor_mn_20d_avg | number | Minimum 20-session average traded value, Rs million. |
rules.session_hours.mon_thu | array | Trading windows, Monday to Thursday. |
rules.session_hours.fri | array | Friday's two windows. |
rules.holidays_next_60_days | array | PSX holidays ahead. |
rules.cost_table.rows | array | Round-trip cost by share price, information only. |
Record
Every pick the rule has listed, re-scored from prices: skipped at the open, filled at +5%,
stopped, out on day 5, still open or pending. The results live in the API, not on this page:
read ?action=record for the current figures.
| Field | Type | Meaning |
|---|---|---|
record.summary.basis | string | Gross or net of costs. |
record.summary.completed | integer | Trades that have exited. |
record.summary.filled | integer | Exited at the +5% sell. |
record.summary.filled_pct | number or empty | Share of completed trades that filled +5%. |
record.summary.avg_pct | number or empty | Average result per completed trade, percent. |
record.summary.worst_pct | number or empty | Worst completed trade, percent. |
record.summary.kill_switch_tripped | boolean | The record has hit a kill-switch limit. |
record.trades[].sym | string | Symbol. |
record.trades[].target_date | string | Entry session. |
record.trades[].status | string | FILLED, STOPPED, EXITED_DAY5, SKIPPED_GAP, OPEN, PENDING. |
record.backtest_reference | object | The study the rule came from, kept beside the forward record. |
Simulator
A paper bot that reads this API every night exactly as a real bot would and trades the published instructions on paper. Compare your bot's fills with it to separate execution problems from rule problems.
| Field | Type | Meaning |
|---|---|---|
sim.mode | string | live. |
sim.processed_through | string | Last session traded on paper. |
sim.stats | object | Trades, win and +5% hit share, average, median, worst, P&L in Rs, drawdown. |
sim.open_positions | array | Paper positions held now. |
sim.halted | boolean | The paper bot's own kill switch. |
sim.times_halted | integer | How often it tripped. |
sim.skips | object | Orders not taken, by reason (gap filter, no slot, already held). |
sim.disclaimer | string | Paper, gross, not a guarantee. |
Execution rules, in plain words
- Buy at the open, below a ceiling. Submit one limit buy per
ORDERrow atlimit_pricein the pre-open. It can only execute at an opening price belowmax_entry(the previous close plus 3%). Cancel anything unfilled once continuous trading starts. Never chase a share that opened higher. - Rest the sell at +5%. Right after the fill, place a limit sell for the whole position at your fill price x 1.05, rounded up to the paisa.
- Stop on the close, never intraday. If any session's official closing price is at or below your fill x 0.95, sell at the next session's open. Do not rest an intraday stop order. If the +5% sell fills in the same session, that comes first.
- Day 5 exit. If neither has happened, sell at the close of
exit_session(or in the post-close session at the closing price). - Slots and size. Never hold more than
rules.risk.max_open_positions; takeORDERrows inpriorityorder; buy exactlyshares. Never add to a position and never average down. - Kill switch. After the configured run of losing trades, or the configured realised loss,
trading_haltedbecomestrueand no new position may open. Exit instructions keep coming. Only the account owner re-arms it; it never resets by itself. - No intraday trading, no trading outside PSX session hours, nothing on PSX holidays.
Freshness and do_not_trade
The rule book is computed after each session's close. Orders are valid for exactly one session,
valid_for_session. The API returns do_not_trade: true, with reasons, when:
- today (PKT) is not
valid_for_session: the night's computation did not run, or you are early; - the nightly list for the next session was not produced;
- the kill switch has tripped (
trading_halted: true); - the configuration could not be read.
On do_not_trade, open nothing new. Held positions still follow
manage_open_positions, acting only on rows with actionable_today: true.
Time zone and PSX session hours
| Day | Pre-open | Trading | Post-close (at the closing price) |
|---|---|---|---|
| Monday to Thursday | 09:15 to 09:30 | 09:32 to 15:30 | 15:35 to 15:50 |
| Friday | 09:00 to 09:15 | 09:17 to 12:00, then 14:32 to 16:30 | 16:35 to 16:50 |
All times PKT (UTC+5). The authoritative copy is rules.session_hours; PSX holidays are in
rules.holidays_next_60_days.
Broker integration: who does what
The API tells an execution bot what to trade. Placing orders in client accounts is done by the broker's own bot, connected to the broker's order management system (OMS). ZEME never connects to an OMS, a trading app or a client account.
| Part | Owner |
|---|---|
| Which shares, maximum buy price, share count, +5% sell formula, exit date, HOLD / SELL instructions, kill switch, freshness flag | ZEME (this API) |
| Reading the API, placing, amending and cancelling orders in client accounts, recording fills | Broker's bot + OMS |
| SECP-licensed process for automated execution, written consent of every client, suitability, client reporting | Broker |
Position size per client (the API's shares is sized for Rs 10,000; scale it to each client's allocation) | Broker |
The broker bot's daily run
| When (PKT) | What the bot does |
|---|---|
| From 09:00 (Mon–Thu pre-open 09:15–09:30; Fri 09:00–09:15) | GET ?action=orders. If orders.do_not_trade is true or trading_halted is true: place no new buys. |
| Pre-open | For every row with action = "ORDER": a LIMIT BUY of shares at limit_price. Rows with action = "SKIP" are not traded. |
| Market open (09:32 Mon–Thu, 09:17 Fri) | Cancel any unfilled part of the buy. The rule buys the open; it never chases. |
| Right after a fill | Rest a LIMIT SELL for the whole position at ceil_to_0.01(fill_price × 1.05). Leave it live every session until it fills or the position exits. |
| Every morning, for every held position | Read manage_open_positions, field next_action (for next_session): HOLD = keep the +5% sell; SELL_AT_OPEN = cancel the +5% sell and sell at the open (the stop: a close ≤ fill × 0.95); SELL_AT_CLOSE = sell at that session's close (5th session). |
| Never | Average down, add to a position, trade intraday, rest an intraday stop order, act on orders whose valid_for_session is not today. |
The API computes its HOLD / SELL instructions from its own record, which assumes the rule's fills (the
opening price). If a client's real fill differs, the broker bot should apply the same rules to its own fill
price: stop when a session closes at or below fill × 0.95, exit at the close of
exit_session.
Code sample
Read the orders (replace the key with the one ZEME issued to you):
curl -s -H "X-Bot-Key: zb_YOUR_KEY" "https://zeme.app/api/v1/bot.php?action=orders"
A minimal Python skeleton. oms_* are placeholders for your own order system's calls:
import math, requests, datetime
API = "https://zeme.app/api/v1/bot.php"
KEY = "zb_YOUR_KEY"
def zeme(action):
r = requests.get(API, params={"action": action}, headers={"X-Bot-Key": KEY}, timeout=20)
r.raise_for_status()
return r.json()
def morning_run(today): # today = "YYYY-MM-DD" in PKT
book = zeme("orders")["orders"]
if book["valid_for_session"] != today:
return # stale or early: do nothing
# 1) positions already held: follow the instruction
for p in book["manage_open_positions"]:
if p["next_session"] != today:
continue
if p["next_action"] == "SELL_AT_OPEN":
oms_cancel_resting_sell(p["sym"])
oms_sell_at_open(p["sym"])
elif p["next_action"] == "SELL_AT_CLOSE":
oms_sell_at_close(p["sym"])
# 2) new buys
if book["do_not_trade"] or book["trading_halted"]:
return
for o in book["orders"]:
if o["action"] == "ORDER":
oms_limit_buy(o["sym"], o["shares"], o["limit_price"]) # pre-open
def on_fill(sym, fill_price, qty):
target = math.ceil(fill_price * 1.05 * 100) / 100
oms_limit_sell(sym, qty, target) # rests until filled or exit
Onboarding and go-live checklist
- Key. The account owner issues a read-only key for your firm (scope
bot_rules:read). It can be revoked at any time; every call is logged. - Read-only test (week 1). Call
orders,rules,recordandsimdaily after 09:00 and compare with the owner's 09:00 order email. Nothing is executed. - Paper run (weeks 2–4). Your bot executes against your OMS test/UAT environment only. Compare its fills and exits with
?action=sim, which paper-trades the same API. - Compliance. Confirm your SECP-licensed process for automated execution and collect written consent from every client before any live order.
- Pilot. One account, small fixed size, the kill switch respected (3 losing trades in a row or Rs 10,000 realised loss halts new entries).
- Go-live criteria. Your bot's fills and exits match the rules on every pilot trade; no order placed when
do_not_tradewas true; no trade outside session hours.
Risk you must disclose to clients: this rule has no intraday stop. Losing trades in its history averaged about −15% and the worst was about −34% (with the close-based stop, the worst in the measured sample was about −12%). A share locked at its lower circuit cannot be sold until buyers return. Past results do not guarantee future returns.
Errors
| Code | Meaning |
|---|---|
400 | Key sent in the URL, or an unknown action. |
401 | No X-Bot-Key header, or the key has been revoked. |
403 | The key does not carry the bot_rules:read scope. |
405 | Not a GET. |
429 | Rate limit reached, or too many failed keys from one address this hour. |
503 | The rule book is missing. The body says do_not_trade: true. |
Any response your bot cannot parse, and any status other than 200, means: open nothing new.
Rate limits
60 requests a minute per key; a daily allowance per key (5,000 for the owner, set per broker key when it is issued); plus a per-address limit at the network edge. Ten failed keys from one address lock it out for the rest of the hour. The rule book changes once a night, so one call before the pre-open and one after the close are enough.
Request a key
Bot keys are issued by the account owner, one per broker, with the bot_rules:read
scope. Broker technology teams can ask about integration and licensing through the contact page.
Disclaimer
ZEME publishes educational analytics, not investment advice. Past results do not guarantee future returns, and losses can exceed anything in the historical record. ZEME does not place orders, manage accounts or hold client money. Automated trading on behalf of third parties requires the appropriate licensing from the Securities and Exchange Commission of Pakistan (SECP) and each client's informed consent; that responsibility sits with the licensed broker or operator running the bot.