Getting started¶
Go from zero to a placed and cancelled order in about five minutes. The order in this guide is priced well below the market, so it doesn't fill and you can cancel it.
You need a US stocks account with INDmoney.
1. Get an access token¶
Generate a token on the Access Tokens page and copy it. If you've set up TOTP, you can generate one from code instead (see Authentication):
curl --location 'https://api.indmoney.com/generate/token' \
--header 'x-api-key: YOUR_CLIENT_ID' \
--header 'Content-Type: application/json' \
--data '{"mpin": "YOUR_MPIN", "totp": "123456"}'
The rest of this guide calls your token YOUR_ACCESS_TOKEN.
2. Check the market is open¶
curl --location 'https://api.indmoneyglobal.com/v1/market/status' \
--header 'Authorization: YOUR_ACCESS_TOKEN'
Look at the US row: session is REGULAR during US market hours.
3. Find a security ID¶
Download the instrument list and look up a ticker. This guide uses VTI, security_id 116532.
4. Get a price¶
curl --location 'https://api.indmoneyglobal.com/v1/market/quotes/ltp?security_ids=116532' \
--header 'Authorization: YOUR_ACCESS_TOKEN'
5. Place a LIMIT order below the market¶
curl --location 'https://api.indmoneyglobal.com/v1/order/place' \
--header 'Authorization: YOUR_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{"security_id": "116532", "txn_type": "BUY", "order_type": "LIMIT", "quantity": 1, "price": 20, "validity": "DAY"}'
You get 202 with an order_id and order_status: ACCEPTED. Your trading balance needs at least $20 plus fees, because a BUY LIMIT order blocks that amount until it fills or is cancelled.
6. Check the order¶
curl --location 'https://api.indmoneyglobal.com/v1/orders/ORDER_ID' \
--header 'Authorization: YOUR_ACCESS_TOKEN'
The order is open until order_status shows one of the final order statuses.
7. Cancel it¶
curl --location 'https://api.indmoneyglobal.com/v1/order/cancel' \
--header 'Authorization: YOUR_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{"order_id": "ORDER_ID"}'
Check the order again until order_status is CANCELLED.
The same flow in Python¶
import time
import requests
BASE = "https://api.indmoneyglobal.com"
HEADERS = {"Authorization": "YOUR_ACCESS_TOKEN"}
FINAL = ("FILLED", "CANCELLED", "REJECTED", "FAILED", "EXPIRED")
status = requests.get(f"{BASE}/v1/market/status", headers=HEADERS).json()
us = next(row for row in status["data"] if row["exchange"] == "US")
print("US session:", us["session"])
ltp = requests.get(f"{BASE}/v1/market/quotes/ltp",
params={"security_ids": "116532"}, headers=HEADERS).json()
print("VTI:", ltp["data"]["116532"]["live_price"])
order = requests.post(f"{BASE}/v1/order/place", headers=HEADERS, json={
"security_id": "116532", "txn_type": "BUY", "order_type": "LIMIT",
"quantity": 1, "price": 20, "validity": "DAY",
}).json()
order_id = order["data"]["order_id"]
print("Placed:", order_id)
time.sleep(3)
requests.post(f"{BASE}/v1/order/cancel", headers=HEADERS, json={"order_id": order_id})
for _ in range(5):
time.sleep(3)
o = requests.get(f"{BASE}/v1/orders/{order_id}", headers=HEADERS).json()["data"]
print("Status:", o["order_status"])
if o["order_status"] in FINAL:
break
If cancel returns 409 pending_broker_confirmation, the order is still being processed. Wait a few seconds and cancel again.
Next¶
- Place order: all order types and rules
- Live prices: stream prices instead of polling
- Errors: what each error means and when to retry