import os
import time
import logging
import requests
import redis
from dash import Dash, html, dcc
from dash.dependencies import Input, Output
from optionchain_stream import OptionChain
# Configure logging
logging.basicConfig(filename='option_stream.log', level=logging.INFO)
# Redis configuration
REDIS_HOST = 'localhost'
REDIS_PORT = 6379
# Kite API credentials
API_KEY = os.getenv('KITE_API_KEY')
API_SECRET = os.getenv('KITE_API_SECRET')
ACCESS_TOKEN = os.getenv('KITE_ACCESS_TOKEN')
SYMBOL = 'NIFTY'
EXPIRY_DATE = '2024-10-10'
# Connect to Redis
try:
redis_client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
redis_client.ping()
print("Connected to Redis.")
except redis.ConnectionError as e:
print("Failed to connect to Redis. Make sure Redis server is running.")
exit(1)
# Create an OptionChain object
def create_option_stream():
try:
option_stream = OptionChain(
symbol=SYMBOL,
expiry=EXPIRY_DATE,
api_key=API_KEY,
October 9