POST /ch/api/order accepts {api_key, member_id, symbol, side, quantity, price}
for programmatic order placement by external services like Soci agents.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Per-member AI model switching: right-click Type badge to change LLM/NN1/NN2
Replace global strategy system with per-member assignment map.
Default: USR01-04 LLM, USR05-07 NN1, USR08-10 NN2.
Right-click any member's Type badge in the leaderboard to change
their individual AI model. Human members (logged in) show Human
badge and skip the context menu.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add runtime NN model switching: LLM, NN1 (Adilbai), NN2 (RayMelius)
Support dual NN model slots in ch_rl_trader with lazy loading per slot.
Six strategies: hybrid (USR01-04 LLM, USR05-07 NN1, USR08-10 NN2),
hybrid-nn1, hybrid-nn2, nn1, nn2, llm. Right-click context menu and
badges updated for NN1/NN2 distinction.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix HF Spaces: create /app/data dir for matcher.db after shared_data merge
The old COPY shared_data/ lines implicitly created /app/data/. After
merging into shared/data, the matcher crashed on startup because
/app/data/ no longer existed for matcher.db.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Seed dashboard price chart with real OHLCV history from Yahoo Finance
- Script: --seed-chart flag writes OHLCV candles into dashboard_history.db
- Dashboard: auto-seeds from ohlcv/*.json on first run if DB is empty
- Dashboard: /history/symbols endpoint for pre-populating chart dropdown
- Frontend: loads available symbols on page load for pre-session chart display
- Fix HISTORY_DB default path after shared_data -> shared/data merge
- 1W shows ~5 daily candles, 1M shows ~20 daily candles with real prices
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add real ATHEX/NYSE/Euronext prices, OHLCV data for RL agent, merge shared_data into shared/data
- Type column shows NN (green) or LLM (purple) per member instead of generic AI
- AI decision history badges: RL source shown as NN
- Right-click leaderboard table opens context menu to switch strategy
(hybrid/rl/llm) at runtime via POST /ch/api/strategy
- Current strategy highlighted with checkmark in context menu
- Leaderboard auto-refreshes after strategy switch
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previous push was fully cached by HF Spaces. Pinning explicit versions
(numpy, pandas, scikit-learn, stable-baselines3, huggingface_hub) changes
the RUN command text, which invalidates the Docker layer cache.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Force Docker rebuild on HF Spaces, add version stamp to startup log
ARG PIP_CACHE_BUST invalidates pip layer cache. Entrypoint now prints
StockEx version at startup so deploys can be verified from container logs.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- README rewritten with full Clearing House, RL agent, and MDF regime docs
- CH_AI_STRATEGY defaults to hybrid, switchable via POST /ch/api/strategy
- Source label CLEARINGHOUSE → CLRH
- MDF snapshots include embedded technical indicators
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Integrate Adilbai/stock-trading-rl-agent PPO model as alternative CH
trading strategy (new ch_rl_trader.py)
- CH_AI_STRATEGY: llm/rl/hybrid (default hybrid, dynamically switchable
via POST /ch/api/strategy)
- MDF now uses regime-driven price dynamics (trending/mean-reverting/
volatile/calm) producing meaningful SMA, EMA, MACD, RSI, Bollinger
Band signals embedded in snapshots
- Rename source CLEARINGHOUSE → CLRH in order messages
- Add stable-baselines3, pandas, scikit-learn, huggingface_hub to Docker
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix MDF order book depth and CH AI reference price fallback
MDF now places 3 levels of resting bids and asks per symbol each cycle,
ensuring order books always have liquidity. CH AI trader falls back to
securities.txt reference prices when books are empty. CH daily obligation
raised to 20.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use Groq on HF Spaces, prefer fine-tuned Ollama model locally
- Notebook: merge LoRA adapter into base model on CPU and push complete
weights so stockex-ch-trader works via HF Inference Router API
- CH AI Trader: revert default HF_MODEL to RayMelius/stockex-ch-trader
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add script to convert fine-tuned adapter to Ollama GGUF
scripts/convert_to_ollama.py:
- Downloads base Qwen2.5-7B + LoRA adapter from HF Hub
- Merges adapter into base model (CPU, ~16GB RAM)
- Converts to GGUF via llama.cpp (Q4_K_M quantization)
- Creates Ollama model with system prompt and parameters
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix CH AI trader: use real LLM model and balance BUY/SELL fallback
- Default HF model changed from LoRA adapter (stockex-ch-trader, not
servable via HF Router API) to Qwen/Qwen2.5-7B-Instruct
- New env var CH_HF_MODEL for CH-specific model override
- Rebalanced fallback logic: SELL weight increases as holdings grow
(was always BUY when holdings < 30% of net worth)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Skip merge_and_unload which causes peft/accelerate TypeError on T4
- Push LoRA adapter + tokenizer directly via HfApi.upload_folder
- Update inference test to load adapter with PeftModel.from_pretrained
- Remove redundant push cell
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add AI reasoning history to CH member detail panel
- New ch_ai_decisions table stores LLM responses and parsed orders
- AI trader logs every decision: LLM response, fallback, invalid parse
- Member detail API returns last 10 AI decisions
- Detail panel shows AI Reasoning section with:
- LLM/Fallback/Invalid badges
- Parsed order (side, qty, symbol, price)
- Raw LLM response in scrollable monospace box
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix training cell hanging: remove load_best_model_at_end
- Removed load_best_model_at_end=True which caused the trainer to hang
trying to reload the best checkpoint after training (OOM on T4)
- Save adapter immediately after training completes in the same cell
- Removed redundant save_pretrained from the merge cell
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix duplicate FIX orders and lowercase side field
Two bugs found:
1. FIX UI client was publishing orders to Kafka directly AND via FIX
protocol to OEG (which also publishes to Kafka) = duplicate orders.
Removed the direct Kafka publish from FIX UI client.
2. FIX OEG used "type": "buy"/"sell" instead of "side": "BUY"/"SELL",
inconsistent with the rest of the system.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Click any row on /ch/ to see a slide-out panel with:
- Capital, holdings value, total value, P&L stats
- Full holdings table with current prices and unrealized P&L
- Last 20 trades with time, symbol, side, qty, price, value
- New API endpoint: GET /ch/api/member/<member_id>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix AI Analyst: use Qwen2.5-7B as default HF model
RayMelius/stockex-analyst is not hosted on any HF inference provider,
causing HTTP 400 errors. Fall back to Qwen/Qwen2.5-7B-Instruct.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Increase post-order reload from 1.5s to 4s to allow Kafka round-trip
(order → matcher → trade → CH consumer → DB) to complete
- Fix auto-refresh: was fetching data but not updating the page;
now reloads every 10s so trades are reflected promptly
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix AI Analyst duplicate output and CH trade attribution
- Dashboard: remove direct SSE broadcast from _generate_and_broadcast(),
let Kafka consumer handle it (was causing every insight to appear twice)
- CH trade consumer: match matcher's field names (buy_id/sell_id) instead
of buy_order_id/sell_order_id, so trades are actually attributed to members
- Notebook: support both Kaggle (dataset) and Colab (Drive) checkpoints,
set SAVE_STEPS=10
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update fine-tune notebook securities to real StockEx symbols
Replace hardcoded OPAP/MYTIL/ADMIE/etc. with actual StockEx securities
(ALPHA, PEIR, EXAE, QUEST, NBG, EUROB, AEG, INTKA, AAAK, ATTIK) and
current market prices for Colab training dataset generation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Mounts Google Drive; checkpoints saved to MyDrive/stockex-ch-checkpoints
- Auto-detects latest checkpoint and resumes with resume_from_checkpoint
- CheckpointSyncCallback: on every save → copies to Drive + pushes adapter to HF Hub
- save_total_limit=3 to keep local disk usage bounded
- Falls back gracefully if Drive not available
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix SFTConfig: move max_seq_length to tokenizer.model_max_length
api-inference.huggingface.co is deprecated (HTTP 410).
All three services (ai_analyst, ch_ai_trader, dashboard) now
route every model through router.huggingface.co.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix notebook for T4/free tier: auto GPU detection + bitsandbytes fix
- notebooks/ch_trader_finetune.ipynb: QLoRA fine-tunes Qwen2.5-7B-Instruct
on 2500 synthetic clearing house trading scenarios (Colab A100-ready)
- Generates diverse examples: varied capital, holdings, obligation levels
- Trains with SFTTrainer + chat template formatting, merges and pushes
the model to RayMelius/stockex-ch-trader on HuggingFace Hub
- ch_ai_trader.py + docker-compose: default HF_MODEL updated to
RayMelius/stockex-ch-trader (override via HF_MODEL env var)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use RayMelius/stockex-analyst as default LLM for CH AI trader
Matches the model already used by the AI Analyst service.
A CH-specific fine-tuned model can replace it later via HF_MODEL env var.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add navigation links between Dashboard and Clearing House
- Dashboard header: green "Clearing House" button linking to /ch/
- Clearing House nav: "← Main Dashboard" link back to /
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add clearing house simulation with 10 members (USR01-USR10)
- New clearing_house/ Flask service (port 5004) with dedicated dark-themed portal
- SQLite persistence: member capital, holdings, daily trade counters, settlements
- Members start with €100,000; must trade ≥10 securities per trading day
- Password = member ID (e.g. USR01 logs in with password USR01)
- Real users log in to trade manually; AI (LLM via Groq→HF→Ollama) simulates unoccupied members
- Trade attribution via Kafka trades consumer — detects USRxx- cl_ord_id prefix
- EOD settlement triggered by dashboard session end; calculates unrealized P&L
- Leaderboard at /ch/ with real-time auto-refresh and Human/AI badges
- Member portfolio view: holdings, order entry, trade history, settlement history
- Integrated into nginx (/ch/), entrypoint.sh, docker-compose, and HF Dockerfile
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fix HF routing: use router for third-party models, not model-specific endpoint
Only RayMelius/ finetuned models need the direct inference endpoint.
All other org/model format models (e.g. mistralai/Mistral-7B-Instruct-v0.3)
must go through router.huggingface.co which supports chat completions for them.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add new securities and use real prices in FIX UI order entry
- securities.txt: add EUROB, AEG, INTKA, AAAK, ATTIK to existing symbols
- fix-ui-client: load securities as {symbol: price} dict so prices flow through
- index.html: auto-populate price field from current security price on symbol change
- oeg_simulator: read symbols and prices from securities.txt instead of hardcoded FOO/AAA/BBB at ~100
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix HF inference URL routing for org/model format models
The condition '/ in m.split(\"/\")[0]' was always False (split removes
the slash), so only RayMelius/ models used the direct inference API —
all other org/model names (Qwen/, meta-llama/, etc.) hit the router
and got 400 'not supported by any provider'.
Fix: use direct inference API for any model containing a slash.
Also: replace Qwen/Qwen2.5-7B-Instruct-1M with Qwen/Qwen2.5-7B-Instruct
in the HF model list (-1M variant not available on inference API).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Restore SYSTEM_PROMPT and finetuned model default for AI Analyst
- HF_MODEL default: RayMelius/stockex-analyst (our Round 2 finetuned model)
- Add SYSTEM_PROMPT for correct finetuned model behaviour
- _try_hf: use direct inference API for RayMelius/ models + system prompt
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add dynamic LLM provider/model selection to AI Analyst
- ai_analyst: add Groq support, _active_provider/_active_model globals,
refactored call_llm routing (Ollama → Groq → HF auto fallback),
handle Kafka 'set_llm' control message to switch provider at runtime
- dashboard: /ai/select now publishes set_llm to Kafka control topic so
the AI Analyst service picks up provider changes immediately
- dashboard + index.html: sync LLM selector UI (provider/model dropdowns,
badge, SSE llm_config event) to latest working version
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- frontend.py: /book was calling /book on matcher (404); fixed to
/orderbook/<symbol> with ?symbol= query param
- Order Entry: pass selected symbol to /book, reload on symbol change
- Order Entry: add ← Dashboard link via onclick (not href)
- FIX UI: ← Dashboard href="/" was rewritten by nginx sub_filter to
/fix/; fixed by switching to onclick so sub_filter can't touch it
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add Groq as primary LLM provider (free, 14k req/day)