Retry Wrapper for Exchange Calls in Trading Scripts
Summary
This short note presents a reusable wrapper for retrying exchange API calls that fail because of network problems. Rather than adding retry logic separately around account, order-book, or candle-data requests, the wrapper repeatedly invokes a supplied method and waits briefly whenever its return value is falsy. It also shows that arguments, such as a candle interval, can be passed through the wrapper.
The approach reduces duplicated retry code and can make transient network failures less disruptive. However, the example retries indefinitely and treats any falsy result as a failure, without distinguishing temporary connectivity issues from permanent errors or valid empty responses. It gives no timeout, retry limit, backoff schedule, logging, or error classification. Traders adapting the pattern should consider how a stalled request affects strategy timing and whether repeated calls are safe for the particular exchange operation.
Key ideas
- A common wrapper can apply retry behavior to multiple exchange API methods.
- The example waits briefly and retries whenever a call returns a falsy value.
- Additional method arguments can be forwarded through the wrapper.
- Unlimited retries can stall a strategy and do not distinguish transient from permanent failures.
- Production use may need limits, backoff, logging, and operation-specific error handling.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.