yunusus
yunusus

Reputation: 81

How to fetch multiple data from a server at the same time with Python?

I am developing a crypto trading bot using the API of Binance exchange with python language. I am trading on the 5-minute chart, so a new bar is closing every 5 minutes and I am getting data from the server for this newly closed bar and the previous 499 bars.

I use the line of code you see below for this process.

candles = client.futures_klines(symbol='ETHUSDT', interval=client.KLINE_INTERVAL_5MINUTE)

There are 109 coins on the stock market and I need to get the data of all these coins separately from the server every 5 minutes. When I perform this operation for 1 coin, there is no problem, but when I want to put the process in a loop and perform it in order for 109 coins, there is a waiting time of about 2 minutes in total, from 1 second for each coin in my program. Since I have already traded on the 5-minute chart, the prices have already changed after a 2-minute waiting period.

Is there a way for me to complete all these processes faster? How would you overcome this problem?

Many thanks to everyone who took the time to share their experiences with me

Upvotes: 0

Views: 618

Answers (1)

Isslerman
Isslerman

Reputation: 49

This looping to fetch the data needs to be an asynchronous process. So they don't need to wait one finish to start the others. Not sure how you can do this in python, but I know that is easy to do with nodejs.

I'm doing a similar project in python too. Are you using the CCXT library? It's a good API solution that you can connect to others exchanges using the same CCXT API.

Marcos Issler

Upvotes: 1

Related Questions