Prayog functional overview
What a person can do on Prayog, what the exchange does on its own, and when each thing happens. The model is an NSE-style cash equity market, based on public information only. Prayog is a simulation and is not affiliated with any exchange.
How to read this
This page describes the target product: what a production exchange in this style offers. Each feature is tagged with when Prayog builds it:
- MVP in the current build plan (sessions S1–S22).
- PHASE 2 next after the MVP. Needs your approval before it enters the plan.
- LATER production features we describe so the design leaves room for them, but do not build yet.
Some things people think of as exchange features are really broker features: the broker's system holds the order and sends it to the exchange later (GTT, after-market orders, bracket orders). Those are marked as such. Prayog plays both roles, but the line matters for the design, because broker features live outside the matching engine.
The companion page, technical.html, explains how each feature is built and how data flows through the system.
1. The big picture: exchanges and trading firms
Videos about HFT describe the whole industry at once: exchanges, trading firms, feeds, FPGAs, monitoring, reporting. These belong to two different organisations on either side of a network cable:
- The exchange (NSE, BSE, Nasdaq) runs the market. It keeps the one official order book per stock, matches orders fairly, publishes prices to everyone, and makes sure trades settle. It does not care whether you win or lose.
- A trading firm (an HFT firm, a hedge fund, your paper-trading algo) is a customer of the exchange. It reads the exchange's price feed, decides what to trade, and sends orders. Its whole job is to make money, and in HFT, to do it faster than other firms.
Both sides have an "order book", which is a common source of confusion. The exchange's book is the real one. A trading firm rebuilds its own copy from the exchange's feed (a "book builder") so its strategy can read it without asking the exchange.
What each component does, and where Prayog stands
| Component | What it does | Prayog |
|---|---|---|
| Trading firm side | ||
| Colocation and network | Servers rented inside the exchange's data centre, cables cut to equal length, microwave links between cities. Every metre is about 5 ns | Not built. Everything runs on one machine |
| Time sync | GPS and PTP clocks so every server agrees on time to within nanoseconds. Needed to measure latency and for regulators' timestamps | Not built. Prayog uses a simulated clock |
| FPGAs and fast network cards | An FPGA is a chip you program as a circuit rather than as software. HFT firms use them to decode the price feed and fire an order in well under a microsecond, faster than any CPU program. Fast network cards skip the operating system ("kernel bypass") to save microseconds | Not built. It's hardware. The software ideas behind it (no allocation, busy-spinning, one thread per core) show up in our engine |
| Feed handler (market data ingestion) | Reads the exchange's raw feed, decodes it, spots missing messages by sequence number, and recovers them | Simplified: the SDK's WebSocket client with gap detection (S12) |
| Book builder | Rebuilds each stock's order book from the feed so the strategy can read it locally in nanoseconds | Simplified: the SDK keeps a local book from snapshot + updates (S12) |
| Strategy / signal engine | Decides what to buy and sell: market making, arbitrage, momentum. This is the firm's secret ("alpha") | Yours: your bot. Our agents (S13) are simple strategies that create the market |
| Pre-trade risk checks | Blocks orders that break limits (position, order size, price far off the market, loss limit) before they leave the firm. Required by regulators after real disasters (Knight Capital lost $440m in 45 minutes in 2012) | Exchange-side checks are built (max quantity, bands, rate limits, kill switch). Firm-side checks in the SDK could be a Phase 2 item |
| Order management (OMS / EMS) | Tracks every order's state, handles partial fills and rejects, and decides which exchange to send to ("smart order routing") | Simplified: the SDK tracks your orders. No routing, because there is only one exchange |
| Order gateway | Speaks the exchange's order protocol (FIX or binary) and manages the session | Simplified: REST and WebSocket JSON via the SDK |
| Tick data store | Records every price update for research. Often terabytes a day, in specialised databases | Not built. Prayog's journal holds every event, so it could be exported later |
| Research and backtesting | Replays history through a strategy to estimate how it would have performed, before risking money | Not built. A natural Later item: replay a recorded Prayog day into your bot |
| Monitoring and alerting | Dashboards for latency, fills, errors and P&L; alerts when anything drifts | Built for the exchange (S21). Your bot's own monitoring is up to you |
| P&L, risk and reporting | Real-time P&L and exposure, end-of-day reconciliation with the broker, regulatory reports | Built on the broker side: positions, P&L, charges, blotter, leaderboard (S16–S19) |
| Exchange side | ||
| Order gateway | Accepts connections, authenticates, rate-limits, checks message shape | Built (S10) |
| Sequencer | Puts all orders from all members into one official arrival order, which is what makes "first come, first served" fair | Built (S7) |
| Matching engine | Keeps the official order books and applies the rules: priority, bands, sessions, self-trade prevention | Built (S4–S6). S4 is done |
| Market data publisher | Sends book changes and trades to everyone at the same moment | Built (S11) |
| Journal and replay | Records every input so the market can be rebuilt exactly after a crash | Built (S8) |
| Sessions and ops control | Opens, halts and closes the market; kill switches | Built (S6, S19) |
| Post-trade, monitoring, reports | For an exchange: trade reports and statistics. For a broker: positions, P&L, charges, contract notes | Built (S15–S21), simplified |
| Market surveillance | Looks for manipulation: spoofing, wash trades, pump-and-dump | Not built (Later) |
| Clearing and settlement | A clearing house guarantees every trade and moves cash and shares (T+1 in India) | Not built (Later) |
A possible later track: if you want to go deeper on the trading-firm side, the natural next steps are a backtester that replays a recorded Prayog day into a bot, firm-side risk checks in the SDK, and latency measurement from your bot to the exchange and back. It's listed in open decisions.
2. Prayog at a glance
The same picture at the level of what people do. Everything inside the exchange box happens in the moment an order arrives. The "after the trade" boxes update a moment later and can never slow down trading.
The results of "after the trade" (P&L, blotter, leaderboard) show up in the trader's terminal and through the API, read from those services rather than from the exchange.
3. People and roles
| Role | Who | How they connect | What they can do |
|---|---|---|---|
| Trader MVP | A person trading by hand | Web terminal at app.prayog.localhost, signed in through Keycloak | Place, modify and cancel orders; watch the book and charts; see positions, P&L and the leaderboard |
| Bot developer MVP | A person running their own algorithm | Python SDK or plain REST + WebSocket, with a client ID and secret as the API key | Everything a trader can do, but from code. Higher message rates, so rate limits matter |
| Simulated trader MVP | Prayog's own agents that create the market | The same public API as bots: no back door | Quote prices, trade on news-like shocks, add noise. They make the market feel alive |
| Ops MVP | The person running the exchange | Ops page in the web app (role ops) | Open, halt and close the market; kill switch per account; change the clock speed; watch health |
| Viewer PHASE 2 | Anyone not signed in | Public market data and leaderboard | Watch only |
| Risk / compliance LATER | Surveillance staff | Reports and alerts | Spot wash trades, spoofing and unusual activity; review audit trails |
4. Instruments
An instrument is something you can trade (here, a share of a made-up company). Every instrument has static settings that the exchange checks on every order.
| Setting | Meaning | Example | Status |
|---|---|---|---|
| Symbol | Short name, upper case | ABC | MVP |
| Tick size | Smallest price step. Every price must be a multiple | 5 paise: ₹100.05 is valid, ₹100.03 is rejected | MVP |
| Lot size | Smallest quantity step. 1 for Indian cash equities | 1 share | MVP (fixed at 1) |
| Reference price | The price bands are measured from (normally yesterday's close) | ₹100.00 | MVP (static) |
| Price band | How far from the reference price an order may be priced today. NSE uses 2%, 5%, 10% or 20% bands depending on the stock | 10% band on ₹100 → valid ₹90.00 to ₹110.00 | MVP |
| Max order quantity | Largest single order. Protects against "fat finger" mistakes | 100,000 shares | MVP |
| Status | Active, suspended, or delisted | A suspended stock accepts no orders | PHASE 2 |
| Daily reference rollover | Next day's reference = today's closing price | Close ₹104.20 → tomorrow's band ₹93.80–₹114.60 | LATER |
5. The trading day
An exchange is not always open for continuous trading. The day has sessions, and each session allows different actions. NSE's cash market day, from public information (check current NSE circulars before relying on exact minutes):
| Session | What happens | Orders allowed | Status |
|---|---|---|---|
| Closed | Nothing trades. Open orders from the day are gone (DAY validity) | None. Broker-side "after-market orders" queue outside the exchange | MVP |
| Pre-open: order entry (NSE 09:00–09:08, ends at a random moment in the last minute) | Orders are collected but nothing matches. The ending is random so nobody can game the last second | Place, modify, cancel limit and market orders | PHASE 2 |
| Pre-open: matching (≈09:08–09:12) | A call auction picks one opening price, the one where the most shares can trade, and all crossing orders trade at it | None | PHASE 2 |
| Buffer (≈09:12–09:15) | A quiet gap before continuous trading starts | None | PHASE 2 |
| Open / continuous (09:15–15:30) | Every incoming order is matched immediately against the book by price-time priority | All order types and actions | MVP |
| Halted | Trading paused by ops or by a circuit breaker. The book is kept | Cancels only (common policy). New orders and modifies are rejected | MVP (ops halt) |
| Closing price | NSE sets the official close from trades near the end of the day; in 2026 it began moving some stocks to a closing auction | Depends on method | LATER |
| Post-close (≈15:50–16:00) | Trading only at the closing price | Limit orders at the close price | LATER |
6. Order types and validity
An order has a type (how its price works) and a validity (how long it lives). Prices are always whole paise.
| Type | How it works | Example | Where it lives | Status |
|---|---|---|---|---|
| Limit | Buy at this price or lower / sell at this price or higher. Whatever does not fill immediately rests on the book | BUY 10 ABC @ ₹100.00 | Exchange | MVP |
| Market | Take whatever the book offers, best price first, until filled. Never rests. Prayog stops at the price band; any remainder is cancelled | SELL 10 ABC at market | Exchange | MVP |
| Stop-loss limit (SL) | Sleeps until the last traded price touches the trigger, then becomes a limit order | SELL 10, trigger ₹95.00, limit ₹94.50 | Exchange (NSE holds stop orders) | PHASE 2 |
| Stop-loss market (SL-M) | Like SL, but becomes a market order when triggered | SELL 10, trigger ₹95.00 | Exchange or broker | LATER |
| Disclosed quantity (iceberg) | Only part of the order shows on the book; the rest refills as it trades. Lets large orders hide their size | BUY 10,000, show 1,000 | Exchange | LATER |
| GTT / OCO, bracket and cover orders | Conditional orders held by the broker, sent to the exchange when the condition is met | "If ABC hits ₹120, sell 10" | Broker | LATER |
| Validity | Meaning | Status |
|---|---|---|
| DAY | Lives until the market closes, then expires. The default on Indian exchanges | MVP |
| IOC (immediate or cancel) | Fill what you can right now; cancel the rest at once. Never rests. Bots use this a lot | PHASE 2 |
| FOK (fill or kill) | All or nothing, right now. Not offered on NSE cash; common elsewhere | LATER |
| GTC (good till cancelled) | Survives across days. On Indian markets this is a broker feature (GTT), not an exchange one | LATER (broker) |
7. Order lifecycle
Every order moves through a small set of states. Each arrow is an event the exchange publishes, so the order's state is always rebuildable from its events.
Open and Partially filled are the live states: the order can still trade, be modified or be cancelled. The other four are final. "Expired" is published as OrderCancelled with a reason; we will add an EXPIRED reason when sessions arrive in S6.
The quantities always add up: ordered = filled + open + cancelled. Prayog's property tests check this for thousands of random order flows.
8. Actions
Every action is described the same way: who does it, when it is allowed, what happens step by step, and what comes out.
A. Access
Sign in MVP
Create bot credentials (API key) MVP
Rate limiting MVP
B. Orders
Place a limit order MVP
Place a market order MVP (S5)
Place an IOC order PHASE 2
Place a stop-loss order PHASE 2
Modify an order MVP (S5)
Cancel an order MVP (S5)
Cancel all (mass cancel) PHASE 2
C. Exchange rules (things the exchange does by itself)
Price-time priority matching MVP
Price band rejection MVP (S6)
Self-trade prevention MVP (S6)
Expiry at end of day MVP (S6)
Opening call auction PHASE 2
Circuit breakers LATER
D. Market data
Order book (depth) MVP (S11)
Trade prints and ticker MVP (S11)
Your own order updates MVP (S11)
E. After the trade
Positions MVP (S16)
P&L MVP (S16)
Charges MVP (simple) · LATER (Indian detail)
Trade blotter and reports MVP (S19)
Leaderboard MVP (S17)
Settlement LATER
Buying power and margin checks PHASE 2
F. Operations
Open, halt, resume, close the market MVP
Kill switch MVP
Change clock speed MVP
Replay a session MVP (S8)
Add or suspend an instrument PHASE 2
G. Simulated market
Simulated traders MVP (S13)
9. Worked example: one trader's morning
Instrument ABC: tick 5 paise, reference ₹100.00, band 10% (₹90.00–₹110.00). Charges for the example: ₹10 per trade.
| Sim time | Action | Book before (best) | Result | Position · avg price |
|---|---|---|---|---|
| 09:15:00 | Ops opens the market | empty | SessionStateChanged(OPEN) | — |
| 09:15:02 | Market maker quotes 100 @ ₹99.95 / 100 @ ₹100.05 | — | Two orders rest | — |
| 09:20:10 | You BUY 10 @ ₹100.10 (limit) | ask ₹100.05 | Trade 10 @ ₹100.05 (resting price: 5 paise saved) | +10 · ₹100.05 |
| 09:31:00 | You BUY 10 @ ₹101.95 | ask ₹102.05 | No cross; your bid rests and becomes the best bid | +10 |
| 09:33:40 | Momentum bot SELLS 10 at market | bid ₹101.95 (yours) | Trade 10 @ ₹101.95; you are filled | +20 · ₹101.00 |
| 10:05:00 | You SELL 15 @ ₹103.00 | bid ₹103.10 | Trade 15 @ ₹103.10 | +5 · ₹101.00 |
| 10:30:00 | Last trade on ABC prints at ₹102.50 | — | Unrealised P&L is revalued | +5 |
Average price after both buys: (10 × 100.05 + 10 × 101.95) ÷ 20 = ₹101.00.
Realised on the sale: (103.10 − 101.00) × 15 = ₹31.50.
Unrealised on the 5 left: (102.50 − 101.00) × 5 = ₹7.50.
Charges: 3 trades × ₹10 = ₹30.00. Net P&L: 31.50 + 7.50 − 30.00 = ₹9.00.
Internally every one of those numbers is whole paise (₹101.00 = 10,100 paise). An average price that isn't a whole number of paise is kept as a total cost (paise × shares) instead, so no rounding happens until display.
10. Functional decisions still open
These change behaviour users can see. Each has a recommended default; we decide when the session that needs it starts.
| Decision | Options | Recommended | Needed by |
|---|---|---|---|
| What can you do while HALTED? | Nothing / cancels only / cancels and modifies | Cancels only: people can reduce risk, but nothing new trades | S6 |
| Realised P&L method | Average cost / FIFO lots | Average cost: simpler, and what most Indian broker P&L screens show for intraday | S16 |
| Short selling | Allowed freely / allowed intraday only (square off by close) / not allowed | Allowed freely in the MVP; intraday-only with auto square-off in Phase 2 (that's how Indian cash shorts work) | S16 |
| Starting cash | Unlimited / fixed (e.g. ₹10 lakh) with buying-power checks | Unlimited for MVP; fixed in Phase 2. It makes the leaderboard fairer | Phase 2 |
| Leaderboard metric | Net P&L / return % / risk-adjusted (Sharpe-like) | Net P&L first; return % once cash is fixed | S17 |
| Trading-firm track | None / backtester replaying a Prayog day / SDK-side risk checks / bot latency measurement | Decide after the MVP; the backtester gives the most learning for algo work | After MVP |
| Which Phase 2 features first | IOC, stop-loss, pre-open auction, buying power, mass cancel | IOC and mass cancel (small, and bots need them), then buying power, then the auction | After MVP |
11. Glossary
| Term | Meaning |
|---|---|
| Bid / ask | A buy order's price / a sell order's price. Best bid = highest bid; best ask = lowest ask |
| Spread | Best ask − best bid. Narrow spread = cheap to trade |
| Resting / passive / maker | An order waiting on the book; it "made" liquidity |
| Aggressive / incoming / taker | An order that trades on arrival; it "took" liquidity |
| Crossed book | Best bid ≥ best ask. Must never last in continuous trading: those orders should have traded |
| Depth / level 2 | Total quantity at each price, per side |
| Tick size | Smallest allowed price step |
| Price band / circuit filter | Today's allowed price range for a stock |
| Leaves quantity | The part of an order still open |
| Call auction | Collect orders, then trade everything at one price that maximises volume |
| Wash trade | Trading with yourself; blocked by self-trade prevention |
| Paise | 1/100 of a rupee. All Prayog prices are whole paise |
| T+1 | Settlement one business day after the trade |