Skip to Main Content

Quick Start (5 minutes)

Go from zero to your first authenticated API call in under five minutes.

Overview

This walkthrough gets a single-user script talking to Shoonya end to end: log in via OAuth, fetch a quote, and place one order. It assumes you already have a Shoonya trading account and API access enabled — if not, see Prerequisites first.

1. Install the SDK

bash
pip install NorenRestApiOAuth

2. Install the Requirements

bash
pip install -r requirements.txt

2. Authenticate

Shoonya currently supports OAuth-based login only — there's no TOTP auto-login flow. You'll need the code returned from the OAuth authorize redirect and a SHA256 checksum of client_id + secret_code + auth_code to exchange for a session token. See Manual Login (OAuth) for the full authorize URL, redirect handling, and checksum reference.

python
import os
import hashlib
from NorenRestApiPy.NorenApi import NorenApi

CLIENT_ID   = os.environ["SHOONYA_CLIENT_ID"]
USER_ID     = os.environ["SHOONYA_USER_ID"]
SECRET_CODE = os.environ["SHOONYA_SECRET_CODE"]

# 1. Send the user to the OAuth authorize URL and capture the
#    "code" query param from the redirect back to your app.
#    https://api.shoonya.com/OAuthlogin/authorize/oauth?client_id=Your_Client_id
auth_code = os.environ["SHOONYA_AUTH_CODE"]  # obtained from the redirect

# 2. Compute the checksum GenAcsTok expects.
checksum = hashlib.sha256(
    (CLIENT_ID + SECRET_CODE + auth_code).encode()
).hexdigest()

# 3. Exchange for a session token.
api = NorenApi(host="https://api.shoonya.com/NorenWClientAPI/", websocket="wss://api.shoonya.com/NorenWSAPI/")
session = api.gen_access_token(
    uid=USER_ID,
    code=auth_code,
    appkey=checksum,
)
print("Logged in:", session["susertoken"])

3. Fetch a quote

python
quote = api.get_quotes(exchange="NSE", token="2885")
print(quote["tsym"], quote["lp"])

4. Place your first order

python
order = api.place_order(
    buy_or_sell='B', product_type='C',
    exchange='NSE', tradingsymbol='CANBK-EQ',
    quantity=1, discloseqty=0, price_type='SL-LMT', price=200.00, trigger_price=199.50,
    retention='DAY', remarks='my_order_001',
)
print("Order placed:", order)
Before you run thisThe snippet above sends a live market order if pointed at production credentials. Confirm you're on a paper/test account, or set quantity to a size you're comfortable with, before executing.

What's next