# Shared Hosting Deployment Guide

This guide explains how to deploy the Crypto Algo Platform on a shared Linux hosting environment where you don't have root access or Docker, but you do have **Cron Jobs**.

## Prerequisites

1.  **PHP 8.2+**: Ensure your hosting provider supports PHP 8.2.
2.  **MySQL Database**: Create a database via your hosting control panel (cPanel, etc.).
3.  **Cron Jobs**: Ability to set up cron jobs (scheduled tasks).
4.  **SSH Access** (Optional but recommended): For running composer and git commands.

## Installation Steps

### 1. Upload Files
Upload the entire project folder to your server (e.g., `public_html/crypto-bot` or a private folder like `~/crypto-bot`).
*Recommended*: specificy a folder *outside* `public_html` for security, since this is a backend application.

### 2. Configure Environment
1.  Copy `.env.example` to `.env`.
2.  Edit `.env` with your database credentials and settings:
    ```ini
    DB_HOST=127.0.0.1
    DB_NAME=your_db_name
    DB_USER=your_db_user
    DB_PASS=your_db_password
    
    TRADING_ENABLED=true
    ```

### 3. Install Dependencies
If you have SSH access, run:
```bash
cd /path/to/crypto-bot
composer install --no-dev --optimize-autoloader
```
*If you don't have SSH*, run `composer install` locally on your machine and upload the `vendor/` folder.

### 4. Setup Database
Import the schema into your database.
1.  If you have migration scripts in `database/`, run them (or use `bin/migrate_schema.php` if available).
2.  Alternatively, import the raw SQL if provided.

## Running the Application (The "Cron" Method)

Since shared hosting kills long-running processes, we use a **Cron Entrypoint** script. This script acts as a "watchdog". You schedule it to run every minute. It checks if the bot processes are running; if not, it starts them.

### Setup Cron Job
Add the following line to your Cron configuration (cPanel > Cron Jobs):

```bash
* * * * * /usr/local/bin/php /path/to/crypto-bot/bin/cron-entrypoint.php > /dev/null 2>&1
```
*Note: The path to PHP (`/usr/local/bin/php`) varies by host. Check your hosting docs.*

### What does `cron-entrypoint.php` do?
1.  Checks if `market-data-runner.php` is running. If not, starts it.
2.  Checks if `trade-monitor-runner.php` is running. If not, starts it.
3.  Checks if `telegram-bot-runner.php` is running. If not, starts it.

**Important Note on Shared Hosting Limits**:
- **Process Killing**: Hostings often kill processes using too much CPU or running longer than 5 mins. The Cron script will simply restart them after they die. This might cause 1-minute gaps in market data.
- **WebSockets**: The generic Runners use loops. If your host blocks outbound ports or kills persistent connections efficiently, you might experience frequent disconnects.

## Logs
Check `storage/logs/` to see the output of your background processes.
- `market-data.log`
- `trade-monitor.log`
