Async Python client for the INDstocks Trading API v1
Full-featured, async-first Python library for algorithmic trading with INDstocks. Covers all API endpoints: user management, market data, instruments, historical data, order management, smart orders (GTT), portfolio, margin calculator, and WebSocket streaming.
pip install -r requirements.txtOr using the package:
pip install -e .import asyncio
from indstocks import INDstocksClient
async def main():
async with INDstocksClient(access_token="YOUR_ACCESS_TOKEN") as client:
# Get user profile
profile = await client.user.get_profile()
print(f"Hello, {profile['data']['first_name']}!")
# Get account funds
funds = await client.user.get_funds()
print(f"Available balance: ₹{funds['data']['sod_balance']}")
# Get real-time quotes
quotes = await client.market_data.get_full_quotes("NSE_3045,NSE_11536")
for code, data in quotes['data'].items():
print(f"{code}: ₹{data['live_price']}")
# Place a LIMIT order
order = await client.orders.place_order(
txn_type="BUY",
exchange="NSE",
segment="EQUITY",
product="CNC",
order_type="LIMIT",
validity="DAY",
security_id="3045",
qty=1,
limit_price=790.00,
algo_id="99999",
)
print(f"Order placed: {order['data']['order_id']}")
asyncio.run(main())| Module | Endpoints |
|---|---|
client.user |
Profile, Funds |
client.market_data |
Full quotes, LTP, Market depth, Historical candles |
client.instruments |
CSV instrument master download & parse |
client.orders |
Place, Modify, Cancel, Order book, Trade book, Trade details |
client.smart_orders |
Multi-leg GTT orders with SL/Target, Trigger orders |
client.portfolio |
Equity holdings, Open positions |
client.margin |
Pre-trade margin estimation with charges breakdown |
client.utility |
Option chain, Expiries, Greeks |
from indstocks import INDstocksClient
async def on_price(data):
print(f"Price update: {data}")
async def main():
async with INDstocksClient(access_token="TOKEN") as client:
ws = client.websocket()
# Subscribe to LTP feed
await ws.subscribe_prices(
instruments=["NSE:2885", "NSE:3045"],
mode="ltp",
)
ws.on_price(on_price)
# Subscribe to order updates
await ws.subscribe_orders()
await ws.run_forever()
asyncio.run(main())from indstocks import (
INDstocksClient,
TokenException,
InputException,
OrderException,
NetworkException,
)
async def safe_trade():
async with INDstocksClient(access_token="TOKEN") as client:
try:
order = await client.orders.place_order(
txn_type="BUY",
exchange="NSE",
segment="EQUITY",
product="CNC",
order_type="LIMIT",
validity="DAY",
security_id="3045",
qty=1,
limit_price=790.00,
algo_id="99999",
)
except TokenException:
print("Token expired — refresh your access token")
except InputException as e:
print(f"Invalid input: {e}")
except OrderException as e:
print(f"Order rejected by RMS: {e}")
except NetworkException:
print("Network issue — retry later")The client automatically respects API rate limits by default:
- Order APIs: 10 req/min
- Quote APIs: 5 req/min
- Data APIs: 5 req/min
- Non-trading APIs: 15 req/min
Disable with rate_limit_pause=False if needed.
Automatic retry on transient errors (429, 503, 504, network issues) with exponential backoff. Configurable via max_retries.
Full human-readable API documentation is in the docs/ folder:
Official docs: https://api-docs.indstocks.com
- Python 3.9+
httpx— async HTTP clientwebsockets— WebSocket client
MIT