HFT: Can python execute faster than C#?
High Frequency Trading
Recently a new member of the betcode slack group asked an innocent question regarding ‘slippage’ and if migrating to flumine would be faster than using BA automation, I responded with my view:
The thread quickly went toxic and apparently this isn’t true and python is always slower than a C# application regardless of the way a programming language is written / optimised.
In order to see what a highly optimised python program can do vs a faster language I decided to do a real world test. A simple strategy that triggers a few times per racing market was written and used as the benchmark:
Note how I am having to filter on prices where size greater than 1, a rather bizarre limitation of BA automation unless I am missing a setting.
Although it’s limiting in that we are only placing a few orders thus ignoring high transaction outputs and order processing it does allow us to compare tick to execution latency. This strategy is also very easy to create using BetAngel automation with just 5 conditions, a rules file was used as opposed to excel integration as my assumption is that this will be much slower and unfair (future test maybe)
Programs
Python 3.11
flumine 2.13.9
betfairlightweight[speed] 2.23.2
BetAngel v1.63.0
Setup
Same machine / network (local)
Single/isolated Betfair account for both
Streaming on for both (BA background market prices 20ms) (XM off)
Latest flumine version with no extra optimisations or libraries other than what is included in [speed]
BA Automation rule used (not excel integration)
BA Guardian automation settings:
Refresh interval 20ms
Restrict refresh set to 10/900s start time
Auto-switch set to 10s*
Refresh every ‘update’
Test
09/04/26 GB/IE WIN racing, started late and finished early as I got bored
Multi bet placement based on simple event trigger
Latency
BetId’s stored
Execution time stored
Raw order stream recorded
*This means that BA is actually only processing markets which are past the scheduled start time (~1 market at a time), flumine is processing all market updates for the day that come through the stream. If it was a fair fight we should either limit flumine to the same or turn off auto-switch but I want this test to best represent each system using best practices recommended.
Results
The Betfair order stream only returns a ‘placedDate’ field in seconds which is useless for this analysis so instead I have used betId as its sequential and allows us to get a good idea of which is faster. I am going to message Betfair to see if they can give me the full timestamps for the bets so this will hopefully be updated.
Using a ECDF plot you can see that flumine is faster >95% of the time and BA shows instances of some slow processing (long tail) even with the multi market processing handicap.
On this small sample I am seeing flumine has a median lower betId of ~39 however this absolute figure isn’t accurate (will vary based on matching engine load) but merely signals that flumine is faster. Considering the matching engine is FIFO, even a small improvement in this number can have a big impact on match rates and thus pnl.
From the data it looks as though BA processes rules sequentially and places bets on the conditions, this is important to know as large rules files with logic/conditions will have higher latency. BA does not take advantage of batching the orders into one request but sends them individually, you can see this due to the BetId’s not following each other like they do in a flumine transaction.
You can see how the latency increases based on the price due to the order of the ‘rules’ with 1.01 placed first vs 1.05 last in the rules order. At a high level the more you scale your rules/logic and the number of markets the limitations of BA will become apparent although without benchmarking most users will be unaware.
It’s important to note that python being faster is simply because flumine is event driven and designed purely to execute off marketBook updates vs BetAngel which is designed as a fully functioning trading package with Automation built on top. Even with BA looking at just a single market vs all markets in flumine there is still a big advantage in using a purpose built event driven framework when executing.
The fact that BetAngel only streams the current Market based on scheduled start time / inplay has given me a few ideas of how flumine could be further optimised when looking for a few extra ms.
Notes
Do I believe python is faster than C#?
No
Do I think BA is a poor trading framework?
No, it does exactly what it states and it does it very well (it’s how I started)
Should I migrate to flumine?
If your strategies are latency sensitive and/or you want to scale horizontally to more markets I will always strongly recommend it





