Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
exchange.Go
EventLoop
ctx.subscribe
ctx.poll
ctx.order
ctx.cancel
ctx.submit
Subscription
threading
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Server
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

This section introduces concurrency-related functions. exchange.Go runs time-consuming calls in the background, and EventLoop waits for concurrent call results and events. These two functions are available in all supported programming languages; the multithreading objects listed below support only JavaScript. ctx.subscribe and ctx.poll are the Docker's WebSocket push interfaces: ctx.subscribe() subscribes to market data, market-wide tickers, or private account data streams and returns a Subscription object (an array of subscription objects when subscribing to multiple instruments at once), while ctx.poll() retrieves push events. ctx.order and ctx.cancel place and cancel orders through the exchange's REST API and return only after receiving the exchange's response; ctx.submit places and cancels orders through the exchange's WebSocket trading API (with support for batch operations), returning immediately after the request is written, with results retrieved as response events through ctx.poll(). JavaScript and Python strategies use the global ctx object, while Rust uses functions with the same names in the ctx module. Subscriptions belong to the thread that initiates them. The main thread and each child thread subscribe and retrieve events independently, and all can place orders. Push streams and REST API methods such as exchange.GetTicker() operate independently. For each exchange's push capabilities, see the Capability Matrix.

The FMZ Quant Trading Platform supports multithreading for JavaScript strategies at the underlying system level and provides the following objects:

ObjectDescriptionNotes
threadingGlobal multithreading objectMember functions: Thread, getThread, mainThread, etc.
ThreadThread objectMember functions: peekMessage, postMessage, join, etc.
ThreadLockThread lock objectMember functions: acquire, release. Can be passed into the thread environment as an argument to the thread's execution function.
ThreadEventEvent objectMember functions: set, clear, wait, isSet. Can be passed into the thread environment as an argument to the thread's execution function.
ThreadConditionCondition variable objectMember functions: notify, notifyAll, wait, acquire, release. Can be passed into the thread environment as an argument to the thread's execution function.
ThreadDictDictionary objectMember functions: get, set. Can be passed into the thread environment as an argument to the thread's execution function.
ServerServer objectReturned by threading.Serve(). Member functions: addr, close, stop, join, pending. Can be passed into the thread environment as an argument to the thread's execution function.

In this sectionRead the whole section

NameDescription
exchange.GoMulti-threaded asynchronous support function that can convert the operations of all supported functions into asynchronous concurrent execution.
EventLoopListens for events.
ctx.subscribeSubscribes to WebSocket push streams.
ctx.pollRetrieves the next push event from the subscriptions of the current thread, with an optional wait timeout.
ctx.orderPlaces an order through the exchange's REST API and returns after the exchange returns an order ID.
ctx.cancelCancels an order through the exchange's REST API and returns after the exchange confirms the cancellation.
ctx.submitPlaces and cancels orders through the exchange's WebSocket trading API: returns a request ID immediately after sending the request, without waiting for the exch…
Subscription (4)A subscription object, returned by ctx.subscribe, represents a single push subscription stream.
threading (10)A global multi-threading management tool, providing functions for creating concurrent threads, thread locks, condition variables, and more.
Thread (9)Represents one thread; created or returned through threading.Thread(), threading.getThread(), threading.mainThread(), threading.currentThread().
ThreadLock (2)Thread lock object for multi-threaded synchronization processing.
ThreadEvent (4)Event object for event notification and signal passing between multiple threads.
ThreadCondition (5)Condition variable object used for implementing synchronization and communication between multiple threads.
ThreadDict (2)Thread-safe dictionary object for data sharing in multi-threaded environments.
Server (5)Returned by threading.Serve(); represents a running service.