0

I plan on creating a trading bot that performs the same tasks on different cryptos at the same time. Without threading/multiprocessing, it would kind of look like this:

while True:
    # load data for crypto no. 1
    # perform math
    # buy or sell crypto no. 1

Once finished, it goes over to do the same with crypto no. 2.

However, I thought I could use threading for that but I learned that threading performs best with I/O tasks and not with sheer computation. So, am I better of using multiprocessing here?

  • threading pretty much just launches a function and the launches the next one while the previous is still working, multiprocessing launches them at the same time – Matiiss Apr 02 '21 at 19:42
  • Understood, but aren't we then talking about nanoseconds? I mean, how much longer could it take to start them all after each other than starting them at the same time. Or, in other words: Why is multiprocessing an advantage? – newtopython Apr 02 '21 at 19:50
  • I don't know whether multiprocessing is an advantege, check these two tutorials where I think it is also explained for what they are used: [threading](https://www.youtube.com/watch?v=IEEhzQoKtQU), [multiprocessing](https://www.youtube.com/watch?v=fKl2JW_qrso) – Matiiss Apr 02 '21 at 20:00
  • Funnily enough, in the very moment you suggest this, I am watching Corey's video on multiprocessing :) Thank you. – newtopython Apr 02 '21 at 20:03
  • The main reason to choose multiprocessing over multithreading in python is to avoid the GIL, which is a performance bottleneck for CPU-intensive threaded Python code: https://stackoverflow.com/questions/1294382/what-is-the-global-interpreter-lock-gil-in-cpython – Jeremy Friesner Apr 03 '21 at 00:18
  • @newtopython don't concern yourself with nanoseconds. I guarantee you aren't going to be successful in high frequency trading. Threading will be better if you are mostly waiting on the network (your cpu is very likely faster than your internet), and multiprocessing for when you're hitting the limit of a single core. – Aaron Apr 03 '21 at 17:20

0 Answers0