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_trade rather 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:read explicitly. If your firm already holds a ZEME Intelligence API key (zk_...), the owner can add the scope to that key; otherwise he issues a new zb_... 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 gets 401.
  • 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_notice and in disclaimer: "Signals only. Executing on third-party/customer accounts requires the broker's SECP-licensed process and client consent."
To get a key, ask the account owner you work with. ZEME does not issue bot keys directly; questions about integration and licensing go through the contact page.

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:

FieldTypeMeaning
okbooleanThe request was served.
rule_shastringFingerprint of the rule's parameters. A different value means a different rule.
freshness.today_pktstringToday's date in PKT, as the server sees it.
freshness.valid_for_sessionstringThe one session these orders are for.
freshness.as_of_sessionstringThe last completed session the computation used.
freshness.generated_at_pktstringWhen the rule book was computed.
freshness.do_not_tradebooleantrue = open no new position today.
freshness.do_not_trade_reasonsarrayPlain-language reasons, empty when trading is allowed.
disclaimerstringCarried on every response.

Orders

GET/api/v1/bot.php?action=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

FieldTypeMeaning
do_not_tradebooleanThe final word for new entries today. When true, every order row reads SKIP.
do_not_trade_reasonsarrayWhy.
trading_haltedbooleanThe kill switch has tripped (see execution rules).
orders.valid_for_sessionstringThe session the rows below are for.
orders.do_not_trade_scopestringStates that do_not_trade stops NEW entries only.
orders.slots_free_todayintegerNew positions the rule allows today.
orders.open_positions_per_recordintegerPositions the rule's own record holds.
orders.tiebreakstringHow rows are ranked when they outnumber free slots.

Each order row: orders.orders[]

FieldTypeMeaning
symstringPSX symbol.
sidestringAlways BUY.
actionstringORDER = act on it. SKIP = do not; see skip_reasons.
skip_reasonsarrayEmpty on an ORDER row.
prev_closenumberThe signal session's close, Rs.
max_entrynumberprev_close x 1.03. Buy only if the open is BELOW it.
limit_pricenumberThe highest 0.01 tick strictly below max_entry: the buy limit to submit.
upper_circuit_pricenumberThe session's upper circuit. Never buy a share locked there (the limit already rules it out).
sharesintegerfloor(per-stock cap / max_entry), whole shares.
capital_rsnumbershares x max_entry: the most this order can cost.
target_formulastringThe sell price from your actual fill.
target_if_filled_at_limitnumberThe sell price if the fill is at limit_price.
exit_sessionstringThe 5th session counting the entry session (weekends and PSX holidays skipped).
exit_at_close_pktstringThat session's closing time.
windowarrayThe five session dates the position may live.
turnover_mn_20d_avgnumber20-session average traded value, Rs million (liquidity floor input).
cost_pct_round_trip_infonumber or emptyEstimated 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[]

FieldTypeMeaning
symstringPSX symbol.
enteredstringEntry session.
fill_opennumberThe rule's fill (that session's open). ZEME cannot see your real fill.
resting_sellnumberThe +5% sell on that fill.
stop_trigger_closenumber or emptyA CLOSE at or below this triggers a sell at the next open.
last_closenumber or emptyThe latest close the instruction used.
next_sessionstringThe session the instruction is for.
next_actionstringHOLD, SELL_AT_OPEN or SELL_AT_CLOSE.
actionable_todaybooleantrue only when next_session is today.
exit_sessionstringThe day-5 exit session.

Rules

GET/api/v1/bot.php?action=rules

The rule text, its parameters, the risk limits your bot must enforce, the intraday decision, session hours and upcoming PSX holidays.

FieldTypeMeaning
rules.buy_rule.namestringThe one rule allowed to buy.
rules.buy_rule.textstringThe rule in one paragraph.
rules.buy_rule.params.max_gap_pctnumberThe gap filter, percent over the previous close.
rules.buy_rule.params.target_pctnumberThe resting sell, percent over the fill.
rules.buy_rule.params.horizon_sessionsintegerSessions a position may live.
rules.stop_rule.modestringclose: judged on the closing price only.
rules.stop_rule.pctnumberPercent under the fill that a close must reach.
rules.intraday.allowedbooleanAlways false today.
rules.intraday.reasonstringWhy.
rules.intraday.evidencearrayThe measurements behind the decision.
rules.risk.max_capital_per_stock_per_day_rsnumberPer-stock cap used for shares.
rules.risk.max_open_positionsintegerNever hold more.
rules.risk.kill_switch.consecutive_lossesintegerLosing trades in a row that halt new entries.
rules.risk.kill_switch.cumulative_loss_rsnumberRealised loss, Rs, that halts new entries.
rules.risk.include_costsbooleanWhether the record deducts trading costs.
rules.risk.liquidity_floor_mn_20d_avgnumberMinimum 20-session average traded value, Rs million.
rules.session_hours.mon_thuarrayTrading windows, Monday to Thursday.
rules.session_hours.friarrayFriday's two windows.
rules.holidays_next_60_daysarrayPSX holidays ahead.
rules.cost_table.rowsarrayRound-trip cost by share price, information only.

Record

GET/api/v1/bot.php?action=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.

FieldTypeMeaning
record.summary.basisstringGross or net of costs.
record.summary.completedintegerTrades that have exited.
record.summary.filledintegerExited at the +5% sell.
record.summary.filled_pctnumber or emptyShare of completed trades that filled +5%.
record.summary.avg_pctnumber or emptyAverage result per completed trade, percent.
record.summary.worst_pctnumber or emptyWorst completed trade, percent.
record.summary.kill_switch_trippedbooleanThe record has hit a kill-switch limit.
record.trades[].symstringSymbol.
record.trades[].target_datestringEntry session.
record.trades[].statusstringFILLED, STOPPED, EXITED_DAY5, SKIPPED_GAP, OPEN, PENDING.
record.backtest_referenceobjectThe study the rule came from, kept beside the forward record.

Simulator

GET/api/v1/bot.php?action=sim

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.

FieldTypeMeaning
sim.modestringlive.
sim.processed_throughstringLast session traded on paper.
sim.statsobjectTrades, win and +5% hit share, average, median, worst, P&L in Rs, drawdown.
sim.open_positionsarrayPaper positions held now.
sim.haltedbooleanThe paper bot's own kill switch.
sim.times_haltedintegerHow often it tripped.
sim.skipsobjectOrders not taken, by reason (gap filter, no slot, already held).
sim.disclaimerstringPaper, gross, not a guarantee.

Execution rules, in plain words

  1. Buy at the open, below a ceiling. Submit one limit buy per ORDER row at limit_price in the pre-open. It can only execute at an opening price below max_entry (the previous close plus 3%). Cancel anything unfilled once continuous trading starts. Never chase a share that opened higher.
  2. 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.
  3. 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.
  4. Day 5 exit. If neither has happened, sell at the close of exit_session (or in the post-close session at the closing price).
  5. Slots and size. Never hold more than rules.risk.max_open_positions; take ORDER rows in priority order; buy exactly shares. Never add to a position and never average down.
  6. Kill switch. After the configured run of losing trades, or the configured realised loss, trading_halted becomes true and no new position may open. Exit instructions keep coming. Only the account owner re-arms it; it never resets by itself.
  7. No intraday trading, no trading outside PSX session hours, nothing on PSX holidays.
A share locked at its lower circuit cannot be sold until buyers return. The close-based stop limits a slow slide; it cannot protect against a lock-down. Size every position as if it could lose far more than 5%.

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

DayPre-openTradingPost-close (at the closing price)
Monday to Thursday09:15 to 09:3009:32 to 15:3015:35 to 15:50
Friday09:00 to 09:1509:17 to 12:00, then 14:32 to 16:3016: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.

PartOwner
Which shares, maximum buy price, share count, +5% sell formula, exit date, HOLD / SELL instructions, kill switch, freshness flagZEME (this API)
Reading the API, placing, amending and cancelling orders in client accounts, recording fillsBroker's bot + OMS
SECP-licensed process for automated execution, written consent of every client, suitability, client reportingBroker
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-openFor 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 fillRest 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 positionRead 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).
NeverAverage 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

  1. 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.
  2. Read-only test (week 1). Call orders, rules, record and sim daily after 09:00 and compare with the owner's 09:00 order email. Nothing is executed.
  3. 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.
  4. Compliance. Confirm your SECP-licensed process for automated execution and collect written consent from every client before any live order.
  5. 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).
  6. Go-live criteria. Your bot's fills and exits match the rules on every pilot trade; no order placed when do_not_trade was 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

CodeMeaning
400Key sent in the URL, or an unknown action.
401No X-Bot-Key header, or the key has been revoked.
403The key does not carry the bot_rules:read scope.
405Not a GET.
429Rate limit reached, or too many failed keys from one address this hour.
503The 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.

Contact ZEME

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.