Yes, the rate limit varies from broker to broker (e.g.: Zeroth 3req/sec)
This happens in almost every broker if we hit the API in the loop continuously.
To solve this problem, you have to put the delay, if possible, of approx. 0.30 sec,
also, we can do the batch fetching – hit the API in batch
Below sample code you can refer:
import time
def fetch_all_data(symbols, fetch_func):
data = {}
for i, symbol in enumerate(symbols):
try:
data[symbol] = fetch_func(symbol)
print(f"Fetched: {symbol}")
# small delay to avoid rate limit
time.sleep(0.5)
except Exception as error:
print(f"Failed: {symbol} -> {error}")
return data
# Sample
def mock_fetch(symbol):
return f"data_for_{symbol}"
symbols = ["AAPL", "MSFT", "GOOG", "TSLA"]
result = fetch_all_data(symbols, mock_fetch)
print(result)