GetChannelData
Subscribe to channel data from a specified live trading instance. This function is used for inter-instance communication, allowing retrieval of the latest status data published by other live trading instances via the SetChannelData() function.
GetChannelData(channelId)Examples
-
Channel Subscriber Example - Subscribe to channel data from two live trading bots
javascriptfunction main() { // Two channel IDs to subscribe to (modify according to actual situation) var channelId1 = "632799" // Live trading bot ID for channel 1 var channelId2 = "632800" // Live trading bot ID for channel 2 while(true) { // Subscribe to current state of channel 1 var state1 = GetChannelData(channelId1) // Subscribe to current state of channel 2 var state2 = GetChannelData(channelId2) // Build status display var statusMsg = "Channel Subscriber - Current Subscription Status\n\n" // Display channel 1 status statusMsg += "═══ Channel 1 [" + channelId1 + "] ═══\n" if (state1 !== null) { statusMsg += "Update ID: #" + state1.updateId + "\n" statusMsg += "Time: " + _D(state1.timestamp) + "\n" statusMsg += "Symbol: " + state1.symbol + "\n" statusMsg += "Last Price: $" + state1.lastPrice.toFixed(2) + "\n" statusMsg += "Volume: " + state1.volume.toFixed(4) + "\n" } else { statusMsg += "Status: Waiting... (first call returns null)\n" } statusMsg += "\n" // Display channel 2 status statusMsg += "═══ Channel 2 [" + channelId2 + "] ═══\n" if (state2 !== null) { statusMsg += "Update ID: #" + state2.updateId + "\n" statusMsg += "Time: " + _D(state2.timestamp) + "\n" statusMsg += "Symbol: " + state2.symbol + "\n" statusMsg += "Last Price: $" + state2.lastPrice.toFixed(2) + "\n" statusMsg += "Volume: " + state2.volume.toFixed(4) + "\n" } else { statusMsg += "Status: Waiting... (first call returns null)\n" } LogStatus(statusMsg) Sleep(5000) // Subscribe to channels every 5 seconds } }pythondef main(): # Two channel IDs to subscribe to (modify according to actual situation) channelId1 = "632799" # Live trading bot ID for channel 1 channelId2 = "632800" # Live trading bot ID for channel 2 while True: # Subscribe to current state of channel 1 state1 = GetChannelData(channelId1) # Subscribe to current state of channel 2 state2 = GetChannelData(channelId2) # Build status display statusMsg = "Channel Subscriber - Current Subscription Status\n\n" # Display channel 1 status statusMsg += "═══ Channel 1 [{}] ═══\n".format(channelId1) if state1 is not None: statusMsg += "Update ID: #{}\n".format(state1["updateId"]) statusMsg += "Time: {}\n".format(_D(state1["timestamp"])) statusMsg += "Symbol: {}\n".format(state1["symbol"]) statusMsg += "Last Price: ${:.2f}\n".format(state1["lastPrice"]) statusMsg += "Volume: {:.4f}\n".format(state1["volume"]) else: statusMsg += "Status: Waiting... (first call returns None)\n" statusMsg += "\n" # Display channel 2 status statusMsg += "═══ Channel 2 [{}] ═══\n".format(channelId2) if state2 is not None: statusMsg += "Update ID: #{}\n".format(state2["updateId"]) statusMsg += "Time: {}\n".format(_D(state2["timestamp"])) statusMsg += "Symbol: {}\n".format(state2["symbol"]) statusMsg += "Last Price: ${:.2f}\n".format(state2["lastPrice"]) statusMsg += "Volume: {:.4f}\n".format(state2["volume"]) else: statusMsg += "Status: Waiting... (first call returns None)\n" LogStatus(statusMsg) Sleep(5000) # Subscribe to channels every 5 secondsc++ -
Cross-platform subscription example - Subscribe to data sent from external systems using UUID
javascriptfunction main() { // Use 32-bit UUID as channel identifier let uuid = "6BC42A119B5DBFA2188A8279DA3B5C30" while (true) { // Subscribe to data from UUID channel let data = GetChannelData(uuid) if (data !== null) { Log("Received cross-platform data:", data) } else { Log("Waiting for data... (first call returns null)") } Sleep(10000) // Check every 10 seconds } }pythondef main(): # Use 32-bit UUID as channel identifier uuid = "6BC42A119B5DBFA2188A8279DA3B5C30" while True: # Subscribe to data from UUID channel data = GetChannelData(uuid) if data is not None: Log("Received cross-platform data:", data) else: Log("Waiting for data... (first call returns None)") Sleep(10000) # Check every 10 secondsc++
Returns
| Type | Description |
object / array / string / number / bool / null value | Returns the latest status data from the subscribed channel. The first call returns |
Arguments
| Name | Type | Required | Description |
channelId | string / number | Yes | Channel identifier, supports two types:
|
See Also
Remarks
The GetChannelData() function is a non-blocking call that returns immediately without waiting for data reception to complete.
The first call to the GetChannelData() function will return null, requiring retries to wait for channel data synchronization to complete.
Each call retrieves the latest status data on the channel, not a historical message queue.
A live trading instance can subscribe to channels from multiple different live trading instances simultaneously by calling GetChannelData() multiple times with different live trading IDs.
The current live trading instance can also subscribe to its own channel, meaning the robotId parameter can be the current live trading ID.
Channel data can be transmitted across live trading instances, across dockers, and across servers.
The broadcasting side uses the SetChannelData() function to publish channel data.
Channel communication is designed for live trading environments; this feature may be limited in the backtesting system.
The GetChannelData() function supports cross-platform subscription functionality. When using a 32-bit UUID as the channel identifier, it can receive data sent from external systems outside the FMZ platform via HTTP API. External systems need to specify the live trading ID and UUID to send data. All live trading instances under the same docker can subscribe to data from that UUID channel, while live trading instances under different dockers cannot subscribe.