Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

INDstocks Python API Client

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.

Python License

Installation

pip install -r requirements.txt

Or using the package:

pip install -e .

Quick Start

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())

Features

REST API Coverage

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

WebSocket Streaming

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())

Error Handling

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")

Rate Limiting

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.

Retry Logic

Automatic retry on transient errors (429, 503, 504, network issues) with exponential backoff. Configurable via max_retries.

API Documentation

Full human-readable API documentation is in the docs/ folder:

# Document
1 Getting Started
2 Authentication & Conventions
3 User Management
4 Market Data
5 Instruments Master
6 Historical Data
7 WebSocket Streaming
8 Order Management
9 Smart Orders (GTT)
10 Margin Calculator
11 Portfolio & Holdings
12 Utility APIs
13 Error Codes

Official docs: https://api-docs.indstocks.com

Requirements

  • Python 3.9+
  • httpx — async HTTP client
  • websockets — WebSocket client

License

MIT

About

Full-featured, async-first Python library for algorithmic trading with INDstocks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages