最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - How to correctly use icici breeze api? - Stack Overflow

programmeradmin4浏览0评论

I am fresher working on a project relating to icici breeze api and I am stuck for a long time now. Any help will be much appreciated.

from datetime import datetime
import hashlib
import http.client
import json
time_stamp = datetime.utcnow().isoformat()[:19] + '.000Z'
from selenium import webdriver

driver = webdriver.Chrome()
useragent = driver.execute_script("return navigator.userAgent")
driver.quit()

conn = http.client.HTTPSConnection("api.icicidirect")
payload = json.dumps({
    "stock_code": "CNXBAN",
    "exchange_code": "NFO",
    # "expiry_date": "2022-05-26T06:00:00.000Z",
    "product_type": "options",
    "right": "call"
})
secret_key = "XXXXX~xx`2Gzs01+8"
appkey = "XXXXX(x@xxx"
checksum = hashlib.sha256((time_stamp+payload+secret_key).encode("utf-8")).hexdigest()
headers = {
    'Content-Type': 'application/json',
    'X-Checksum': 'token '+checksum,
    'X-Timestamp': time_stamp,
    'X-AppKey': appkey,
    'X-SessionToken':  "QXXX=",
    'User-Agent': useragent
}
conn.request("GET", "/breezeapi/api/v1/quotes", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

when i execute this code I get this an invalid checkcsum error:

C:\Users\anubh\AppData\Local\Temp\ipykernel_8528\2218726139.py:5: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).   time_stamp = datetime.utcnow().isoformat()[:19] + '.000Z' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 {"Status":5,"Error":"Authentication Fail :: Invalid Checksum."} 

I have used another approach with same payload and header but there i get no data found error.

from breeze_connect import BreezeConnect
from datetime import datetime
breeze = BreezeConnect(api_key="97A2873969504H7(1371R78@620dA614")
import urllib
breeze.generate_session(api_secret="xx~jx7745W3`xx+8",
                        session_token="xxx")

breeze.ws_connect()
time_stamp = datetime.utcnow().isoformat()[:19] + '.000Z'
print(breeze.get_quotes(stock_code="CNXBAN",
                    exchange_code="NFO",
                    product_type="options",
                    expiry_date=time_stamp,
                    right="call"))

this is the output that i get:

{'Success': {'exg_trade_date': {'NSE': '14-Feb-2025', 'BSE': '14-Feb-2025', 'FNO': '13-Feb-2025', 'NDX': '13-Feb-2025'}, 'exg_status': {'NSE': 'X', 'BSE': 'X', 'FNO': 'Y', 'NDX': 'O'}, 'segments_allowed': {'Trading': 'Y', 'Equity': 'Y', 'Derivatives': 'Y', 'Currency': 'Y'}, 'idirect_userid': 'xx', 'idirect_user_name': 'xx   xx', 'idirect_ORD_TYP': 'N', 'idirect_lastlogin_time': '13-Feb-2025 16:29:01', 'mf_holding_mode_popup_flg': 'N', 'commodity_exchange_status': 'N', 'commodity_trade_date': '13-Feb-2025', 'commodity_allowed': 'X'}, 'Status': 200, 'Error': None} C:\Users\anubh\AppData\Local\Temp\ipykernel_8528\912988948.py:27: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).   time_stamp = datetime.utcnow().isoformat()[:19] + '.000Z'  {'Success': None, 'Status': 500, 'Error': 'No Data Found'} packet queue is empty, aborting
发布评论

评论列表(0)

  1. 暂无评论