-
Notifications
You must be signed in to change notification settings - Fork 110
Description
During some thorough testing, I have discovered that when HTTP 429 status codes are returned to the client by Alpaca's Trading API, this client library code will attempt to retry by default. However in the process of doing so, the response body from from the previous attempt is not closed properly. This causes errors to be produced with the following message:
Post "https://paper-api.alpaca.markets/v2/orders": http: ContentLength=446 with Body length 0
This appears to happen because resp.Body.Close() is only called inside the verify() function, which is called only once and not once per c.httpClient.Do(req).
In my particular situation this is a simple fix now that I know the issue exists. Since retrying is something my code needs to handle explicitly, I decided to simply disable the client.RetryLimit by setting it to 0. Curiously though, client.RetryLimit cannot be set to 0, as it will be overwritten to become 3, as per
alpaca-trade-api-go/alpaca/rest.go
Lines 59 to 62 in 73c6e7b
| } | |
| if opts.RetryLimit == 0 { | |
| opts.RetryLimit = 3 | |
| } |
RetryLimit = -1, which does produce the desired result of disabling retries.
So two issues:
- Unnecessary error logging is printed on HTTP 429 responses, and
- RetryLimit cannot be set to 0
Thanks!