Skip to content
All library documents

Structuring Live Python Arbitrage Systems Across Many Pairs

Article Quant Q&A · Author: Cindy88

Summary

The question describes a live arbitrage setup that compares prices for many product pairs using separate trading and market data APIs. It seeks a way to monitor the pairs continuously without unnecessary looping, distinguishing live system design from backtesting. The proposed strategy is to trade when paired prices diverge beyond a chosen threshold, on the assumption that the products should have equal prices.

The replies offer only broad implementation pointers. One recommends introductory reading rather than giving an architecture. The other suggests moving calculations to C, using a separate process to send results to trading API code, and argues this can make calculations much faster than Python. No benchmarks, code details for a working system, or guidance on data handling, order safety, or synchronizing pair prices are provided. The exchange therefore raises useful design concerns but does not establish that rewriting in C is necessary or sufficient for managing many live pairs; the suggestion depends on calculation speed being the actual bottleneck.

Key ideas

  • The example strategy watches paired products and trades when their prices diverge beyond a threshold.
  • The question concerns continuous live processing across many pairs, rather than backtesting.
  • One reply suggests separating calculations from trading API operations by using distinct processes.
  • The suggestion to use C is not supported by benchmarks or a complete system design.

Tags

Full text
# Tips on building an automated trading system in python


# Tips on building an automated trading system in python












I have an trading API that allows me to send/cancel/update orders. I have marketdata that I can use through another API that gives me orderbook data.

Now let's say I want to build a simple arbitrage strategy, for products X1 vs X2, Y1 vs Y2, and Z1 vs Z2.

X1 and X2 should have the same price, and if they differ more than 0.5% in price I want to trade on this difference.

My question is how to structure my python code, so that it can handle 100 of those pairs simultaneously and continuously. I find a lot of information on backtesting, but I want to trade this live and need to prevent any unnecessary loops.

## Answer by Bob Jansen (score 1)

https://quant.stackexchange.com/a/54004

This is indeed so broad people can write books about this and not a good fit for this site. An introductory book has been written and you could give it a try.

## Answer by Kevin (score 0)

https://quant.stackexchange.com/a/54005

Use C, and if you need math functions, use OpenBLAS. That will run 100-1000 times faster than Python. Then you can use one simple loop for your calculations. Pipe that output into your trading API code running in a separate process.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.