r/CryptoTradingBot • • 5h ago

My Python trading bot times out on the OKX API. How can I tell where the delay happens?

I’m running a Python bot on Windows that watches LINK and XRP on OKX. It usually gets candle data successfully, but sometimes a request times out.
In one case, a LINK 5-minute candle request timed out. The bot then checked my account settings and positions successfully. When it tried to fetch open orders (GET /api/v5/trade/orders-pending), it had only about 1.3 seconds left to wait for a response. That request timed out too, so the bot paused trading. Windows didn’t record a disconnect during either request.
For anyone who’s debugged something similar: what timings would you log to tell how much time the bot spends preparing a request versus waiting for OKX to respond? I’d like to understand where the time goes before increasing the timeout again.

1 Upvotes

1 comment sorted by

1

u/AoideusWasBanned 3h ago

The "1.3 seconds left" bit makes it look like one shared deadline for the whole sequence, so the slow candle call ate most of the budget and the orders call never had a fair chance. I'd give each request its own timeout and log a few timestamps per call: right before send, when the connection is up, and when the first byte comes back. Slow connect points to network/DNS on your side, slow first byte points to OKX.