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
pipinstall NorenRestApiOAuth
2. Install the Requirements
bash
pipinstall-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"])
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.
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
2. Install the Requirements
2. Authenticate
Shoonya currently supports OAuth-based login only — there's no TOTP auto-login flow. You'll need the
codereturned from the OAuth authorize redirect and a SHA256 checksum ofclient_id + secret_code + auth_codeto exchange for a session token. See Manual Login (OAuth) for the full authorize URL, redirect handling, and checksum reference.3. Fetch a quote
4. Place your first order
quantityto a size you're comfortable with, before executing.What's next