On this page

Knowing which systems your request passes through explains most of the API's behaviour: why some failures carry no message, why a timeout is not the same as a rejection, and why the rate limit bites before your order is ever seen by a market.

The four parties

Your programany languageInfinn APIHTTPS + WebSocketOrder managementrisk checks, marginExchangeNSE / BSE / MCXEvery call you make travels left to right, and the answer comes back right to left.orderreplyRate limit: 20 req/sec, 200 req/minThe limit is applied at the API, before your call reaches the order system.
Figure 1. Every call travels left to right and the answer comes back right to left. Each hop can fail independently, and each fails differently.

Your program

Anything that can make an HTTPS request. There is no required language, framework or SDK.

The Infinn API

The public front door at

api.infinn.in

. It checks your token and your IP address, applies the rate limit, and forwards what is left.

The order management system

Infinn's internal engine. It knows your balance, your positions and your risk limits. It is what decides whether you can afford an order. The error strings beginning

RED:RULE:

come from here.

The exchange

NSE, BSE or MCX. The actual market. It has the final word on whether an order is accepted and whether it trades.

Following one order all the way

  1. Your program sends the requestA POST to /NorenWClientAPI/PlaceOrder carrying your access token and a JSON body describing the order.
  2. The API checks the doorIs the token valid? Is it from a registered IP address? Have you exceeded 20 orders this second, or 200 this minute? If any answer is no, you get a 401 or a 429 with no body at all, and nothing further happens.
  3. The order management system checks the orderDo you have the margin? Is the price inside the circuit limits? Is this product allowed on this exchange for this account? A failure here comes back as HTTP 200 with stat: "Not_Ok" and an emsg explaining why.
  4. The exchange receives itIf everything passed, the order is forwarded. You get back stat: "Ok" and a norenordno - your order number.
  5. The order waits, or tradesThe order number means accepted, not filled. The order now sits in the market until it matches, you cancel it, or the day ends.
  6. You find out what happenedEither by reading the order book, or - much better - by having subscribed to order updates, which push each change to you as it occurs.
Step 5 is where most bugs live

A great many first integrations treat step 4 as the end: order number received, job done, move on. It is not. Between "accepted" and "filled" an order can be rejected by the exchange, partially filled, or left sitting all day.

The order lifecycle page sets out every state and which transitions are possible.

Two kinds of conversation

Infinn offers two quite different ways to get information, and choosing wrongly is the most common performance mistake.

Polling — what not to doYour appAPIGetQuotesGetQuotesGetQuotesGetQuotes4 requests to learn the price changed onceStreaming — what to doYour appFeedsubscribe oncepushed only when it changes1 request, then updates arrive by themselves
Figure 2. Asking repeatedly versus being told. For anything that changes continuously, the second is not merely faster -- it is the only approach that fits inside the rate limit.

The rule of thumb: if you would otherwise write a loop with a sleep in it, you want the WebSocket.

Where each kind of failure comes from

The layer that rejects you determines the shape of what you get back, which is why one error-handling branch is never enough.

Your requestLAYER 1 — gatewayToken? IP? Path?401 / 404 / 429empty bodyLAYER 2 — trading systemHTTP 200always"stat": "Ok""stat": "Not_Ok"An HTTP 200 is NOT success. Check the status code, then check stat in the body.Layer 1 failures have no body at all. Layer 2 failures look like successes to your HTTP client.
Figure 3. The gateway and the trading system fail in completely different ways. Code that only checks the HTTP status will treat every trading-system rejection as a success.
CodeMeaningBody
401The gateway rejected your credentials before the request reached the trading system.empty body
400Missing or bad request parameters or values.
403Session expired or invalidated. Must relogin.
404The requested resource was not found.empty body
405The request method is not allowed on this endpoint.
410The requested resource is gone permanently.
429Too many requests to the API (rate limiting).
500Something unexpected went wrong.
502The backend OMS is down and the API is unable to communicate with it.
503Service unavailable; the API is down.
504Gateway timeout; the API is unreachable.

Full detail, with causes and fixes for each, is on the error reference.

What this means for how you build

Check both layers, every time

Look at the HTTP status, and then look at stat in the body. Every code sample on this site does both; see the two error layers.

Treat a timeout as "unknown", not "failed"

If a PlaceOrder call times out, the order may well be live. Read the order book before retrying, or you will end up with two positions. Retrying safely

Keep one WebSocket, not many REST loops

A single connection replaces an unbounded number of polling calls and keeps you comfortably inside the rate limit. Worked example

Fix your IP address early

Because the API authorises by IP as well as by token, decide where your code will run before you build around it. A dynamic home IP will stop working without warning. Credentials

Drive your UI from the account's own entitlements

User Details returns the exchanges, products and order types this account may actually use. Hard-coding them instead produces rejections that look like bugs in your own code.

Next

Esc
↑↓ navigate↵ openEsc close/ to search