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
-
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"])) 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"])) 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() { // Rust's GetChannelData() function does not accept a channel ID parameter; it can only read the current live trading bot's own channel // (i.e. the latest data published by this bot via SetChannelData()); it cannot subscribe to the channels of other live trading bots loop { // Subscribe to the current state of the channel let state = GetChannelData(); // Build the status display let mut statusMsg = String::from("Channel Subscriber - Current Subscription State\n\n"); 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"; } LogStatus!(statusMsg); Sleep(5000); // Subscribe to the channel every 5 seconds } }c++ -
Cross-platform subscription example - Using UUID to subscribe to data sent from external systems
javascriptfunction main() { // Use a 32-bit 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-bit 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() { // Rust's GetChannelData() function does not accept a channel ID parameter, so it cannot use a 32-bit UUID to subscribe to cross-platform data; // it can only read the latest data from the current live trading bot's own channel (i.e., data published by this bot via SetChannelData()) loop { // Subscribe to the channel's data let data = GetChannelData(); 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 } }c++
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 | The channel identifier, which supports the following two types:
|
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.
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.
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-bit 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.