|
1 | | -# Daily Trading Bot |
| 1 | +# Trading Bot |
2 | 2 |
|
3 | | -This is a Python-based trading bot designed to run daily, ingest market data, generate signals, and execute trades (simulated or real). |
| 3 | +This repo now contains both parts of the system in one place: |
4 | 4 |
|
5 | | -## Setup |
| 5 | +1. The daily trading bot at the repo root |
| 6 | +2. The train-once quant model platform under `quant_platform/` |
6 | 7 |
|
7 | | -### Prerequisites |
8 | | -- Python 3.10+ |
9 | | -- `pip` |
| 8 | +## Repo Layout |
10 | 9 |
|
11 | | -### Installation |
12 | | -1. Clone the repository. |
13 | | -2. Install dependencies: |
14 | | - ```bash |
15 | | - pip install -r requirements.txt |
16 | | - ``` |
17 | | -3. Create a `.env` file with your API keys: |
18 | | - ```bash |
19 | | - cp .env.example .env |
20 | | - ``` |
21 | | -4. Open `.env` and paste your keys (do not commit `.env`). |
| 10 | +- Root: live trading bot, daily orchestration, SQLite state, email/reporting |
| 11 | +- `quant_platform/`: corpus building, one-time GPU training, frozen LoRA adapter workflow, backtesting/research platform |
22 | 12 |
|
23 | | -## Usage |
| 13 | +## Current Architecture |
24 | 14 |
|
25 | | -### Local Run |
26 | | -To run the daily job manually: |
| 15 | +``` |
| 16 | +trading_bot/ |
| 17 | +├── main.py # Daily core bot + AI bot orchestration |
| 18 | +├── llm_trader.py # AI trading branch using the trained model |
| 19 | +├── trained_model_client.py # Remote HTTP client for trained-model inference |
| 20 | +├── modal_trained_model_service.py |
| 21 | +├── backtesting/ # Existing research stack in the bot repo |
| 22 | +└── quant_platform/ # Merged train-once quant platform repo |
| 23 | +``` |
| 24 | + |
| 25 | +## Core vs AI |
| 26 | + |
| 27 | +- Core bot remains unchanged in principle: price ingestion, feature generation, OLS ranking, meta-learner, portfolio logic |
| 28 | +- AI trading bot is separate and now uses the trained quant model over HTTP |
| 29 | +- The AI path is batched and designed to call the Modal CPU endpoint, not a local model |
| 30 | + |
| 31 | +## Secrets |
| 32 | + |
| 33 | +### Still used |
| 34 | +- `NVIDIA_API_KEY`: news sentiment path |
| 35 | +- `TRAINED_MODEL_INFERENCE_URL`: deployed Modal CPU inference URL for the AI trading bot |
| 36 | +- `TRAINED_MODEL_API_KEY`: optional auth for the trained-model endpoint |
| 37 | +- `TWELVEDATA_API_KEYS`, `ALPHAVANTAGE_API_KEYS`: optional price providers |
| 38 | + |
| 39 | +### No longer used by the AI trading bot |
| 40 | +- `NVIDIA_REASONING_API_KEY` |
| 41 | + |
| 42 | +## Main Workflows |
| 43 | + |
| 44 | +- `.github/workflows/daily_trading_bot.yml` |
| 45 | + - Daily root bot workflow |
| 46 | + - Core + AI orchestration |
| 47 | +- `.github/workflows/ai_trading_smoke.yml` |
| 48 | + - AI-only smoke test against the trained model endpoint |
| 49 | + - Does not run the core strategy |
| 50 | + |
| 51 | +## AI-Only Smoke Test |
| 52 | + |
| 53 | +Manual: |
27 | 54 | ```bash |
| 55 | +python run_ai_trading_smoke.py |
| 56 | +``` |
| 57 | + |
| 58 | +GitHub Actions: |
| 59 | +- Actions -> **AI Trading Smoke** |
| 60 | +- This tests only the AI trading branch and the trained-model endpoint |
| 61 | + |
| 62 | +## Quant Platform |
| 63 | + |
| 64 | +The full train-once quant platform has been merged into: |
| 65 | + |
| 66 | +- [quant_platform/](./quant_platform) |
| 67 | + |
| 68 | +That subtree contains: |
| 69 | +- corpus builders |
| 70 | +- training scripts |
| 71 | +- backtest engine |
| 72 | +- inference/API scaffolding |
| 73 | +- configs, docs, and tests from the original train-once repo |
| 74 | + |
| 75 | +Start there if you want to inspect the model/training system rather than the daily bot. |
| 76 | + |
| 77 | +## Local Setup |
| 78 | + |
| 79 | +```bash |
| 80 | +pip install -r requirements.txt |
28 | 81 | python main.py daily_job |
29 | 82 | ``` |
30 | 83 |
|
31 | | -### Full Pipeline |
32 | | -To run the full pipeline (ingest, train, backtest): |
| 84 | +For AI-only testing: |
33 | 85 | ```bash |
34 | | -python main.py full |
| 86 | +python run_ai_trading_smoke.py |
35 | 87 | ``` |
36 | 88 |
|
37 | | -## API Keys (Step-by-Step) |
38 | | - |
39 | | -This repo is set up so secrets are **not** stored in git. A fresh `git clone` will **not** include your API keys. |
40 | | - |
41 | | -### A) Run Locally (Recommended) |
42 | | -1. Clone: |
43 | | - ```bash |
44 | | - git clone https://github.com/Rohan5commit/trading_bot.git |
45 | | - cd trading_bot |
46 | | - ``` |
47 | | -2. Create `.env`: |
48 | | - ```bash |
49 | | - cp .env.example .env |
50 | | - ``` |
51 | | -3. Open `.env` and paste your keys: |
52 | | - - In VS Code: `code .` then click `.env` and paste values. |
53 | | - - In Terminal: `nano .env` then paste values and save. |
54 | | -4. Required env vars for the current setup: |
55 | | - - `NVIDIA_API_KEY` (news/LLM sentiment) |
56 | | - - `NVIDIA_REASONING_API_KEY` (AI strategy trade selection) |
57 | | - - Email: `SMTP_SERVER`, `SMTP_PORT`, `SENDER_EMAIL`, `SENDER_PASSWORD`, `RECIPIENT_EMAIL` |
58 | | - - Optional (faster S&P500 ingestion): `TWELVEDATA_API_KEYS` (comma-separated) |
59 | | -5. Run: |
60 | | - ```bash |
61 | | - python3 main.py daily_job |
62 | | - ``` |
63 | | - |
64 | | -### B) Run In GitHub Actions (Cloud) |
65 | | -1. Go to your repo on GitHub. |
66 | | -2. `Settings` -> `Secrets and variables` -> `Actions`. |
67 | | -3. Click `New repository secret`. |
68 | | -4. Add secrets (names must match exactly): |
69 | | - - `NVIDIA_API_KEY` |
70 | | - - `NVIDIA_API_KEY_ID` (optional) |
71 | | - - `NVIDIA_REASONING_API_KEY` |
72 | | - - `NVIDIA_REASONING_API_KEY_ID` (optional) |
73 | | - - `TWELVEDATA_API_KEYS` (optional, comma-separated) |
74 | | - - Email secrets as used by your deployment (see your workflow / `send_email_report.py` configuration). |
75 | | - |
76 | | -## State Persistence (Important) |
77 | | -Positions and account state live in SQLite at `data/trading_bot.db`. |
78 | | -- GitHub Actions keeps this via cache for cloud runs. |
79 | | -- A new local clone starts "fresh" unless you restore a saved copy of `data/trading_bot.db`. |
80 | | - |
81 | | -## GitHub Actions Deployment |
82 | | - |
83 | | -This repository includes a GitHub Actions workflow (`.github/workflows/daily_trading_bot.yml`) that runs the bot daily at 9:30 AM EST (Mon-Fri). |
84 | | - |
85 | | -### Configuration |
86 | | -To execute successfully on GitHub Actions, you must configure the following **Repository Secrets** in your GitHub repository (Settings -> Secrets and variables -> Actions): |
87 | | - |
88 | | -| Secret Name | Description | |
89 | | -|---|---| |
90 | | -| `TWELVEDATA_API_KEYS` | Comma-separated API keys for TwelveData (if used). | |
91 | | -| `ALPHAVANTAGE_API_KEYS` | Comma-separated API keys for AlphaVantage (if used). | |
92 | | -| `MAILGUN_API_KEY` | API Key for Mailgun (for email reports). | |
93 | | -| `MAILGUN_DOMAIN` | Mailgun domain (e.g., `mg.yourdomain.com`). | |
94 | | -| `EMAIL_RECIPIENTS` | Comma-separated list of email addresses to receive reports. | |
95 | | -| `EMAIL_SENDER` | Email address to send from (e.g., `bot@yourdomain.com`). | |
96 | | -| `OPENAI_API_KEY` | OpenAI API Key (for LLM analysis). | |
97 | | - |
98 | | -### Workflows |
99 | | -- **Daily Trading Bot**: Triggers on schedule (Mon-Fri) and can be manually triggered via the "Run workflow" button in the Actions tab. |
| 89 | +## Notes |
| 90 | + |
| 91 | +- The AI bot is remote-only and expects the trained model to be served externally. |
| 92 | +- The current deployment target is Modal CPU. |
| 93 | +- The core bot and AI bot remain logically separate even though they now live in one combined repo. |
0 commit comments