GetChannelData
Subscribes to the channel data of a specified live trading bot. This function is used for inter-bot communication, allowing you to retrieve the latest status data published by other live trading bots via the SetChannelData() function.
GetChannelData(channelId)Examples
-
Read the latest price published on another robot's channel every 5 seconds.
javascriptfunction main() { var channelId = "632799" // robot ID of the publisher while (true) { var state = GetChannelData(channelId) // Non-blocking: null on the first call or before the publisher has sent anything if (state) { Log(state.symbol, "Last", state.last) } Sleep(5000) } }pythondef main(): channelId = "632799" # robot ID of the publisher while True: state = GetChannelData(channelId) # Non-blocking: None on the first call or before the publisher has sent anything if state: Log(state["symbol"], "Last", state["last"]) Sleep(5000)rustfn main() { let channelId = "632799"; // robot ID of the publisher loop { // Rust reads another robot's channel with GetChannelDataOf; null until data arrives let state = GetChannelDataOf(channelId); if !state.is_null() { Log!(state["symbol"].clone(), "Last", state["last"].clone()); } Sleep(5000); } } -
Channel Subscriber Example - Subscribe to Channel Data from Two Live Trading Bots
javascriptfunction main() { // The two channel IDs to subscribe to (modify according to your actual situation) var channelId1 = "632799" // Live trading bot ID of channel 1 var channelId2 = "632800" // Live trading bot ID of channel 2 while(true) { // Subscribe to the current state of channel 1 var state1 = GetChannelData(channelId1) // Subscribe to the current state of channel 2 var state2 = GetChannelData(channelId2) // Build the status display var statusMsg = "Channel Subscriber - Current Subscription State\n\n" // Display channel 1 state statusMsg += "═══ Channel 1 [" + channelId1 + "] ═══\n" if (state1 !== null) { statusMsg += "Update ID: #" + state1.updateId + "\n" statusMsg += "Time: " + _D(state1.timestamp) + "\n" statusMsg += "Trading Pair: " + state1.symbol + "\n" statusMsg += "Last Price: $" + state1.lastPrice.toFixed(2) + "\n" statusMsg += "Volume: " + state1.volume.toFixed(4) + "\n" } else { statusMsg += "State: Waiting... (first call returns null)\n" } statusMsg += "\n" // Display channel 2 state statusMsg += "═══ Channel 2 [" + channelId2 + "] ═══\n" if (state2 !== null) { statusMsg += "Update ID: #" + state2.updateId + "\n" statusMsg += "Time: " + _D(state2.timestamp) + "\n" statusMsg += "Trading Pair: " + state2.symbol + "\n" statusMsg += "Last Price: $" + state2.lastPrice.toFixed(2) + "\n" statusMsg += "Volume: " + state2.volume.toFixed(4) + "\n" } else { statusMsg += "State: Waiting... (first call returns null)\n" } LogStatus(statusMsg) Sleep(5000) // Subscribe to the channel every 5 seconds } }pythondef main(): # The two channel IDs to subscribe to (modify according to your actual situation) channelId1 = "632799" # Live trading bot ID of channel 1 channelId2 = "632800" # Live trading bot ID of channel 2 while True: # Subscribe to the current state of channel 1 state1 = GetChannelData(channelId1) # Subscribe to the current state of channel 2 state2 = GetChannelData(channelId2) # Build the status display statusMsg = "Channel Subscriber - Current Subscription State\n\n" # Display channel 1 state 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"] / 1000)) statusMsg += "Trading Pair: {}\n".format(state1["symbol"]) statusMsg += "Last Price: ${:.2f}\n".format(state1["lastPrice"]) statusMsg += "Volume: {:.4f}\n".format(state1["volume"]) else: statusMsg += "State: Waiting... (first call returns None)\n" statusMsg += "\n" # Display channel 2 state 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"] / 1000)) statusMsg += "Trading Pair: {}\n".format(state2["symbol"]) statusMsg += "Last Price: ${:.2f}\n".format(state2["lastPrice"]) statusMsg += "Volume: {:.4f}\n".format(state2["volume"]) else: statusMsg += "State: Waiting... (first call returns None)\n" LogStatus(statusMsg) Sleep(5000) # Subscribe to the channel every 5 secondsrustfn main() { // The two channel IDs to subscribe to (modify according to your actual situation) // In Rust, read a specific channel with GetChannelDataOf(channelId); GetChannelData() without // arguments reads this bot's own channel let channelIds = ["632799", "632800"]; // Live trading bot IDs of channel 1 and channel 2 loop { // Build the status display let mut statusMsg = String::from("Channel Subscriber - Current Subscription State\n\n"); for (i, channelId) in channelIds.iter().enumerate() { // Subscribe to the current state of the channel let state = GetChannelDataOf(*channelId); statusMsg += &format!("═══ Channel {} [{}] ═══\n", i + 1, channelId); if !state.is_null() { statusMsg += &format!("Update ID: #{}\n", state["updateId"].as_i64().unwrap_or(0)); statusMsg += &format!("Time: {}\n", _D(state["timestamp"].as_i64().unwrap_or(0))); statusMsg += &format!("Trading Pair: {}\n", state["symbol"].as_str().unwrap_or("")); statusMsg += &format!("Last Price: ${:.2}\n", state["lastPrice"].as_f64().unwrap_or(0.0)); statusMsg += &format!("Volume: {:.4}\n", state["volume"].as_f64().unwrap_or(0.0)); } else { statusMsg += "State: Waiting... (first call returns null)\n"; } statusMsg += "\n"; } LogStatus!(statusMsg); Sleep(5000); // Subscribe to the channels every 5 seconds } } -
Cross-platform subscription example - Using UUID to subscribe to data sent from external systems
javascriptfunction main() { // Use a 32-character UUID as the channel identifier let uuid = "6BC42A119B5DBFA2188A8279DA3B5C30" while (true) { // Subscribe to data on the 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 a 32-character UUID as the channel identifier uuid = "6BC42A119B5DBFA2188A8279DA3B5C30" while True: # Subscribe to data on the 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 secondsrustfn main() { // Use a 32-character UUID as the channel identifier; in Rust, read a specific channel with // GetChannelDataOf() let uuid = "6BC42A119B5DBFA2188A8279DA3B5C30"; loop { // Subscribe to the data of the UUID channel let data = GetChannelDataOf(uuid); if !data.is_null() { Log!("Received cross-platform data:", data); } else { Log!("Waiting for data... (first call returns null)"); } Sleep(10000); // Check every 10 seconds } }
Returns
| Type | Description |
object / array / string / number / bool / null value | Returns the latest status data of the subscribed channel. It returns |
Arguments
| Name | Type | Required | Description |
channelId | string / number | Yes | Channel identifier: the robot ID of another robot (communication between robots; a robot gets its own ID with |
See Also
Remarks
The GetChannelData() function is a non-blocking call. It returns immediately after being called and does not wait for data reception to complete.
The first time the GetChannelData() function is called, it returns null. You need to retry and wait for the channel data synchronization to complete.
Each call retrieves the latest status data on the channel, rather than a historical message queue.
A single live trading bot can subscribe to the channels of multiple different bots simultaneously; simply call GetChannelData() multiple times, passing in a different bot ID each time.
Each live trading can subscribe to at most 10 different channels (live trading ID channels and UUID channels combined); reading a channel for the first time subscribes to it. Beyond the limit the call returns a null value and writes an error log entry channel subscriber exceed limit; the strategy keeps running.
The current live trading bot can also subscribe to its own channel, meaning the robotId parameter can be the ID of the current bot.
Channel data can be transmitted across bots, across administrators, and across servers.
The broadcasting end uses the SetChannelData() function to publish channel data.
In Rust, read a specific channel with GetChannelDataOf(channelId); GetChannelData() without arguments reads the current live trading bot's own channel.
Channel communication is suitable for the live trading environment; this feature may be limited in the backtesting system.
The GetChannelData() function supports cross-platform subscription. When a 32-character UUID is used as the channel identifier, it can receive data sent by external systems outside the FMZ platform via the HTTP API. The external system must specify both the bot ID and the UUID in order to send data; all live trading bots under the same administrator can subscribe to the data of that UUID channel, while bots under different administrators cannot subscribe.