Skip to main content

Hugging Face Hub

Required. All ML model binaries (.pkl and .onnx) are stored on Hugging Face Hub. The trading bot pulls the latest models at startup.

Setup

  1. Create a free account at huggingface.co
  2. Create a new model repository (private)
  3. Generate an access token with write permission at Settings → Access Tokens
  4. Add to your .env:
HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxx
HF_REPO_ID=yourname/novosky-models

Usage

# Pull latest models (run at startup / before trading)
python ml/hf_hub.py --pull

# Push after retrain
python ml/hf_hub.py --push

# Push with a tag (e.g. after a major retrain)
python ml/hf_hub.py --push --tag phase-16

# List available revisions
python ml/hf_hub.py --list
The push command uploads all .pkl and .onnx files from models/ plus the models/model_compat.json and models/risk_metadata.json metadata files.

What is stored

FileDescription
rf_signal.pklRandom Forest signal model (raw)
rf_signal_calibrated.pklCalibrated RF signal model
rf_signal.onnxONNX export of RF signal model
xgb_signal.pkl, _calibrated.pkl, .onnxXGBoost equivalents
lgb_signal.pkl, _calibrated.pkl, .onnxLightGBM signal equivalents
position_*.pklPosition model files
sltp_*.pklSL/TP model files
risk_*.pklRisk multiplier model files
model_compat.jsonFeature list hash + model paths — compatibility check
risk_metadata.jsonRisk model metadata: trained_at, val_mae, features

Supabase

Optional. Supabase stores trade logs, open position snapshots, and bot status. The website dashboard reads from Supabase for trade history display.

Setup

  1. Create a free project at supabase.com
  2. Run the schema migrations from supabase/migrations/
  3. Add to your .env:
SUPABASE_URL=https://xxxxxxxxxxxx.supabase.co
SUPABASE_KEY=your-service-role-key

Schema

-- Core tables (from supabase/migrations/)
trades          -- closed trade records with broker deal data
positions       -- open position snapshots
account_snapshots  -- periodic balance/equity snapshots
bot_status      -- heartbeat and current state

Data integrity rules

For cent accounts, always store raw MT5 values — do not convert USC to USD before writing.
  • Store closing_deal.profit as-is (e.g. 230.0 USC, not 2.30 USD)
  • For price-based profit estimates: use _usd_to_raw(price_diff × lot × contract_size) which multiplies by 100 for cent accounts
  • entry_at timestamps: always strip microseconds → datetime.now(UTC).replace(microsecond=0).isoformat()

Trade reconciliation

After every sync_fallback or estimation path, _reconcile_trade_bg(ticket, ...) fires in the background. It retries _get_deals_for_position() every 60 seconds for up to 4 hours, then overwrites Supabase with real broker deal data. VT Markets can delay closing deal history by hours for manual (mobile) closes. The reconciliation loop handles this automatically.

Telegram

Optional but strongly recommended. Telegram sends trade alerts, weekly optimize reports, and error notifications.

Setup

  1. Create a bot with @BotFather and copy the token
  2. Get your chat ID (send a message to your bot, then check https://api.telegram.org/bot<token>/getUpdates)
  3. Add to your .env:
TELEGRAM_BOT_TOKEN=7234567890:AABxxxxxxxxxxxxxxxxxxxxxxxx
TELEGRAM_CHAT_ID=123456789

Notification types

EventMessage type
Trade openedBUY/SELL signal, lot, entry price, SL/TP, confidence
Trade closedP&L, duration, exit reason (TP/SL/EXIT signal)
Weekly optimize — successNew score, improvement %, key config, pushed to HF
Weekly optimize — rollbackOld score retained, reason
Hard haltEquity drawdown % that triggered halt
MT5 connection errorAPI URL, error code

Telegram commands

The bot responds to commands sent from your chat:
/status   — current position, equity, today's P&L
/stats    — last 20 trades summary
/pause    — pause trading (next cycle will skip)
/resume   — resume trading
/halt     — trigger immediate hard halt
Commands are handled by trading/telegram_commands.py.

Service dependency summary

ServiceRequiredWithout it
MT5 REST APIYesBot cannot trade
Hugging Face HubYesCannot load models
SupabaseNoNo trade log, no website dashboard
TelegramNoNo alerts or reports