Dear Fyers Support Team,
I am experiencing a recurring issue with the Fyers API when using the fyers.history() function.
**Problem Description:**
I use historical data for live trading and call the history() function immediately after the closing of a candle.
Sometimes the call to fyers.history() hangs indefinitely and never returns, even when my internet connection is stable.
There is no ConnectTimeoutError — the request simply stalls and no exception is raised, causing my program to freeze.
**Additional Information:**
I am using fyers_apiv3
I have already set a global
timeoutparameter for therequestslibrary, but the function still hangs.This makes it impossible to reliably run automated trading strategies, as the system becomes unresponsive whenever this happens.
**Request:**
Kindly help me resolve this issue, or let me know if there is something wrong in my implementation.
Below is a simplified version of my code for reference:
```python
def histData(fyers, data=fut_data_info):
try:
print("Downloading historical data:")
response = fyers.history(data=data)
if response:
df = pd.DataFrame(response.get('candles'),
columns=['date', 'open', 'high', 'low', 'close', 'volume'])
return df
except Exception as e:
print(str(e))
return None
# Main program
timeout_val = 20
for method_name in ['get', 'post', 'put', 'delete', 'head', 'options', 'request']:
original = getattr(requests, method_name)
patched = functools.partial(original, timeout=timeout_val)
setattr(requests, method_name, patched)
print(f"Patched requests methods with a global timeout of {timeout_val} seconds.")
# Initialize the FyersModel instance
fyers = fyersModel.FyersModel(client_id=app_info.get('client_id'),
is_async=False, token=access_token, log_path="")
while True:
data = histData(fyers)
# My strategy
sleep(pause_time)
Here, pause_time is either 10 or 300 seconds depending on whether my algorithm is currently in a trade.
I would appreciate it if you could confirm whether the history() function internally handles timeouts correctly, or I have to do something else to handle it.