Using JavaScript Threads for Concurrent Trading Tasks
Summary
This tutorial shows how FMZ’s JavaScript thread functions can run user-defined tasks concurrently with a strategy’s main loop. Its examples cover a worker that repeatedly requests ticker data and passes updates to the main thread, as well as workers launched to submit multiple orders. A third example opens a WebSocket stream in a separate thread and forwards received market data to the main thread through message queues.
The article also demonstrates coordination and cleanup: threads can be signaled to stop, terminated, and joined, and a WebSocket can be closed after its worker exits. Screenshots and live-running examples are cited as evidence that the data flow and interactive order trigger work on the platform. These examples explain platform mechanics rather than establish a trading edge. The order example uses simulated trading and leaves practical safeguards such as order reconciliation, rate limits, duplicate submissions, and concurrency hazards largely untreated, so those concerns need independent handling before live use.
Key ideas
- A worker thread can run a custom function alongside the strategy’s main loop.
- Thread data functions let a worker share ticker updates with the main thread.
- Multiple workers can submit orders concurrently in response to a strategy interaction command.
- WebSocket workers can send streamed data through thread message queues.
- Workers should receive a stop signal and be joined, with resources such as WebSocket connections closed during cleanup.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.