Skip to main content

Option Chain Stream

Live streaming option chain for equity derivatives using Kite connect Websocket.

This package uses Redis as storage backend. Here Redis is used to store real time streaming websocket data and instruments detail i.e all option strike details for contracts. Combination of these data structure are used to create real-time option chain stream for any given instrument.

Installation

pip install optionchain_stream

Request parameters

Field Type Detail
api_key string Kite connect API key
secret_key string Kite connect API secret
request_token string Kite connect one-time token obtained after the login flow
access_token string The authentication token obtained post the login flow using request_token and secret_key
option_symbol string Symbol of the instrument(eg: NIFTY, SBIN, ONGC, etc)
option_expiry_date string Option expiry date in yyyy-mm-dd format(eg: '2021-02-25', '2021-04-29')
underlying boolean Add NSE-EQ underlying stock in option stream for True input

Usage

from optionchain_stream import OptionChain
OptionStream = OptionChain("option_symbol", "option_expiry_date in yyyy-mm-dd format", "api_key",
                    "api_secret=None", "request_token=None", "access_token=None", underlying=False)

# You can directly pass access_token from previous active session 
Eg: OptionStream = OptionChain("ONGC", "2021-02-25", "your_api_key", access_token="XXXXXX")

# Generate new session by passing api_secret and request_token
Eg: OptionStream = OptionChain("ONGC", "2021-02-25", "your_api_key", api_secret="XXXXX",
                    request_token="XXXXXX")

# You can fetch underlying stock tick as well in option chain, by sending optional param `underlying=True`
Eg: OptionStream = OptionChain("ONGC", "2021-02-25", "your_api_key", access_token="XXXXXX", underlying=True)
                  Or
    OptionStream = OptionChain("ONGC", "2021-02-25", "your_api_key", api_secret="XXXXX",
                    request_token="XXXXXX", underlying=True)


# Sync master instrument data to DB(redis)     
# This sync is required only once daily at initial run             
OptionStream.sync_instruments()

# Stream option chain data in real-time
StreamData = OptionStream.create_option_chain()
for data in StreamData:
    print(data)

Response

Responses are JSON messages.
1> For underlying=True, response contain underlying stock tick as well. Eg. for option_symbol=ONGC, underlying is ONGC EQ NSE contract:

....{'token': 633601, 'symbol': 'ONGC', 'last_price': 112.35, 'change': 0.4470272686633885},....,
{'token': 24268034, 'symbol': 'ONGC21FEB87PE', 'last_price': 1.5, 'volume': 61600, 'change': 0.0, 'oi': 400400},.....

2> By default, option contracts are sent.


...., 'change': 54.09090909090908, 'oi': 7700},{'token': 24268034, 'symbol': 'ONGC21FEB87PE', 'last_price': 1.5, 'volume': 61600, 'change': 0.0, 'oi': 400400}, 
{'token': 24268290, 'symbol': 'ONGC21FEB88CE', 'last_price': 10.6, 'volume': 0, 'change': -12.033195020746897, 'oi': 15400}, {'token': 24268546, 'symbol': 
'ONGC21FEB88PE', 'last_price': 1.75, 'volume': 53900, 'change': 25.000000000000007, 'oi': 261800}, {'token': 24268802, 'symbol': 'ONGC21FEB89CE', 
'last_price':10.6, 'volume': 15400, 'change': -5.77777777777778, 'oi': 107800}, 
{'token': 24269058, 'symbol': 'ONGC21FEB89PE', 'last_price': 1.85, 'volume': 184800, 'change': -11.904761904761905, 'oi': 338800}, {'token': 24269314, 'symbol': 
'ONGC21FEB90CE', 'last_price': 10.0, 'volume': 654500, 'change': 2.5641025641025643, 'oi': 1632400}, {'token': 24269570, 'symbol': 'ONGC21FEB90PE', 'last_price': 
2.2, 'volume': 1925000, 'change': -2.2222222222222143, 'oi': 3326400}, {'token': 24269826, 'symbol': 'ONGC21FEB91CE', 'last_price': 9.3, 'volume': 15400, 
'change': -6.999999999999993, 'oi': 308000}, {'token': 24270082, 'symbol': 'ONGC21FEB91PE', 'last_price': 2.55, 'volume': 61600, 'change': -5.555555555555569, 
'oi': 323400}, {'token': 24270338, 'symbol': 'ONGC21FEB92CE', 'last_price': 8.7, 'volume': 30800,....

Response attributes

Field Type Detail
token string instrument_token for requested tradingsymbol
symbol string tradingsymbol of the instrument
last_price float Current market price
volume int Volume traded for the day
change float Price change % w.r.t previous day close/LTP
oi float Open Interest for a options contract

Metadata

Release files for optionchain-stream 0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optionchain-stream 0.6
File Size Uploaded
optionchain_stream-0.6.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for optionchain-stream 0.6
File Interpreter ABI Platform
optionchain_stream-0.6-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / optionchain_stream-0.6.tar.gz

Download URL optionchain_stream-0.6.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f4b9eb4893bbf20bab5825cc6523ee801c4de8fb9ac77e30b5d0074ce461d8ec
BLAKE2b-256 checksum
How to use checksums
f7fac690fa809a56f8e424619d6df8dd79638d73dda0af50d17b3c89d120471b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9

Release files / optionchain_stream-0.6-py3-none-any.whl

Download URL optionchain_stream-0.6-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e1416dee402a7b918886fcec8427ca4dbc7ac7bec65054e1189e813ac54dc21
BLAKE2b-256 checksum
How to use checksums
24361ab92ab4a1d300f3a982737a67c57e9aa3d021c0f847a0af475cd2a8966c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.6 This release

2 release files

0.5

2 release files

0.4

2 release files

0.3

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page