On this page
This page assumes nothing. If you already write software against HTTP APIs, skip to how requests are shaped, which covers the parts specific to Infinn.
An API is a way for programs to talk
When you log into Infinn in a browser and click Buy, a person is driving. You read the screen, you decide, you click.
An API removes the screen and the person. Your program sends the same instruction directly, in a form another program can read, and gets the answer back in the same form. Same account, same orders, same money - no clicking.
Think of a restaurant. You do not walk into the kitchen and cook. You give your order to a waiter, in a form the kitchen understands, and food comes back.
The API is the waiter. Your program is the customer. The menu - the list of things you are allowed to ask for, and exactly how to ask - is what this documentation is.
A request is what you send
Every request to Infinn has four parts. Here is a real one, labelled.
The method
What kind of action this is. Infinn uses
POST
for everything - all 63 endpoints, including the ones that only read data.
The address
Which thing you are talking to.
api.infinn.in
is the building;
/NorenWClientAPI/PlaceOrder
is the room.
The headers
Information
about
the request rather than the request itself: who you are, and what format you are sending.
The body
The actual content - which share, how many, at what price.
A response is what comes back
The answer has two parts that matter.
First, a status code: a three-digit number saying whether the message got through at all. 200 means it did. 401 means "I do not know who you are". 404 means "there is no such room".
Second, a body containing the answer itself.
With the Infinn API, a status code of 200 does not mean your request succeeded. It means the message arrived. Whether the thing you asked for actually happened is reported separately, inside the body.
This catches almost everyone once. It has a page of its own.
JSON is the format both sides use
JSON is just a way of writing down structured information as text so that a program can read it reliably. You already know how to read it.
{
"tsym": "RELIANCE-EQ",
"qty": "1",
"prc": "1000",
"trantype": "B"
}The rules are small:
{ }wraps a set of named values, like a form.- Each entry is
"name": value. [ ]wraps a list of things.- Text goes in double quotes.
JSON can hold real numbers, but Infinn sends almost everything as text - note "qty": "1" above, with quotes, not "qty": 1. Prices, quantities and timestamps all arrive as quoted strings.
That means "1000" + "500" gives you "1000500" in most languages, not 1500. Convert to a number before you do arithmetic. More on this.
Authentication is proving who you are
Infinn will not let any passing program move your money. So before you can do anything, you prove who you are and receive an access token - a long string of characters that acts as a temporary password.
Think of a hotel key card. You show your passport once at the desk, and in return you get a card that opens your room. The card is not your passport: it works only in this hotel, only for your room, and only until you check out.
An access token is that card. You prove your identity once with your username, password and keys; you get back a token; and every later request just carries the token. If the token leaks, you cancel it rather than changing your password.
Once you have one, you attach it to every request in a header:
Authorization: Bearer dde92200b0744defa1d98e3b3cc0027530c6b31627619dd318c9e3cd88ecd33aBearer is a fixed word meaning "whoever bears this token is allowed in". It is followed by one space and then your token.
Anyone holding your access token can place orders on your account. Never put one in a public repository, a client-side web page, a mobile app bundle, a screenshot, or a log file.
Putting it together
Here is the entire shape of working with the Infinn API, in five lines:
- Get credentials, onceRegister your IP address and generate an app key and a secret key in the Infinn terminal. You do this by hand, in a browser, and then never again. How
- Log in, once per sessionSend the user to a login page; get a one-time code back; exchange that code for an access token. How
- Make requestsSend a
POSTwith your token in the header and your question in the body. How - Check both layersLook at the status code, then look at
statinside the body. Both must be good. How - Stream, instead of asking repeatedlyFor anything live, open one WebSocket connection and let Infinn push updates to you. How
Words you will meet
Endpoint
One specific thing you can ask for, identified by its address. /NorenWClientAPI/PlaceOrder
is an endpoint; so is /NorenWClientAPI/OrderBook. There are
63 of them.
Parameter / field
One piece of information you include in a request. qty is a
field; so is prc. Some are required and some are optional, and
every endpoint page lists both.
Header
A line of information about the request rather than in it. Infinn needs two:
Authorization (who you are) and Content-Type (what
format the body is in).
Status code
A three-digit number summarising what happened at the transport level.
2xx is fine, 4xx means you did something wrong,
5xx means the server did.
Rate limit
A cap on how often you may call. Infinn allows 20 orders per second and 200 orders per minute. Exceed it and you get a 429.
Details
WebSocket
A connection that stays open, so the server can send you things without being asked. Used for live prices and order updates. Details
Token (two different meanings)
Confusingly, this word means two things here. An access
token is your temporary password. A contract token
is a number identifying an instrument - 2885 is
RELIANCE-EQ. Context always makes it clear which is meant.