Skip to content
Advertisement

How to monitor multiple assets at the same time with a trading robot?

I am developing a trading robot in Python 3.8 and I need to know if you can give me any ideas to monitor multiple open orders simultaneously.

The situation is as follows: When you want to sell an asset, the robot can monitor conditions permanently and easily evaluate the indicators to place the sell order (limit or market).

But when you have 3, 4, 5 assets or more the situation gets complicated because the robot monitors one asset and then moves on to the next one and so on. This means that when monitoring asset # 2 (for example) asset # 5 (which is not being monitored) may be suffering a sudden strong fluctuation that makes you lose money.

My question is: Is there a way to keep an eye on all 5 assets at the same time?

Advertisement

Answer

Investigating thoroughly on this problem I found a way to theoretically and technically solve this problem. This is multiprocessing in Python.

The technique consists of distributing the memory of our PC in portions to execute the same process many times and at the same time.

Graphically I explain it with the following images. Python runs sequentially as we see in this image:

enter image description here

This has the consequence that if the monitoring loop is calculating the indicators of asset 1, then asset 130 (for example) is unsupervised and could generate considerable losses.

But if we divide the memory of our machine or use multiple cores, we can execute the same process at the same time for several assets, as I show in the following image:

enter image description here

In this link you can see the result of applying a multithreading (take a good look at the time) and a multiprocess: http://pythondiario.com/2018/07/multihilo-y-multiprocesamiento.html

I also leave the link of the library: https://docs.python.org/3/library/multiprocessing.html

More information and more detailed examples of multiprocessing can be seen here: https://www.genbeta.com/desarrollo/multiprocesamiento-en-python-benchmarking

It only remains to develop the code and put it to the test.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement