Upgrade
Follow these steps to upgrade your OpenAlgo application:
Backup the Database
Navigate to your database folder and make a copy of the current database file for safekeeping.
Update the Application Code
Open your terminal and run the following command to pull the latest changes:
cd openalgo
git pull
Update the .env files
update your .env files from .sample.env (as some of the newer updates often has new enviromentatal variables. which is vital for the openalgo to function
cp .sample.env .env
and config the apikeys and apisecret as per the openalgo broker documentation
Install Dependencies
Install or update the required Python packages by running:
pip install -r requirements.txt
Run the Migration Script
Execute the migration script to add the feed_token
column to your database:
# Navigate to your OpenAlgo upgrade directory
cd upgrade
# Run the migration script
python add_feed_token.py
python add_user_id.py
# Get back to openalgo directory
cd..
# Run the OpenAlgo App
python app.py
The script will:
Check if the
feed_token
column already existsAdd the column if it doesn't exist
Log the results of the operation
Verify the Migration
After running the script, verify that the column was added successfully by:
Checking the script output for success messages
Logging into your OpenAlgo application and testing Angel broker authentication
Technical Notes
What is the Feed Token?
The feed token (data token) is provided by Angel Broking's API during authentication and is used for real-time market data operations. It is separate from the authentication token and has its own validity period.
Implementation Details
The upgrade adds:
A new
feed_token
column to theauth
table in the databaseStorage and retrieval mechanisms for the feed token
Integration of the feed token with market data operations
Modified Files
This upgrade modifies the following key files:
openalgo/broker/angel/api/auth_api.py
- To extract and return the feed token from the Angel authentication responseopenalgo/database/auth_db.py
- To add storage and retrieval functions for the feed tokenopenalgo/utils/auth_utils.py
- To handle the feed token in session management
Troubleshooting
"Unable to open database file" Error
If you encounter this error, check:
The database path in your
.env
file is correctThe directory exists and has proper permissions
You are running the script from the correct location
"feed_token column already exists" Message
This is not an error. It means the migration has already been applied to your database.
Authentication Issues After Upgrade
If you experience authentication issues:
Verify that all files have been properly updated
Log out and log back in to generate a new feed token
Check the application logs for specific error messages
Support
If you need assistance with the feed token upgrade, please:
Check the OpenAlgo documentation
Refer to the Angel broking API documentation for feed token details
File an issue on the OpenAlgo GitHub repository
Dependecies Check (Optional)
Ensure all installed dependencies are compatible with the new version:
• Use a virtual environment to avoid conflicts:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
Configure the Environment
Create a .env file from the provided .sample.env file. Update the following configurations in the .env file:
• Generate random values for APP_KEY and API_KEY_PEPPER using: • Update the following parameters:
• BROKER_API_KEY
• BROKER_API_SECRET
• REDIRECT_URL
• Verify and adjust other configurations as needed.
Sample .env template
# Broker Configuration
BROKER_API_KEY = 'YOUR_BROKER_API_KEY'
BROKER_API_SECRET = 'YOUR_BROKER_API_SECRET'
REDIRECT_URL = 'http://127.0.0.1:5000/<broker>/callback' # Change if different
# Valid Brokers Configuration
VALID_BROKERS = 'fivepaisa,aliceblue,angel,dhan,fyers,icici,kotak,shoonya,upstox,zebu,zerodha'
# Security Configuration
# IMPORTANT: Generate new random values for both keys during setup!
# OpenAlgo Application Key
APP_KEY = 'GENERATE_A_RANDOM_APP_KEY'
# Security Pepper - Used for hashing/encryption of sensitive data
# This is used for:
# 1. API key hashing
# 2. User password hashing
# 3. Broker auth token encryption
API_KEY_PEPPER = 'GENERATE_A_RANDOM_PEPPER_KEY'
# OpenAlgo Database Configuration
DATABASE_URL = 'sqlite:///db/openalgo.db'
# OpenAlgo Ngrok Configuration
NGROK_ALLOW = 'FALSE'
# OpenAlgo Hosted Server (Custom Domain Name) or Ngrok Domain Configuration
# Change to your custom domain or Ngrok domain
HOST_SERVER = 'http://127.0.0.1:5000'
# OpenAlgo Flask App Host and Port Configuration
# For 0.0.0.0 (accessible from other devices on the network)
# Flask Environment - development or production
FLASK_HOST_IP='127.0.0.1'
FLASK_PORT='5000'
FLASK_DEBUG='False'
FLASK_ENV='development'
# OpenAlgo Flask App Version Management
FLASK_APP_VERSION='1.0.0.14'
# OpenAlgo Rate Limit Settings
LOGIN_RATE_LIMIT_MIN = "5 per minute"
LOGIN_RATE_LIMIT_HOUR = "25 per hour"
API_RATE_LIMIT="10 per second"
# OpenAlgo API Configuration
# Required to give 0.5 second to 1 second delay between multi-legged option strategies
# Single legged orders are not affected by this setting.
SMART_ORDER_DELAY = '0.5'
# Session Expiry Time (24-hour format, IST)
# All user sessions will automatically expire at this time daily
SESSION_EXPIRY_TIME = '03:00'
Last updated