Spaces:
Running
Running
| title: Gotti Signal Gen | |
| emoji: 🏢 | |
| colorFrom: green | |
| colorTo: gray | |
| sdk: docker | |
| pinned: false | |
| # Stock Alchemist Signal Generator | |
| A Dockerized FastAPI application that generates stock trading signals using Ollama (LLaMA 3.1) and performs scheduled fundamental analysis. Designed to run on Hugging Face Spaces. | |
| ## Features | |
| - **Daily Signal Generation**: Prompts a local LLaMA 3.1 model to analyze stocks and generates trading signals. | |
| - **Weekly Analysis**: Runs a comprehensive fundamental analysis script every Saturday. | |
| - **Persistent Storage**: Stores results in a TiDB/MySQL database. | |
| - **Automated Scheduling**: Uses GitHub Actions to trigger daily and weekly tasks. | |
| ## Setup Instructions | |
| ### 1. Hugging Face Space Setup | |
| 1. Create a new Space on [Hugging Face](https://huggingface.co/spaces). | |
| 2. Select **Docker** as the SDK. | |
| 3. Choose "Blank" or just point it to your repository. | |
| ### 2. Environment Variables | |
| In your Hugging Face Space "Settings" -> "Variables and secrets", add the following **Secret** variables: | |
| - `API_SECRET`: A strong secret key to protect your endpoints. | |
| - `DB_HOST`: Your TiDB/MySQL host. | |
| - `DB_PORT`: Your TiDB/MySQL port (e.g., 4000 for TiDB, 3306 for MySQL). | |
| - `DB_USERNAME`: Database username. | |
| - `DB_PASSWORD`: Database password. | |
| - `DB_DATABASE`: Database name (e.g., `gotti`). | |
| - `DB_SSL_CA`: (Optional) Path to SSL CA certificate if needed (relative to repository root). | |
| ### 3. GitHub Actions Setup | |
| To enable the scheduler: | |
| 1. Go to your GitHub repository -> **Settings** -> **Secrets and variables** -> **Actions**. | |
| 2. Add the following **Repository secrets**: | |
| - `HF_SPACE_URL`: The URL of your Hugging Face Space (e.g., `https://username-space-name.hf.space`). | |
| - `API_SECRET`: The same secret you set in Hugging Face. | |
| ### 4. Database Initialization | |
| The application handles table creation automatically in `src/db/local_database.py`. Ensure your database user has `CREATE TABLE` permissions. | |
| ## Local Development | |
| ### Prerequisites | |
| - Docker | |
| - Python 3.10+ | |
| - Ollama (running locally if testing outside Docker) | |
| ### Running with Docker | |
| ```bash | |
| # Build the image | |
| docker build -t stock-alchemist . | |
| # Run the container | |
| # Note: You need to pass env vars. For local testing, you might want to use --env-file | |
| docker run -p 7860:7860 \ | |
| -e API_SECRET=test_secret \ | |
| -e DB_HOST=host.docker.internal \ | |
| -e DB_USERNAME=root \ | |
| -e DB_PASSWORD=yourpassword \ | |
| stock-alchemist | |
| ``` | |
| ### API Endpoints | |
| - `POST /generate-signal`: Trigger signal generation. Headers: `X-API-Secret: <your_secret>` (or `API_SECRET` in local dev). *Note: The code uses `API_SECRET` env var validation.* | |
| - `POST /saturday-analysis`: Trigger weekly analysis. | |
| - `GET /health`: Health check and system vitals. | |
| ## Project Structure | |
| - `Dockerfile` & `entrypoint.sh`: System configuration. | |
| - `src/main.py`: FastAPI application entry point. | |
| - `src/db/`: Database interaction logic. | |
| - `.github/workflows/scheduler.yml`: Automated scheduler. | |