# AccelPix Data API
# Introduction
Python library to connect and stream the market data.
This is websocket and fallback transport based library with all the functionalyties to get eod and live streaming data
Simple and easy integration with your web application, all heavy weight work are back lifted.
# What's new
v1.3.5 : 13-12-2024
Bug fixes
v1.3.4 : 11-Dec-2024
Scheme param removed from initialize method
Library tree updated to latest version
v1.3.3 : 29-Aug-2022
1. Option Chain and Option Chain Range subscription and unsubscription method.
v1.3.2 : 02-Aug-2022
1. Intraducing Optionchain subscription and unsubscription method.
v1.3.1 : 28-Jan-2022
1. New callback for Trade snapshot during subscription, earlier it was provided along with Trade callback
2. Segment subscription for the entitled user
3. Intraducing Option Greeks
v1.3.0 : 06-May-2021
1. Upper and lower price band for EQ market added - refer 'Refs snapshot data' section
2. Live ticks aggregation which provides current day minutes bar - refer 'History data - Inraday' section
# Simple steps to up and running
> ### For Streaming Data:
1. Initialize
2. Register required callbacks
3. Do subscribe with symbols list
> ### For History Data:
1. Initialize
2. Async call to respective methods exposed
#### **Working sample is available at the bottom of this help page**
# Installation
```bash
pip install pix-apidata
```
# Import
```python
import asyncio
from pix_apidata import *
```
# Initialize
```python
api = apidata_lib.ApiData()
event_loop = asyncio.get_event_loop()
apiKey = "api-access-key" //provided by your data vendor
apiHost = "apidata.accelpix.in" //provided by your data vendor
await api.initialize(apiKey, apiHost)
# *** IMPORTANT ***
# *** initialize(...) - wait for initialize to complete before making any other API calls.
```
# Symbol Master
### Use below REST API to get Master Data
#### (Only for master data download due to larger data size)
### https://apidata.accelpix.in/api/hsd/Masters/2?fmt=json
```python
#response data
{
xid: 1,
tkr: "20MICRONS",
atkr: null,
ctkr: null,
exp: "1970-01-01 00:00:00",
utkr: null,
inst: "EQUITY",
a3tkr: null,
sp: 0.00,
tk: 16921
}
```
# Callbacks for live streaming
### Available callbacks
#### api.on_trade_update(on_trade)
#### api.on_best_update(on_best)
#### api.on_refs_update(on_refs)
#### api.on_srefs_update(on_srefs)
#### api.on_tradeSnapshot_update(on_tradeSnap)
#### api.on_greeks_update(on_greeks)
#### Trade
```python
#callback to listen for trade data
api.on_trade_update(on_trade)
def on_trade(msg):
print(msg) # Trade msg
t = apidata_models.Trade(msg)
print(t.ticker , t.oi) #likewise object can be called for id, kind, ticker, segment, price, qty, volume, oi
#response data
{
id: 0,
ticker: 'NIFTY-1',
segmentId: 2,
time: 1293704493,
price: 13958.6,
qty: 75,
volume: 1587975,
oi: 9700275,
kind: 'T'
}
```
#### Trade snapshot data
```python
#callback to listen for trade snapshot, called during subcription process
#listen to onTrade callback for continuouse stream data
api.on_tradeSnapshot_update(on_tradeSnapshot)
def on_tradeSnapshot(msg):
print(msg) # TradeSnapshot msg
t = apidata_models.Trade(msg)
print(t.ticker , t.oi) #likewise object can be called for id, kind, ticker, segment, price, qty, volume, oi
#response data
{
id: 0,
ticker: 'NIFTY-1',
segmentId: 2,
time: 1293704493,
price: 13958.6,
qty: 75,
volume: 1587975,
oi: 9700275,
kind: 'T'
}
```
#### Best
```python
#callback to listen for bid, ask and respective qty
api.on_best_update(on_best)
def on_best(msg):
print(msg) # Best msg
b = apidata_models.Best(msg)
print(b.ticker , b.bidPrice) #likewise object can be called for segmentId, kind, bidQty, askPrice, askQty
#response data
{
ticker: 'NIFTY-1',
segmentId: 2,
kind: 'B',
bidPrice: 13957.45,
bidQty: 75,
askPrice: 13958.8,
askQty: 75,
time: 1293704493
}
```
### Recent change in Refs data
```python
#callback to listen for change in o, h, l, c, oi and avg data
api.on_trade_ref(on_ref)
def on_ref(msg):
print(msg) # Refs msg
ref = apidata_models.Refs(msg)
print(ref.price) #likewise object can be called for segmentId, kind, ticker
#response data
{
kind: 'A',
ticker: 'NIFTY-1',
segmentId: 2,
price: 11781.08984375
}
```
### Refs snapshot data
```python
#callback to listen for o, h, l, c, oi and avg snapshot
api.on_srefs_update(on_srefs)
def on_srefs(msg):
print(msg) # Srefs msg
sref = apidata_models.RefsSnapshot(msg)
print(sref.high) #likewise object can be called for kind, ticker, segmentId, open, close, high, low, avg, oi, upperBand and lowerBand
#response data
{
kind: 'V',
ticker: 'NIFTY-1',
segmentId: 2,
open: 11749.650390625,
close: 11681.5498046875,
avg: 11780.8603515625,
high: 11822,
low: 11731.2001953125,
oi: 10615950,
upperBand: 0,
lowerBand: 0
}
```
### OptionGreeks data
```python
#callback to listen for optionGreek data
api.on_greeks_update(on_greeks)
def on_greeks(msg):
print(msg) # Option Greeks Data
greeks = apidata_models.Greeks(msg)
print(greeks.gamma) # likewise object can be called for kind, ticker, iv, delta, theta, vega, gamma, ivvwap, vanna, charm, speed, zomma, color, volga, veta, tgr, tv and dtr
#response data
{
kind:'G',
ticker:'NIFTY2220318500CE',
charm:13.510149002075195,
color:0.0010876863962039351,
ivvwap:0.2657951712608337,
speed:-0.25761404633522034,
tgr:1437.1766357421875,
theta:-3.690974235534668,
tv:-28860.783203125,
vega:1.935671329498291,
veta:57653.11328125,
volga:0.000020740208128700033,
zomma:3.531916377141897e-7,
iv:0.2650300860404968,
gamma:0.00012788892490789294,
dtr:-1.9068187475204468,
delta:0.03707314282655716
}
```
### OptionGreeks Snapshot data
```python
#callback to listen for optionGreek snap data
api.on_greeks_update(on_greeks)
def on_greekSnapshot(msg):
print(msg) # Option Greeks snap data
greeks = apidata_models.Greeks(msg)
print(greeks.gamma) # likewise object can be called for kind, ticker, iv, delta, theta, vega, gamma, ivvwap, vanna, charm, speed, zomma, color, volga, veta, tgr, tv and dtr
#response data
{
kind:'G',
ticker:'NIFTY2220318500CE',
charm:13.510149002075195,
color:0.0010876863962039351,
ivvwap:0.2657951712608337,
speed:-0.25761404633522034,
tgr:1437.1766357421875,
theta:-3.690974235534668,
tv:-28860.783203125,
vega:1.935671329498291,
veta:57653.11328125,
volga:0.000020740208128700033,
zomma:3.531916377141897e-7,
iv:0.2650300860404968,
gamma:0.00012788892490789294,
dtr:-1.9068187475204468,
delta:0.03707314282655716
}
```
# Callbacks for connection status
#### api.on_connection_started(connection_started)
#### api.on_connection_stopped(connection_stopped)
```python
# Fired when connection is successful
def connection_started():
print("Connection started callback")
# Fired when the connection is closed after automatic retry or some issues in networking
# Need to re-establish the connection manually
def connection_stopped():
print("connection Stopped callback")
```
# Live stream subscription
#### Subscribe to receive updates of segments entitled to you
```python
needSnapshot = False
await api.subscribeSegments(needSnapshot)
# IMPORTANT NOTE:
# If needSnapshot = True, then buffer the updates received on 'api.on_tradeSnapshot_update' and 'api.on_srefs_update' before processing.
# Data transfer is huge and you may get disconnected from server in-case if you don't process the incoming updates as fast enough.
# It's advised to buffer the data then process it once 'api.subscribeSegments' method returns.
```
#### Subscribe to receive ALL updates
```python
await api.subscribeAll('NIFTY-1')
```
#### Subscribe to receive TRADE updates
```python
await api.subscribeTrade(['NIFTY-1','BANKNIFTY-1','NIFTY 50'])
```
#### Subscribe to receive REFS and BEST updates
```python
await api.subscribeBestAndRefs(['NIFTY-1','BANKNIFTY-1'])
```
#### Subscribe to receive Greeks updates
```python
await api.subscribeGreeks(['NIFTY2220318500CE'])
```
#### Subscribe to receive Optionchain updates
```python
# params: spotName, Expiry Date
# subscribe to full chain
await api.subscribeOptionChain('BANKNIFTY','20220901')
# subscribe to range of strikes(CE, PE) considering current spot value(at time of subscribe) as the mid-point, essentially 10 strike(CE,PE) below mid-point and 10 strikes(CE, PE) above mid-point and total of 40 contracts subscribed for the below call.
await api.subscribeOptionChainRange('NIFTY','20220901',10)
```
# Unsubscribe live stream
```python
# unsubscribe single symbol
await api.unsubscribeAll(['NIFTY-1'])
# unsubscribe multiple symbol
await api.unsubscribeAll(['NIFTY-1','BANKNIFTY-1'])
```
#### Unsubscribe Optionchain updates
```python
await api.unsubscribeOptionChain('NIFTY','20220609')
```
#### Unsubscribe Greeks updates
```python
await api.unsubscribeGreeks(['NIFTY2220318500CE'])
```
# History data - Eod
```python
# Continues data
#params: ticker, startDate, endDate
await api.get_eod("NIFTY-1", "20200828", "20200901")
# Contract data
#params: underlying ticker, startDate, endDate, contractExpiryDate
await api.get_eod_contract("NIFTY", "20200828", "20200901", "20201029")
#response data
{
td: '2020-08-28T00:00:00',
op: 11630,
hp: 11708,
lp: 11617.05,
cp: 11689.05,
vol: 260625,
oi: 488325
}
```
# History data - Inraday
#### Provides intra-eod bars with the time resolution in minutes (default:'5' mins)
#### You can set minute resolution to '1', '5', '10' and so on.
#### Custom minute resolution also supported like '3', '7' and so on.
#### Passing CURRENT DATE as parameter in 'toDate' will respond the LIVE ticks aggregated upto the time it traded today. Last BAR of the current day may be incomplete. Current day tick aggregation response will always provide complete bar list from the beginning of day.
```python
# Continues data
#params: ticker, startDate, endDate, resolution
await api.get_intra_eod("NIFTY-1", "20210603", "20210604", "5")
# Contract data
#params: underlying ticker, startDate, endDate, contractExpiryDate
await api.get_intra_eod_contract("NIFTY", "20200828", "20200901", "20201029", "5")
#response data
{
td: '2020-08-28T09:15:00',
op: 11630,
hp: 11643.45,
lp: 11630,
cp: 11639.8,
vol: 4575,
oi: 440475
}
```
# History data - Ticks
Provides back log ticks from the date time specified till current live time, that is the ticks available till request hit the server.
```python
#params: ticker, fromDateTime
await api.get_back_ticks("BANKNIFTY-1", "20201016 15:00:00")
#response data
{
td: 2020-11-16T15:00:01.000Z,
pr: 23600,
vol: 125,
oi: 1692375
}
```
# Example
``` Python
import asyncio
import time
#import requests
from pix_apidata import *
api = apidata_lib.ApiData()
event_loop = asyncio.get_event_loop()
async def main():
api.on_connection_started(connection_started)
api.on_connection_stopped(connection_stopped)
api.on_trade_update(on_trade)
api.on_best_update(on_best)
api.on_refs_update(on_refs)
api.on_srefs_update(on_srefs)
api.on_tradeSnapshot_update(on_tradeSnapshot)
api.on_greeks_update(on_greeks)
api.on_greekSnapshot_update(on_greekSnapshot)
key = "your-api-key"
host = "apidata.accelpix.in"
scheme = "http"
s = await api.initialize(key, host,scheme)
print(s)
his = await api.get_intra_eod("NIFTY-1","20210603", "20210604", "5")
print("History : ",his)
syms = ['NIFTY-1', 'BANKNIFTY-1']
symsGreeks = ["BANKNIFTY2290126500CE"]
await api.subscribeAll(syms)
# await api.subscribeOptionChain('NIFTY','20220901')
# await api.subscribeGreeks(symsGreeks)
# await api.subscribeOptionChainRange('NIFTY','20220901',3)
print("Subscribe Done")
#needSnapshot = False
#await api.subscribeSegments(needSnapshot)
#time.sleep(5)
# await api.unsubscribeAll(['NIFTY-1'])
# await api.unsubscribeGreeks(['BANKNIFTY2290126500CE'])
# await api.unsubscribeOptionChain('NIFTY','20220901')
def on_trade(msg):
trd = apidata_models.Trade(msg)
print("Trade : ",msg) # or print(trd.volume) likewise object can be called for id, kind, ticker, segment, price, qty, oi
def on_best(msg):
bst = apidata_models.Best(msg)
print("Best : ",msg) # or print(bst.bidPrice) likewise object can be called for ticker, segmentId, kind, bidQty, askPrice, askQty
def on_refs(msg):
ref = apidata_models.Refs(msg)
print("Refs snapshot : ",msg) # or print(ref.price) likewise object can be called for segmentId, kind, ticker
def on_srefs(msg):
sref = apidata_models.RefsSnapshot(msg)
print("Refs update : ",msg) # or print(sref.high) likewise object can be called for kind, ticker, segmentId, open, close, low, avg, oi, lowerBand,upperBand
def on_tradeSnapshot(msg):
trdSnap = apidata_models.Trade(msg)
print("TradeSnap : ",msg) # or print(trdSnap.volume) likewise object can be called for id, kind, ticker, segment, price, qty, oi
def on_greeks(msg):
greeks = apidata_models.Greeks(msg)
print("OptionGreeks : ",msg) # or print(greeks.gamma) likewise object can be called for kind, ticker, iv, delta, theta, vega, gamma, ivvwap, vanna, charm, speed, zomma, color, volga, veta, tgr, tv and dtr
def on_greekSnapshot(msg):
gr = apidata_models.Greeks(msg)
print(msg) # or print(greeks.gamma) likewise object can be called for kind, ticker, iv, delta, theta, vega, gamma, ivvwap, vanna, charm, speed, zomma, color, volga, veta, tgr, tv and dtr
def connection_started():
print("Connection started callback")
def connection_stopped():
print("Connection stopped callback")
event_loop.create_task(main())
try:
event_loop.run_forever()
finally:
event_loop.close()
```
### Powered by ticAnalytics®
Raw data
{
"_id": null,
"home_page": "https://github.com/pscoumar",
"name": "pix-apidata",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "stock market, apidata, accelpix, ticanalytics",
"author": "Coumar Pandourangane",
"author_email": "pscoumar@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/70/68/d4cf1e5959993c2277c2385a40a0d6694b8a55a28eca44908173c6d02d8d/pix_apidata-1.3.5.tar.gz",
"platform": null,
"description": "# AccelPix Data API\r\n\r\n# Introduction \r\n\r\nPython library to connect and stream the market data.\r\nThis is websocket and fallback transport based library with all the functionalyties to get eod and live streaming data\r\n\r\nSimple and easy integration with your web application, all heavy weight work are back lifted.\r\n\r\n# What's new\r\nv1.3.5 : 13-12-2024\r\nBug fixes\r\n\r\nv1.3.4 : 11-Dec-2024\r\nScheme param removed from initialize method\r\nLibrary tree updated to latest version\r\n\r\nv1.3.3 : 29-Aug-2022\r\n1. Option Chain and Option Chain Range subscription and unsubscription method.\r\n\r\nv1.3.2 : 02-Aug-2022\r\n1. Intraducing Optionchain subscription and unsubscription method.\r\n\r\nv1.3.1 : 28-Jan-2022\r\n1. New callback for Trade snapshot during subscription, earlier it was provided along with Trade callback\r\n2. Segment subscription for the entitled user\r\n3. Intraducing Option Greeks \r\n\r\nv1.3.0 : 06-May-2021\r\n1. Upper and lower price band for EQ market added - refer 'Refs snapshot data' section\r\n2. Live ticks aggregation which provides current day minutes bar - refer 'History data - Inraday' section \r\n# Simple steps to up and running\r\n> ### For Streaming Data:\r\n1. Initialize\r\n2. Register required callbacks\r\n3. Do subscribe with symbols list\r\n\r\n> ### For History Data:\r\n1. Initialize\r\n2. Async call to respective methods exposed\r\n\r\n#### **Working sample is available at the bottom of this help page**\r\n# Installation\r\n```bash\r\npip install pix-apidata \r\n```\r\n\r\n# Import\r\n\r\n```python\r\nimport asyncio\r\nfrom pix_apidata import *\r\n```\r\n\r\n# Initialize\r\n```python\r\napi = apidata_lib.ApiData()\r\nevent_loop = asyncio.get_event_loop()\r\n\r\napiKey = \"api-access-key\" //provided by your data vendor\r\napiHost = \"apidata.accelpix.in\" //provided by your data vendor\r\n\r\nawait api.initialize(apiKey, apiHost) \r\n\r\n# *** IMPORTANT ***\r\n\r\n# *** initialize(...) - wait for initialize to complete before making any other API calls.\r\n```\r\n# Symbol Master\r\n### Use below REST API to get Master Data\r\n#### (Only for master data download due to larger data size)\r\n### https://apidata.accelpix.in/api/hsd/Masters/2?fmt=json\r\n```python\r\n#response data\r\n{\r\n xid: 1,\r\n tkr: \"20MICRONS\",\r\n atkr: null,\r\n ctkr: null,\r\n exp: \"1970-01-01 00:00:00\",\r\n utkr: null,\r\n inst: \"EQUITY\",\r\n a3tkr: null,\r\n sp: 0.00,\r\n tk: 16921\r\n}\r\n```\r\n# Callbacks for live streaming\r\n\r\n### Available callbacks \r\n\r\n#### api.on_trade_update(on_trade)\r\n\r\n#### api.on_best_update(on_best)\r\n\r\n#### api.on_refs_update(on_refs)\r\n\r\n#### api.on_srefs_update(on_srefs)\r\n\r\n#### api.on_tradeSnapshot_update(on_tradeSnap)\r\n#### api.on_greeks_update(on_greeks)\r\n\r\n#### Trade\r\n```python\r\n#callback to listen for trade data\r\napi.on_trade_update(on_trade)\r\ndef on_trade(msg):\r\n print(msg) # Trade msg\r\n t = apidata_models.Trade(msg)\r\n print(t.ticker , t.oi) #likewise object can be called for id, kind, ticker, segment, price, qty, volume, oi\r\n\r\n#response data\r\n {\r\n id: 0, \r\n ticker: 'NIFTY-1', \r\n segmentId: 2, \r\n time: 1293704493, \r\n price: 13958.6, \r\n qty: 75, \r\n volume: 1587975, \r\n oi: 9700275,\r\n kind: 'T'\r\n } \r\n```\r\n#### Trade snapshot data\r\n```python\r\n#callback to listen for trade snapshot, called during subcription process\r\n#listen to onTrade callback for continuouse stream data\r\napi.on_tradeSnapshot_update(on_tradeSnapshot)\r\ndef on_tradeSnapshot(msg):\r\n print(msg) # TradeSnapshot msg\r\n t = apidata_models.Trade(msg)\r\n print(t.ticker , t.oi) #likewise object can be called for id, kind, ticker, segment, price, qty, volume, oi\r\n\r\n#response data\r\n {\r\n id: 0, \r\n ticker: 'NIFTY-1', \r\n segmentId: 2, \r\n time: 1293704493, \r\n price: 13958.6, \r\n qty: 75, \r\n volume: 1587975, \r\n oi: 9700275,\r\n kind: 'T'\r\n } \r\n```\r\n#### Best\r\n```python \r\n#callback to listen for bid, ask and respective qty\r\napi.on_best_update(on_best)\r\ndef on_best(msg):\r\n print(msg) # Best msg\r\n b = apidata_models.Best(msg)\r\n print(b.ticker , b.bidPrice) #likewise object can be called for segmentId, kind, bidQty, askPrice, askQty\r\n\r\n#response data\r\n {\r\n ticker: 'NIFTY-1', \r\n segmentId: 2, \r\n kind: 'B', \r\n bidPrice: 13957.45, \r\n bidQty: 75, \r\n askPrice: 13958.8, \r\n askQty: 75, \r\n time: 1293704493\r\n } \r\n```\r\n\r\n### Recent change in Refs data\r\n```python\r\n#callback to listen for change in o, h, l, c, oi and avg data\r\napi.on_trade_ref(on_ref)\r\ndef on_ref(msg):\r\n print(msg) # Refs msg\r\n ref = apidata_models.Refs(msg)\r\n print(ref.price) #likewise object can be called for segmentId, kind, ticker\r\n\r\n#response data\r\n {\r\n kind: 'A',\r\n ticker: 'NIFTY-1',\r\n segmentId: 2,\r\n price: 11781.08984375\r\n }\r\n```\r\n### Refs snapshot data\r\n```python \r\n#callback to listen for o, h, l, c, oi and avg snapshot\r\napi.on_srefs_update(on_srefs)\r\ndef on_srefs(msg):\r\n print(msg) # Srefs msg\r\n sref = apidata_models.RefsSnapshot(msg)\r\n print(sref.high) #likewise object can be called for kind, ticker, segmentId, open, close, high, low, avg, oi, upperBand and lowerBand\r\n\r\n#response data\r\n {\r\n kind: 'V', \r\n ticker: 'NIFTY-1',\r\n segmentId: 2, \r\n open: 11749.650390625, \r\n close: 11681.5498046875,\r\n avg: 11780.8603515625,\r\n high: 11822,\r\n low: 11731.2001953125,\r\n oi: 10615950,\r\n upperBand: 0,\r\n lowerBand: 0\r\n\r\n }\r\n```\r\n### OptionGreeks data\r\n```python \r\n#callback to listen for optionGreek data\r\napi.on_greeks_update(on_greeks)\r\ndef on_greeks(msg):\r\n print(msg) # Option Greeks Data\r\n greeks = apidata_models.Greeks(msg)\r\n print(greeks.gamma) # likewise object can be called for kind, ticker, iv, delta, theta, vega, gamma, ivvwap, vanna, charm, speed, zomma, color, volga, veta, tgr, tv and dtr\r\n\r\n#response data\r\n {\r\n kind:'G',\r\n ticker:'NIFTY2220318500CE',\r\n charm:13.510149002075195,\r\n color:0.0010876863962039351,\r\n ivvwap:0.2657951712608337,\r\n speed:-0.25761404633522034,\r\n tgr:1437.1766357421875,\r\n theta:-3.690974235534668,\r\n tv:-28860.783203125,\r\n vega:1.935671329498291,\r\n veta:57653.11328125,\r\n volga:0.000020740208128700033,\r\n zomma:3.531916377141897e-7,\r\n iv:0.2650300860404968,\r\n gamma:0.00012788892490789294,\r\n dtr:-1.9068187475204468,\r\n delta:0.03707314282655716\r\n }\r\n```\r\n### OptionGreeks Snapshot data\r\n```python \r\n#callback to listen for optionGreek snap data\r\napi.on_greeks_update(on_greeks)\r\ndef on_greekSnapshot(msg):\r\n print(msg) # Option Greeks snap data\r\n greeks = apidata_models.Greeks(msg)\r\n print(greeks.gamma) # likewise object can be called for kind, ticker, iv, delta, theta, vega, gamma, ivvwap, vanna, charm, speed, zomma, color, volga, veta, tgr, tv and dtr\r\n\r\n#response data\r\n {\r\n kind:'G',\r\n ticker:'NIFTY2220318500CE',\r\n charm:13.510149002075195,\r\n color:0.0010876863962039351,\r\n ivvwap:0.2657951712608337,\r\n speed:-0.25761404633522034,\r\n tgr:1437.1766357421875,\r\n theta:-3.690974235534668,\r\n tv:-28860.783203125,\r\n vega:1.935671329498291,\r\n veta:57653.11328125,\r\n volga:0.000020740208128700033,\r\n zomma:3.531916377141897e-7,\r\n iv:0.2650300860404968,\r\n gamma:0.00012788892490789294,\r\n dtr:-1.9068187475204468,\r\n delta:0.03707314282655716\r\n }\r\n```\r\n\r\n\r\n# Callbacks for connection status\r\n#### api.on_connection_started(connection_started)\r\n\r\n#### api.on_connection_stopped(connection_stopped)\r\n```python\r\n# Fired when connection is successful\r\ndef connection_started():\r\n print(\"Connection started callback\")\r\n\r\n# Fired when the connection is closed after automatic retry or some issues in networking\r\n# Need to re-establish the connection manually\r\n\r\ndef connection_stopped():\r\n print(\"connection Stopped callback\")\r\n```\r\n\r\n# Live stream subscription\r\n#### Subscribe to receive updates of segments entitled to you\r\n```python\r\nneedSnapshot = False\r\nawait api.subscribeSegments(needSnapshot)\r\n# IMPORTANT NOTE:\r\n# If needSnapshot = True, then buffer the updates received on 'api.on_tradeSnapshot_update' and 'api.on_srefs_update' before processing. \r\n# Data transfer is huge and you may get disconnected from server in-case if you don't process the incoming updates as fast enough.\r\n# It's advised to buffer the data then process it once 'api.subscribeSegments' method returns.\r\n```\r\n#### Subscribe to receive ALL updates\r\n\r\n```python\r\n await api.subscribeAll('NIFTY-1')\r\n```\r\n#### Subscribe to receive TRADE updates\r\n\r\n```python\r\n await api.subscribeTrade(['NIFTY-1','BANKNIFTY-1','NIFTY 50'])\r\n```\r\n#### Subscribe to receive REFS and BEST updates\r\n```python\r\nawait api.subscribeBestAndRefs(['NIFTY-1','BANKNIFTY-1'])\r\n```\r\n#### Subscribe to receive Greeks updates\r\n```python\r\nawait api.subscribeGreeks(['NIFTY2220318500CE'])\r\n```\r\n#### Subscribe to receive Optionchain updates\r\n```python\r\n# params: spotName, Expiry Date\r\n# subscribe to full chain\r\nawait api.subscribeOptionChain('BANKNIFTY','20220901')\r\n# subscribe to range of strikes(CE, PE) considering current spot value(at time of subscribe) as the mid-point, essentially 10 strike(CE,PE) below mid-point and 10 strikes(CE, PE) above mid-point and total of 40 contracts subscribed for the below call.\r\nawait api.subscribeOptionChainRange('NIFTY','20220901',10)\r\n```\r\n# Unsubscribe live stream\r\n```python\r\n# unsubscribe single symbol\r\n await api.unsubscribeAll(['NIFTY-1'])\r\n# unsubscribe multiple symbol\r\n await api.unsubscribeAll(['NIFTY-1','BANKNIFTY-1'])\r\n```\r\n#### Unsubscribe Optionchain updates\r\n```python\r\nawait api.unsubscribeOptionChain('NIFTY','20220609')\r\n```\r\n#### Unsubscribe Greeks updates\r\n```python\r\nawait api.unsubscribeGreeks(['NIFTY2220318500CE'])\r\n```\r\n\r\n# History data - Eod\r\n```python\r\n# Continues data\r\n#params: ticker, startDate, endDate\r\nawait api.get_eod(\"NIFTY-1\", \"20200828\", \"20200901\")\r\n\r\n# Contract data\r\n#params: underlying ticker, startDate, endDate, contractExpiryDate\r\nawait api.get_eod_contract(\"NIFTY\", \"20200828\", \"20200901\", \"20201029\")\r\n\r\n#response data\r\n{\r\n td: '2020-08-28T00:00:00',\r\n op: 11630,\r\n hp: 11708,\r\n lp: 11617.05,\r\n cp: 11689.05,\r\n vol: 260625,\r\n oi: 488325\r\n}\r\n```\r\n# History data - Inraday\r\n#### Provides intra-eod bars with the time resolution in minutes (default:'5' mins) \r\n#### You can set minute resolution to '1', '5', '10' and so on. \r\n#### Custom minute resolution also supported like '3', '7' and so on.\r\n#### Passing CURRENT DATE as parameter in 'toDate' will respond the LIVE ticks aggregated upto the time it traded today. Last BAR of the current day may be incomplete. Current day tick aggregation response will always provide complete bar list from the beginning of day.\r\n```python\r\n# Continues data \r\n#params: ticker, startDate, endDate, resolution\r\nawait api.get_intra_eod(\"NIFTY-1\", \"20210603\", \"20210604\", \"5\")\r\n\r\n# Contract data\r\n#params: underlying ticker, startDate, endDate, contractExpiryDate\r\nawait api.get_intra_eod_contract(\"NIFTY\", \"20200828\", \"20200901\", \"20201029\", \"5\")\r\n\r\n#response data\r\n{\r\n td: '2020-08-28T09:15:00',\r\n op: 11630,\r\n hp: 11643.45,\r\n lp: 11630,\r\n cp: 11639.8,\r\n vol: 4575,\r\n oi: 440475\r\n}\r\n```\r\n# History data - Ticks\r\nProvides back log ticks from the date time specified till current live time, that is the ticks available till request hit the server.\r\n```python\r\n#params: ticker, fromDateTime\r\nawait api.get_back_ticks(\"BANKNIFTY-1\", \"20201016 15:00:00\")\r\n\r\n#response data\r\n{\r\n td: 2020-11-16T15:00:01.000Z,\r\n pr: 23600,\r\n vol: 125,\r\n oi: 1692375\r\n}\r\n```\r\n# Example\r\n``` Python\r\nimport asyncio\r\nimport time\r\n#import requests\r\nfrom pix_apidata import *\r\n\r\napi = apidata_lib.ApiData()\r\nevent_loop = asyncio.get_event_loop()\r\n\r\nasync def main():\r\n api.on_connection_started(connection_started)\r\n api.on_connection_stopped(connection_stopped)\r\n api.on_trade_update(on_trade)\r\n api.on_best_update(on_best)\r\n api.on_refs_update(on_refs)\r\n api.on_srefs_update(on_srefs)\r\n api.on_tradeSnapshot_update(on_tradeSnapshot)\r\n api.on_greeks_update(on_greeks)\r\n api.on_greekSnapshot_update(on_greekSnapshot)\r\n\r\n key = \"your-api-key\"\r\n host = \"apidata.accelpix.in\"\r\n scheme = \"http\"\r\n s = await api.initialize(key, host,scheme)\r\n print(s)\r\n\r\n his = await api.get_intra_eod(\"NIFTY-1\",\"20210603\", \"20210604\", \"5\")\r\n print(\"History : \",his)\r\n\r\n syms = ['NIFTY-1', 'BANKNIFTY-1']\r\n symsGreeks = [\"BANKNIFTY2290126500CE\"]\r\n await api.subscribeAll(syms)\r\n # await api.subscribeOptionChain('NIFTY','20220901')\r\n # await api.subscribeGreeks(symsGreeks)\r\n # await api.subscribeOptionChainRange('NIFTY','20220901',3)\r\n print(\"Subscribe Done\")\r\n #needSnapshot = False\r\n #await api.subscribeSegments(needSnapshot)\r\n #time.sleep(5)\r\n # await api.unsubscribeAll(['NIFTY-1'])\r\n # await api.unsubscribeGreeks(['BANKNIFTY2290126500CE'])\r\n # await api.unsubscribeOptionChain('NIFTY','20220901')\r\n\r\ndef on_trade(msg):\r\n trd = apidata_models.Trade(msg)\r\n print(\"Trade : \",msg) # or print(trd.volume) likewise object can be called for id, kind, ticker, segment, price, qty, oi\r\n\r\ndef on_best(msg):\r\n bst = apidata_models.Best(msg)\r\n print(\"Best : \",msg) # or print(bst.bidPrice) likewise object can be called for ticker, segmentId, kind, bidQty, askPrice, askQty\r\n\r\ndef on_refs(msg):\r\n ref = apidata_models.Refs(msg)\r\n print(\"Refs snapshot : \",msg) # or print(ref.price) likewise object can be called for segmentId, kind, ticker\r\n\r\ndef on_srefs(msg):\r\n sref = apidata_models.RefsSnapshot(msg)\r\n print(\"Refs update : \",msg) # or print(sref.high) likewise object can be called for kind, ticker, segmentId, open, close, low, avg, oi, lowerBand,upperBand\r\n\r\ndef on_tradeSnapshot(msg):\r\n trdSnap = apidata_models.Trade(msg)\r\n print(\"TradeSnap : \",msg) # or print(trdSnap.volume) likewise object can be called for id, kind, ticker, segment, price, qty, oi\r\n\r\ndef on_greeks(msg):\r\n greeks = apidata_models.Greeks(msg)\r\n print(\"OptionGreeks : \",msg) # or print(greeks.gamma) likewise object can be called for kind, ticker, iv, delta, theta, vega, gamma, ivvwap, vanna, charm, speed, zomma, color, volga, veta, tgr, tv and dtr\r\n\r\ndef on_greekSnapshot(msg):\r\n gr = apidata_models.Greeks(msg)\r\n print(msg) # or print(greeks.gamma) likewise object can be called for kind, ticker, iv, delta, theta, vega, gamma, ivvwap, vanna, charm, speed, zomma, color, volga, veta, tgr, tv and dtr\r\n\r\ndef connection_started():\r\n print(\"Connection started callback\")\r\n\r\ndef connection_stopped():\r\n print(\"Connection stopped callback\")\r\n \r\nevent_loop.create_task(main())\r\ntry:\r\n event_loop.run_forever()\r\nfinally:\r\n event_loop.close()\r\n```\r\n### Powered by ticAnalytics\u00ae\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python library to connect and stream the market data.",
"version": "1.3.5",
"project_urls": {
"Homepage": "https://github.com/pscoumar"
},
"split_keywords": [
"stock market",
" apidata",
" accelpix",
" ticanalytics"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4d8eff7b024fc80e01eadc35ffaa07fa079ddef432ab1723ae6d9ba7f6f4afa6",
"md5": "cf692a863174d3151c335f5064928044",
"sha256": "10bf91cca1023d2d5a09be9c2378bcbdf0dbbf63e342905172c1f1953cd4346f"
},
"downloads": -1,
"filename": "pix_apidata-1.3.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cf692a863174d3151c335f5064928044",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8589,
"upload_time": "2024-12-13T06:48:27",
"upload_time_iso_8601": "2024-12-13T06:48:27.896932Z",
"url": "https://files.pythonhosted.org/packages/4d/8e/ff7b024fc80e01eadc35ffaa07fa079ddef432ab1723ae6d9ba7f6f4afa6/pix_apidata-1.3.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7068d4cf1e5959993c2277c2385a40a0d6694b8a55a28eca44908173c6d02d8d",
"md5": "7982314444564008ec9d790b85b35175",
"sha256": "678f67a7f5437fe6d6f600210d1d2a23d3344fd078e67ce35cc2d643ebf58597"
},
"downloads": -1,
"filename": "pix_apidata-1.3.5.tar.gz",
"has_sig": false,
"md5_digest": "7982314444564008ec9d790b85b35175",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12291,
"upload_time": "2024-12-13T06:48:29",
"upload_time_iso_8601": "2024-12-13T06:48:29.213473Z",
"url": "https://files.pythonhosted.org/packages/70/68/d4cf1e5959993c2277c2385a40a0d6694b8a55a28eca44908173c6d02d8d/pix_apidata-1.3.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-13 06:48:29",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "pix-apidata"
}