Skip to main content

Task 5 — Bot feed provider switch + Task 1 — cTrader live tick stream

Summary​

  • Added feed_provider column to bots (migration 0014_bot_feed_provider.sql).
  • Schema/types/repository updated end-to-end so a bot can be created or updated with feedProvider: 'finnhub' | 'ctrader' (defaults to finnhub).
  • BotExecutorDO now reads the bot's feed provider and routes realtime subscriptions to the matching stream DO.
  • CreateBotPage exposes a Tick Feed Provider dropdown (Finnhub default; cTrader option for accounts with cTrader OAuth credentials).
  • MarketMetadataBadges accepts an optional feedProvider prop so live bots show the active tick feed instead of the candle provider label.
  • New CTraderStreamDO scaffold connects to cTrader Open API JSON over WebSocket (wss://demo.ctraderapi.com:5036), runs the standard ProtoOAApplicationAuthReq → ProtoOAAccountAuthReq → ProtoOASubscribeSpotsReq handshake, and forwards spot ticks to MARKET_DATA_DO. Per-tick interval is logged and a console.warn is emitted when the gap is outside the expected 10-100 ms window.
  • wrangler.jsonc registers the new CTRADER_STREAM_DO binding under migration tag v6.

Files​

  • services/backend/src/db/migrations/0014_bot_feed_provider.sql (new)
  • services/backend/src/realtime/ctrader-stream-do.ts (new)
  • services/backend/src/realtime/bot-executor-do.ts
  • services/backend/src/routes/bots/bots-{schema,types,repository,service}.ts
  • services/backend/src/index.ts, worker-types.ts, wrangler.jsonc
  • services/frontend/src/routes/bots/CreateBotPage.tsx
  • services/frontend/src/components/market/MarketMetadataBadges.tsx
  • shared/types.ts

Migration status​

Applied 0013_bot_strategies.sql and 0014_bot_feed_provider.sql to both dev and prod Neon DBs prior to push.

Verification​

  • pnpm --dir services/backend typecheck clean
  • pnpm --dir services/frontend typecheck clean
  • pnpm --dir services/frontend test 28/28 passing