Step-by-Step Process to Set Up Redis with Python and Zerodha API
Step-by-Step Process to Set Up Redis with Python and Zerodha API
Since you’ve already downloaded Redis for Windows, follow these steps
to set it up:
○
3. This will start the Redis server. You should see logs indicating that
Redis is running.
4. Test Redis:
○ In the same Command Prompt window, open another
command prompt (you can keep the Redis server running in
one window).
Type:
bash
Copy code
redis-cli.exe
This will open the Redis command-line interface. To test Redis, type the
following command:
bash
Copy code
ping
○
○ Redis should respond with PONG, indicating that it’s working.
Step-by-Step Process:
1. Install Python:
○ If you don’t have Python installed, download it from python.org.
Install Required Libraries: Open a command prompt or terminal, and run the following
commands to install the necessary libraries:
2.
https://github.com/tahseenjamal/kite_candles.git
Step 4: Configure Zerodha API in the Code
Step 7: Modify the Script to Stream Data and Update Google Sheets
1. WebSocket Streaming:
○ Modify the code (or use the kite_candles repository) to subscribe to the
tokens you want to track (for example, Nifty options or stocks).
2. Process Data:
○ In the WebSocket on_ticks function (which handles incoming data),
process and store the real-time data for each token.
○ Format the data (e.g., latest price or candlestick data).
3. Update Google Sheets:
○ Modify the code to update Google Sheets in real-time.
○ Use the update_sheet() function (mentioned earlier) to push data to
Google Sheets.
○ You can update Google Sheets every minute or with each new WebSocket
tick, depending on your preference.
Step 8: Run the Script Locally
● Keep an eye on the terminal or console to ensure that the script is running properly
and that data is updating in Google Sheets.
Set up Zerodha API: Get your API key, secret, and access token.
Install Python and dependencies: Install necessary libraries on your local machine.
Set up Google Sheets API: Create a Google Cloud project and authenticate access.
Update the script: Modify the script to process the data and send updates to Google
Sheets.
Run the script: Keep the script running on your machine to stream data and update
Google Sheets.
Below is cloud
Google does not have a direct service or API specifically designed to provide live options
data like the one you're asking for (live 1-minute data of ATM and +/- 5 strikes for Nifty
options). However, you can use Google Cloud's serverless offerings (such as Cloud
Functions) in combination with external data providers, like Zerodha (or another broker that
offers live options data), to fetch and process the live data.
Here’s how you can set up a solution using Google Cloud to get live options data for Nifty
at 1-minute intervals for ATM and +/- 5 strikes using Zerodha's WebSocket API:
○ Use Google Cloud Functions to process the data fetched from the WebSocket
and append it to a Google Sheet or store it in a Cloud Database like
Firestore or BigQuery.
3. Google Sheets API:
○ If you want to store the data in Google Sheets, use the Google Sheets API to
automatically append the live data to a sheet.
1. Zerodha Kite WebSocket API provides real-time market data, including options
data.
○ First, you need to get API keys from Zerodha (if you haven’t already).
○ Then, connect to the WebSocket API using Zerodha's token for Nifty
options.
○ Fetch live market data for ATM and +/- 5 strikes for Nifty options.
1. ATM Calculation:
○ The ATM option strike is the one closest to the current market price of Nifty.
○ For example, if Nifty is at 18,000, the ATM strike could be 18,000.
2. Find +/- 5 Strikes:
○ You can calculate the strikes surrounding the ATM option using a simple
formula. If ATM is 18,000, the surrounding strikes could be 17,950, 18,050,
17,900, 18,100, etc.
3. Monitor Data for These Strikes:
○ After calculating the ATM and surrounding strikes, subscribe to these strike
prices using the Zerodha WebSocket API.
○ The WebSocket will send data about the Nifty options you’ve subscribed to,
including live prices, volume, and other market data.
○ If you don’t have a Google Cloud Project, create one via the Google Cloud
Console.
2. Enable APIs:
○ Create a Service Account to authenticate with the Google Sheets API and
give it appropriate permissions (like “Editor”).
○ Share the Google Sheet with the service account email address.
4. Create a Google Cloud Function:
Step 4: Use WebSocket to Fetch Data and Trigger Google Cloud Functions
○ Parse the incoming data to get relevant details such as price, open interest,
volume, etc.
○ Aggregate this data into a format that can be easily appended to your Google
Sheet.
3. Publish Data to Pub/Sub (Optional for Scaling):
○If you want to make the solution more robust and scalable, you can push
each update from the WebSocket into a Google Cloud Pub/Sub topic.
○ Google Cloud Functions can subscribe to this Pub/Sub topic and process
incoming data for appending to the Google Sheet.
4. Append Data to Google Sheets:
○ Using the Google Sheets API, the Cloud Function will automatically append
the processed data into your Google Sheet. This could include columns like:
■ Timestamp
■ Option Strike Price
■ Option Type (Call/Put)
■ Last Traded Price
■ Volume
■ Open Interest
● The Google Sheets API will handle the actual process of adding the real-time
market data into the Google Sheet.
● The structure of your Google Sheet might look something like this:
● Every minute, data for the ATM and +/- 5 strikes will be updated in the sheet.
Although Google doesn’t directly provide live options data, combining Zerodha's WebSocket
API with Google Cloud's serverless architecture provides a scalable and cost-effective
solution. You can monitor the live options data for ATM and surrounding strikes for Nifty
on a real-time basis.
To create a pipeline that fetches real-time options data from Zerodha's WebSocket API,
processes and stores it in a Google Sheet for monitoring, and optionally integrates Pub/Sub
and Cloud Scheduler for advanced task management.
Project Flow
Technology Stack