On this page

Getting an order number back is not the end of the story. It is the beginning of one.

The most expensive misunderstanding in this API

stat: "Ok" plus a norenordno means the order was accepted. It does not mean it traded, and it does not mean it will.

An accepted order can still be rejected by the exchange, filled in pieces, or sit untouched all day. If your code stops at the order number, it does not know what happened to the order.

The states

You callPlaceOrderPENDINGreceivedOPENrestingREJECTEDnever tradedTRIGGER_PENDINGCOMPLETEfully filledCANCELEDyou withdrew itTradein TradeBookOnly OPEN and TRIGGER_PENDING can be modified or cancelledEverything else is terminal. Check status before you try.
Figure 1. Every documented order state and the transitions between them. Only the two blue states can still be modified or cancelled.
statusMeaningCan you still act on it?
PENDINGReceived by Infinn, not yet acknowledged by the exchange.not yet
OPENLive in the market, waiting to match.yes
TRIGGER_PENDINGA stop-loss order waiting for its trigger price.yes
COMPLETEFully filled.no — terminal
CANCELEDWithdrawn before filling.no — terminal
REJECTEDRefused by Infinn or the exchange. Read rejreason.no — terminal
INVALID_STATUS_TYPEA sentinel in the annexure, not an order state you should see.-

Report types: the events, not the states

status tells you where an order is. rpt - called reporttype on the WebSocket feed - tells you what just happened. One order produces many report types as it moves.

Single Order History, newest first — read it bottom-up
[
{ "status": "COMPLETE", "rpt": "Fill",       "fillshares": "180", "avgprc": "800.00" },
{ "status": "OPEN",     "rpt": "New",        "prc": "800.00", "qty": "180" },
{ "status": "PENDING",  "rpt": "PendingNew" },
{ "status": "PENDING",  "rpt": "NewAck" }
]
The array arrives newest first

In the published sample the first element is the final Fill and the last is the initial NewAck. Reverse the array to read the story forwards.

rpt
NewAck
ModAck
CanAck
PendingNew
PendingReplace
PendingCancel
New
Replaced
Canceled
Fill
Rejected
ReplaceRejected
CancelRejected
INVALID_REPORT_TYPE

The WebSocket feed emits a longer list, including lifecycle events such as Triggered, lapsed, Frozen and the after-market variants. See the WebSocket annexure.

Which states you can still act on

OperationAllowed statusesOtherwise
Modify OrderOPEN, TRIGGER_PENDINGRejected : ORA:Order not found
Cancel OrderOPEN, TRIGGER_PENDINGRejected : ORA:Order not found to Cancel
Exit Cover / BracketAn open cover or bracket orderCover and bracket orders only - products H and B
And expect to lose the race sometimes

An order can fill in the gap between you reading it as OPEN and your modification arriving. The result is Rejected : ORA:Order not found.

That is not a bug in your code and not an error worth alarming the user about - it means the order did what you wanted before you changed your mind. Handle it as a normal outcome.

Partial fills

A large order often fills in pieces. Between the first piece and the last, the order is partly done.

FieldMeaningExample
qtyWhat you asked for180
fillsharesWhat has filled so far120
avgprcAverage price across the filled quantity800.00
cancelqtyWithdrawn, on a cancelled order60
statusStays OPEN until the whole quantity fillsOPEN
Cancelling a partially filled order

Cancellation withdraws only the unfilled balance. The part that already traded is a trade, and trades cannot be undone - you would have to place an opposing order to reverse the position.

Two ways to follow an order

Order Book (REST)Order updates (stream)
Gives youEvery order's current stateEach change as it happens
LatencyYour polling intervalImmediate
Rate limit costOne request per pollNone after connecting
Shows the pathNo - only the latest stateYes - every event
Survives a restartYes - it is a fresh readNo - nothing is replayed
Use it forEstablishing state at startup and after a reconnectStaying current thereafter
Use both, for different jobs

Call Order Book once at startup to establish where everything stands, then keep that picture current from the order update feed. That combination needs no polling at all and stays correct across reconnects.

Worked example, with code

Status values are not consistently cased

The documented values and the sample values disagree

The annexure documents upper-case values: OPEN, REJECTED, COMPLETE. The published Order Book sample response contains "status": "Open" and "status": "REJECT" - different capitalisation, and REJECT rather than REJECTED.

Compare statuses defensively
# Both spellings of "rejected" appear in the documentation, in different
# cases. Normalise before comparing, and accept both.
TERMINAL = {"complete", "canceled", "cancelled", "rejected", "reject"}
ACTIONABLE = {"open", "trigger_pending"}


def is_terminal(order):
  """True when nothing further will happen to this order."""
  return str(order.get("status", "")).strip().lower() in TERMINAL


def can_modify(order):
  """True when the order can still be modified or cancelled."""
  return str(order.get("status", "")).strip().lower() in ACTIONABLE

The GTT lifecycle is different

A GTT order does not enter the states above when you create it. It waits, outside the order book entirely, until its price condition is met - and only then becomes an ordinary order that begins at PENDING.

StageWhere it livesHow to see it
You create itThe GTT list. Not the order book.Get Pending GTT Orders
WaitingStill the GTT list. No margin is blocked.The same endpoint
The trigger price is reachedAn ordinary order is created and enters PENDING.Order Book, and an alert update on the stream
From then onExactly like any other order.The order book and order updates
A pending GTT is not in the order book

Use Get Pending GTT Orders for the ones still waiting. They appear in the ordinary order book only after they fire.

A tracker that handles all of it

Seed from the book, then follow the stream
"""Track every order for a session, without polling.

One Order Book call establishes the starting picture; the WebSocket order
feed keeps it current. Reconnects re-seed from the book, because the stream
has no replay and anything that happened while disconnected is simply gone.
"""
import json
import threading

TERMINAL = {"complete", "canceled", "cancelled", "rejected", "reject"}


class OrderTracker:
  def __init__(self):
      self.orders = {}
      self._lock = threading.Lock()

  # --- seeding ------------------------------------------------------------

  def seed(self, order_book_rows):
      """Replaces local state from an Order Book response."""
      if not isinstance(order_book_rows, list):
          return
      with self._lock:
          self.orders = {
              row["norenordno"]: dict(row)
              for row in order_book_rows if row.get("norenordno")
          }

  # --- streaming ----------------------------------------------------------

  def apply(self, message):
      """Applies one 'om' order-update message.

      The stream uses different names from the REST endpoints -- pcode
      rather than prd, reporttype rather than rpt -- so those are mapped
      here, at the boundary, rather than everywhere downstream.
      """
      if message.get("t") != "om":
          return None

      ordno = message.get("norenordno")
      if not ordno:
          return None

      patch = dict(message)
      if "pcode" in patch:
          patch["prd"] = patch.pop("pcode")
      if "reporttype" in patch:
          patch["rpt"] = patch.pop("reporttype")

      with self._lock:
          # Merge, do not replace: an update carries only what changed.
          current = self.orders.setdefault(ordno, {})
          current.update(patch)
          return dict(current)

  # --- queries ------------------------------------------------------------

  def open_orders(self):
      with self._lock:
          return [
              dict(o) for o in self.orders.values()
              if str(o.get("status", "")).lower() not in TERMINAL
          ]

  def filled_quantity(self, ordno):
      with self._lock:
          return int(self.orders.get(ordno, {}).get("fillshares") or 0)

Next

Esc
↑↓ navigate↵ openEsc close/ to search