alpacahq / alpaca-py

The Official Python SDK for Alpaca API
https://alpaca.markets/sdks/python/getting_started.html
Apache License 2.0
505 stars 125 forks source link

Support REST requests timeout, especially with StockHistoricalDataClient #415

Open impredicative opened 4 months ago

impredicative commented 4 months ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe.

Currently when getting StockBarsRequest, I cannot specify a requests timeout. Sometimes it takes too long to return, as much as 7 seconds.

Describe the solution you'd like.

The requests package supports a timeout argument. It should be possible for me to optionally provide this argument when I initialize StockHistoricalDataClient. I would then use two instances of this client, one without a timeout, and one with a timeout when I need it.

In this way, I can myself easily then retry the request if it takes longer than say 2 seconds instead of waiting for 7 seconds. Usually it returns very quickly.

The default behavior should continue to remain as it is now.

Describe an alternate solution.

No response

Anything else? (Additional Context)

Without this feature I have to use requests myself which may be undesirable. [example]