Skip to content
All library documents

JavaScript Strategy Threads for Market Data, Orders, and WebSockets

Article FMZ digest · Author: 发明者量化-小小梦

Summary

The document explains how FMZ’s JavaScript thread functions can run custom work concurrently with a strategy’s main loop. Its examples show a worker polling ticker data and sharing updates with the main thread, launching several order-placement tasks in response to an interaction command, and consuming WebSocket messages in a worker thread.

It illustrates two communication patterns: shared thread data for ticker updates, and message passing for WebSocket data and shutdown signals. The WebSocket example also joins the worker during strategy cleanup. These are platform-specific implementation patterns, not trading signals or evidence of improved execution. The order example uses simulated pending orders and terminates worker threads after a short wait; it does not establish that live order placement is safe or reliable. Users need to handle timing, errors, and exchange constraints when adapting the examples.

Key ideas

  • A worker thread can run a custom function while the strategy’s main loop continues.
  • Thread data lets a worker publish values that the main thread can read.
  • Separate worker tasks can place orders concurrently after an interaction command.
  • Message passing supports WebSocket data delivery and worker shutdown.
  • The examples demonstrate platform mechanics, not trading performance or production safeguards.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.