Managing Concurrent Trading Tasks with JavaScript and Go
Summary
The document shows how to run exchange requests concurrently from a JavaScript trading strategy by calling Go-backed asynchronous functions. It begins with sequential order-book requests and explains that waiting on each request in turn can add latency, especially when a strategy needs data from multiple exchanges or must perform many operations. The proposed helper pairs each asynchronous task with its context and a callback to store the result when it returns.
A task queue and worker then dispatch queued requests, wait for their results, and write them into the appropriate fields in shared strategy state. This producer-worker structure is intended to make task creation independent from execution and result handling. The example is illustrative rather than a complete production design: it does not provide performance measurements or discuss error handling, synchronization, task cancellation, or the risks of trading on stale results. The presented worker also mutates its task list while iterating, so the implementation should be reviewed before practical use.
Key ideas
- Concurrent requests can reduce the delay caused by making exchange calls sequentially.
- A helper can associate each asynchronous request with context and a result callback.
- A producer can queue exchange tasks while a worker launches them and stores their results.
- The example demonstrates an organizational pattern rather than measured trading performance.
- Production use requires attention to errors, stale data, and task handling.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.