This script serves as a webhook for an Option Alpha trading bot. It uses OpenAI's GPT API to analyze major world events and determine if market conditions are favorable for trading. Designed for use with an iron condor trading strategy, the script triggers either a "Trade" or "No Trade" action based on the predicted market stability, pausing trades if volatility is expected.
- World Event Analysis: Queries OpenAI’s GPT-4 model for recent significant world events and assesses their potential impact on the S&P 500 (SPX).
- Automated Trade Control: Decides to either enable or pause trading based on potential market volatility.
- Secure API Key and URL Handling: Retrieves the OpenAI API key and Option Alpha webhook URLs from secure files stored outside the codebase.
- Python 3.7 or later
- Required Python packages:
Flask
(for the web server)requests
(for API requests)
- Access to an OpenAI API key with GPT-4 model access
- Access to your Option Alpha webhook URLs for trade management
-
Clone the Repository:
git clone https://github.com/Nathan-Strodtbeck/GPT4_TradeIndicator.git cd option_alpha_webhook
-
Install Required Packages:
pip install -r requirements.txt
-
Set Up API Key and Webhook URLs:
-
Create a secure directory to store your secrets:
sudo mkdir -p /etc/secrets sudo chmod 700 /etc/secrets
-
Save the OpenAI API Key:
- Create a file
/etc/secrets/IndicatorKey.txt
and paste your API key into it. - Ensure that the file has restricted permissions:
echo "your_openai_api_key_here" | sudo tee /etc/secrets/IndicatorKey.txt > /dev/null sudo chmod 600 /etc/secrets/IndicatorKey.txt
- Create a file
-
Save the Option Alpha Webhook URLs:
- Create a file
/etc/secrets/WebhookURLs.txt
with the following content:TRADE_URL=https://app.optionalpha.com/hook/your_trade_url_here NO_TRADE_URL=https://app.optionalpha.com/hook/your_no_trade_url_here
- Set the file permissions:
sudo chmod 600 /etc/secrets/WebhookURLs.txt
Important: Replace
your_trade_url_here
andyour_no_trade_url_here
with your actual Option Alpha webhook URLs. - Create a file
-
-
Verify File Permissions:
- Ensure that both
/etc/secrets/IndicatorKey.txt
and/etc/secrets/WebhookURLs.txt
are only readable by the application (permissions set to600
).
- Ensure that both
-
Run the Web Server:
python3 option_alpha_webhook.py
This starts a Flask web server on port 5000.
-
Trigger the Webhook:
- You can set up a cron job or external scheduler to make a request to
http://yourserver:5000/option_alpha_trigger
every 15 minutes or at another desired interval.
- You can set up a cron job or external scheduler to make a request to
-
Sample Cron Job (for Linux):
- To trigger the webhook every 15 minutes, add the following to your crontab:
*/15 * * * * curl -X POST http://localhost:5000/option_alpha_trigger
- To trigger the webhook every 15 minutes, add the following to your crontab:
- World Events Query: The webhook queries GPT-4 with a prompt to summarize major world events from the past 24 hours.
- Impact Analysis: Based on these events, GPT is asked if the SPX is likely to experience volatility exceeding 1.5 basis points.
- Trade Decision:
- If GPT predicts stability, the script triggers the Trade URL to enable trading.
- If volatility is expected, it triggers the No Trade URL to pause trading.
This script retrieves sensitive information (OpenAI API key and webhook URLs) from secure files stored outside the codebase:
- OpenAI API Key: Stored in
/etc/secrets/IndicatorKey.txt
. - Webhook URLs: Stored in
/etc/secrets/WebhookURLs.txt
, withTRADE_URL
andNO_TRADE_URL
as key-value pairs.
Both files should have restrictive permissions (chmod 600
) to ensure that only the application can read them.
/etc/secrets/
├── IndicatorKey.txt # Contains the OpenAI API key
└── WebhookURLs.txt # Contains TRADE_URL and NO_TRADE_URL
List of required packages (also in requirements.txt
):
Flask
requests
Install dependencies with:
pip install -r requirements.txt
- API Key Not Found: Ensure
/etc/secrets/IndicatorKey.txt
exists and contains only the API key. - Webhook URLs Not Found: Ensure
/etc/secrets/WebhookURLs.txt
exists and containsTRADE_URL
andNO_TRADE_URL
. - Permission Errors: Verify that
/etc/secrets/IndicatorKey.txt
and/etc/secrets/WebhookURLs.txt
have restrictive permissions (chmod 600
).
Feel free to submit issues or pull requests if you encounter bugs or have feature suggestions.
This project is licensed under the MIT License. See the LICENSE
file for details.