You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been having issues with missing/delayed data. So I setup a simple script to fetch options prices from websocket and log them. The script is below.
Attached screenshot shows my console logs.
I have marked in red, quotes that are delayed. As you can see, some of them are significantly delayed like 3 to 4 minutes which is a rather long time. Ideally, at say 12.58.XX (XX being seconds), we should get quote for 12.57.00 candle for all subscribed instruments. Preferably within the first 5-10 seconds.
How can I mitigate this issue? I tried running it in parallel using threads but that doesn't improve it either.
For 5 minute quotes, data gets delayed by 4-6 minutes, so the data we get is sometimes 1 entire candle late.
Please advise, as this is causing errors in my signal generation which is messing up my trading activity.
# Initialize keys
api_key = "************************"
api_secret = "************************"
api_session = "************************"
# Import Libraries
from datetime import datetime
import time
from breeze_connect import BreezeConnect
import logging
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
# Setup API keys
breeze = BreezeConnect(api_key=api_key)
breeze.generate_session(api_secret=api_secret, session_token=api_session)
# Define strike ranges for calls and puts
call_strikes = list(range(23600, 24400, 50))
put_strikes = list(range(23600, 24400, 50))
# Callback to handle received ticks
def on_ticks(ticks):
# Log required fields: datetime, strike_price, right
logging.info(f"Datetime: {ticks.get('datetime')}, Strike Price: {ticks.get('strike_price')}, Right: {ticks.get('right_type')}")
# Main Function
if __name__ == "__main__":
print("Starting Execution \n")
# Connect to WebSocket
breeze.ws_connect()
print("Connected to WebSocket")
# Assign the on_ticks callback
breeze.on_ticks = on_ticks
# Create subscriptions for call and put options
subscriptions = []
for strike_price in call_strikes:
subscriptions.append({
"exchange_code": "NFO",
"stock_code": "NIFTY",
"product_type": "options",
"expiry_date": datetime.strftime(datetime.now(), '%Y-%m-%d'), # Replace with your expiry logic
"strike_price": str(strike_price),
"right": "call",
"interval": "1minute"
})
for strike_price in put_strikes:
subscriptions.append({
"exchange_code": "NFO",
"stock_code": "NIFTY",
"product_type": "options",
"expiry_date": datetime.strftime(datetime.now(), '%Y-%m-%d'), # Replace with your expiry logic
"strike_price": str(strike_price),
"right": "put",
"interval": "1minute"
})
# Subscribe to each feed
for sub in subscriptions:
answer = breeze.subscribe_feeds(
exchange_code="NFO",
stock_code="NIFTY",
product_type="options",
expiry_date="05-Dec-2024",
strike_price=sub["strike_price"],
right=sub["right"],
interval="1minute"
)
logging.info(f"Subscribed: {answer}")
# Keep the script running to receive data
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Execution stopped.")
The text was updated successfully, but these errors were encountered:
So shall I expect a response or spend my weekend exploring their API? I have been an ICICI customer since 2004 so not in a mood to shift unless forced to...
Hi Team,
I have been having issues with missing/delayed data. So I setup a simple script to fetch options prices from websocket and log them. The script is below.
Attached screenshot shows my console logs.
I have marked in red, quotes that are delayed. As you can see, some of them are significantly delayed like 3 to 4 minutes which is a rather long time. Ideally, at say 12.58.XX (XX being seconds), we should get quote for 12.57.00 candle for all subscribed instruments. Preferably within the first 5-10 seconds.
How can I mitigate this issue? I tried running it in parallel using threads but that doesn't improve it either.
For 5 minute quotes, data gets delayed by 4-6 minutes, so the data we get is sometimes 1 entire candle late.
Please advise, as this is causing errors in my signal generation which is messing up my trading activity.
The text was updated successfully, but these errors were encountered: