Research Project · MabuhayTech
CFD HFT Bot: Execution Latency Research
Latency-optimization research for a live CFD high-frequency trading bot. The project investigated where execution latency comes from, then reworked the trading path to replace heavy browser-based interaction with direct protocol-level communication. The result was a faster, more consistent execution pipeline, with the network round-trip identified as the remaining latency floor.
Python · asyncio · WebSocket · HTTP · Market Data Feeds · Automation
Outcomes
Faster execution path
Removed heavy browser automation from the trading loop, replacing it with direct protocol-level communication.
Lower internal overhead
Streamlined the signal-to-order dispatch path end-to-end, cutting per-trade internal work.
More consistent latency
Eliminated the latency spikes introduced by the previous execution mechanism.
Clear bottleneck visibility
Isolated the network round-trip as the dominant remaining cost in the execution budget.
Approach
Real-time market data feed
A dedicated WebSocket feed delivers market prices, kept fully isolated from order processing.
Direct order execution
Orders are submitted straight to the trading endpoint over HTTP, removing the browser from the execution path.
Precision latency instrumentation
End-to-end timing of every signal, so exactly where time is spent is visible and measurable.
Safe simulation mode
A simulation mode that exercises the real network path without ever placing an order.
Isolated concurrent processing
Data feeds, order routing, and monitoring run on isolated threads so nothing blocks the trading loop.
Automated session recovery
Automated login and session refresh with zero manual intervention during operation.
Live Console
The system runs entirely from the console, a status line per second, plus signal detection and order entries as they happen.
$ python main.py
[ session ] authenticated
[ feed ] real-time market data connected
[ monitor ] logging started
[ RUNNING ] market: 6.25 | broker: 6.25 | position: none | signals: 44
[ signal ] BUY detected, gap above threshold
[ order ] submitted | status: accepted | qty: 0.0 (simulation)
[ RUNNING ] market: 6.25 | broker: 6.26 | position: open | signals: 46
[ close ] position closed | hold: 1.4s
[ benchmark ] run complete, summary written