# AST Trading Decision Engine

Private FastAPI service for deterministic signals. It never receives client balances and cannot execute trades.

1. Create a PostgreSQL database/user and set `TRADING_AI_DATABASE_URL`.
2. Set the same strong `TRADING_AI_SHARED_SECRET` in this service, Laravel, and the quote worker.
3. Install `requirements.txt`, then run `uvicorn app.main:app --host 127.0.0.1 --port 8091` from this directory.
4. Keep `TRADING_AI_ENABLED=false` and `TRADING_AI_AUTOMATIC_EXECUTION=false` until PostgreSQL is initialized, at least 210 closed candles exist, and sandbox approval is complete.

The service stores one-minute Twelve Data ticks and resamples them into closed 15m, 1h, and 4h candles. `pytest` verifies deterministic features, LONG/SHORT/NO_TRADE behavior, and UTC resampling.
## Private deployment

Copy the required values into an environment file outside source control, then run `docker compose up -d --build`. The engine binds only to `127.0.0.1:8091`; PostgreSQL is not exposed. Use the same randomly generated `TRADING_AI_SHARED_SECRET` in Laravel and this service.

Keep `TRADING_AI_ENABLED=false` and `TRADING_AI_AUTOMATIC_EXECUTION=false` during shadow evaluation. After enabling symbol analysis in CRM, run `php artisan trading-ai:backfill` once. Only after reviewing backtests and shadow reconciliation should both flags be enabled; the database global switch, sandbox mode, Admin approval, client consent, and per-client/per-symbol switches must also all permit an order.

The existing Twelve Data WebSocket worker forwards ticks to this service, so no second provider WebSocket connection is opened.
