Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
_G
DBExec
SetChannelData
GetChannelData
Threads
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Publishes the latest status data to a channel. This function is used for communication between live trading bots, allowing the current bot's status data to be broadcast to a channel for other live trading bots to subscribe to and retrieve.

SetChannelData(data)

Examples

  • Publish the latest BTC_USDT price to this robot's channel every minute.

    javascript
    function main() { while (true) { var ticker = exchange.GetTicker("BTC_USDT") if (ticker) { // Publish the latest state, replacing the previously published data SetChannelData({symbol: "BTC_USDT", last: ticker.Last, time: Date.now()}) } Sleep(60000) } }
    python
    import time def main(): while True: ticker = exchange.GetTicker("BTC_USDT") if ticker: # Publish the latest state, replacing the previously published data data = {"symbol": "BTC_USDT", "last": ticker["Last"], "time": time.time() * 1000} SetChannelData(data) Sleep(60000)
    rust
    fn main() { loop { if let Ok(ticker) = exchange.GetTicker("BTC_USDT") { // Publish the latest state, replacing the previous data; Rust passes a JSON string let data = format!(r#"{{"symbol": "BTC_USDT", "last": {}, "time": {}}}"#, ticker.Last, Unix() * 1000); SetChannelData(&data); } Sleep(60000); } }
  • Channel Broadcaster Example - Publishing BTC Market Price Data

    javascript
    function main() { var updateId = 0 var robotId = _G() // Get current live bot ID while(true) { // Get real-time market price var ticker = exchange.GetTicker("BTC_USDT") if (!ticker) { Sleep(5000) continue } // Construct current channel state data var channelState = { robotId: robotId, updateId: ++updateId, timestamp: Date.now(), symbol: "BTC_USDT", lastPrice: ticker.Last, volume: ticker.Volume, high: ticker.High, low: ticker.Low } // Publish the latest state on the channel (overwrites the old state) SetChannelData(channelState) // Display current channel state LogStatus("Channel Broadcaster [Bot ID: " + robotId + "]\n" + "Update ID: #" + channelState.updateId + "\n" + "Time: " + _D(channelState.timestamp) + "\n" + "Symbol: " + channelState.symbol + "\n" + "Last Price: $" + channelState.lastPrice.toFixed(2) + "\n" + "Volume: " + channelState.volume.toFixed(4) + "\n" + "High: $" + channelState.high.toFixed(2) + "\n" + "Low: $" + channelState.low.toFixed(2)) Sleep(60000) // Update channel state once per minute } }
    python
    import time def main(): updateId = 0 robotId = _G() # Get current live bot ID while True: # Get real-time market price ticker = exchange.GetTicker("BTC_USDT") if not ticker: Sleep(5000) continue # Construct current channel state data channelState = { "robotId": robotId, "updateId": updateId + 1, "timestamp": time.time() * 1000, "symbol": "BTC_USDT", "lastPrice": ticker["Last"], "volume": ticker["Volume"], "high": ticker["High"], "low": ticker["Low"] } updateId += 1 # Publish the latest state on the channel (overwrites the old state) SetChannelData(channelState) # Display current channel state LogStatus("Channel Broadcaster [Bot ID: {}]\n".format(robotId) + "Update ID: #{}\n".format(channelState["updateId"]) + "Time: {}\n".format(_D(channelState["timestamp"] / 1000)) + "Symbol: {}\n".format(channelState["symbol"]) + "Last Price: ${:.2f}\n".format(channelState["lastPrice"]) + "Volume: {:.4f}\n".format(channelState["volume"]) + "High: ${:.2f}\n".format(channelState["high"]) + "Low: ${:.2f}".format(channelState["low"])) Sleep(60000) # Update channel state once per minute
    rust
    fn main() { let mut updateId = 0; let robotId = _G!(); // Get current live bot ID loop { // Get real-time market price let ticker = match exchange.GetTicker("BTC_USDT") { Ok(t) => t, Err(_) => { Sleep(5000); continue; } }; // Construct current channel state data // Rust's SetChannelData only accepts a string argument, so use format! to build the JSON // text updateId += 1; let timestamp = Unix() * 1000; let channelState = format!( r#"{{"robotId": {}, "updateId": {}, "timestamp": {}, "symbol": "BTC_USDT", "lastPrice": {}, "volume": {}, "high": {}, "low": {}}}"#, robotId, updateId, timestamp, ticker.Last, ticker.Volume, ticker.High, ticker.Low ); // Publish the latest state on the channel (overwrites the old state) SetChannelData(&channelState); // Display current channel state LogStatus!(format!( "Channel Broadcaster [Bot ID: {}]\nUpdate ID: #{}\nTime: {}\nSymbol: BTC_USDT\nLast Price: ${:.2}\nVolume: {:.4}\nHigh: ${:.2}\nLow: ${:.2}", robotId, updateId, _D(timestamp), ticker.Last, ticker.Volume, ticker.High, ticker.Low )); Sleep(60000); // Update channel state once per minute } }
  • Cross-platform sending example - Simulate an external platform (such as TradingView) sending data to an FMZ live bot

    javascript
    // This example demonstrates how to use HttpQuery to send an HTTP POST request, simulating an // external platform sending data to an FMZ live bot // In a real scenario, external platforms (such as TradingView's Webhook alert URL, third-party // trading systems, etc.) directly call the FMZ API endpoint function main() { let uuid = "6BC42A119B5DBFA2188A8279DA3B5C30" let robotId = 123456 // Target live bot ID (the live bot used to receive data) let baseUrl = "https://www.fmz.com" while (true) { // Prepare the data to send (can be JSON, text, or other formats) let sendData = { "action": "buy", "symbol": "BTC_USDT", "price": 50000, "timestamp": Date.now() } // Construct the HTTP POST request let options = { method: "POST", body: JSON.stringify(sendData) // body can be a JSON string, plain text, etc. } let url = `${baseUrl}/api/v1?method=pub&robot=${robotId}&channel=${uuid}` // Send the data let ret = HttpQuery(url, options) Log("Simulated external platform sending data, result:", ret) Sleep(10000) // Send once every 10 seconds } }
    python
    # This example demonstrates how to use HttpQuery to send an HTTP POST request, simulating an # external platform sending data to an FMZ live bot # In a real scenario, external platforms (such as TradingView's Webhook alert URL, third-party # trading systems, etc.) directly call the FMZ API endpoint import json import time def main(): uuid = "6BC42A119B5DBFA2188A8279DA3B5C30" robotId = 123456 # Target live bot ID (the live bot used to receive data) baseUrl = "https://www.fmz.com" while True: # Prepare the data to send (can be JSON, text, or other formats) sendData = { "action": "buy", "symbol": "BTC_USDT", "price": 50000, "timestamp": time.time() * 1000 } # Construct the HTTP POST request options = { "method": "POST", "body": json.dumps(sendData) # body can be a JSON string, plain text, etc. } url = "{}/api/v1?method=pub&robot={}&channel={}".format(baseUrl, robotId, uuid) # Send the data ret = HttpQuery(url, options) Log("Simulated external platform sending data, result:", ret) Sleep(10000) # Send once every 10 seconds
    rust
    // This example demonstrates how to use HttpQuery to send an HTTP POST request, simulating an // external platform sending data to an FMZ live bot // In a real scenario, external platforms (such as TradingView's Webhook alert URL, third-party // trading systems, etc.) directly call the FMZ API endpoint fn main() { let uuid = "6BC42A119B5DBFA2188A8279DA3B5C30"; let robotId = 123456; // Target live bot ID (the live bot used to receive data) let baseUrl = "https://www.fmz.com"; loop { // Prepare the data to send (can be JSON, text, or other formats) let sendData = format!( r#"{{"action": "buy", "symbol": "BTC_USDT", "price": 50000, "timestamp": {}}}"#, Unix() * 1000 ); let url = format!("{}/api/v1?method=pub&robot={}&channel={}", baseUrl, robotId, uuid); // Send the data: when the second argument of Rust's HttpQuery() is a string, a POST request // is sent with that string as the body let ret: String = HttpQuery(&url, sendData.as_str()); Log!("Simulated external platform sending data, result:", ret); Sleep(10000); // Send once every 10 seconds } }

Returns

TypeDescription

null value

This function has no return value.

Arguments

NameTypeRequiredDescription

data

object / array / string / number / bool / null value

Yes

The data to be published to the channel. It can be any data structure that supports JSON serialization, and is typically an object containing the live trading bot's status information.

See Also

Remarks

The SetChannelData() function is a non-blocking call; it returns immediately after being called and does not wait for the data transmission to complete.

Each live trading bot has its own dedicated channel, and the channel ID is the bot ID (which can be obtained via the _G() function).

The channel only stores the latest status data. Each call to SetChannelData() overwrites the previously published data rather than appending to a message history.

Channel data supports broadcasting across live trading bots, across dockers, and across servers, and multiple bots can subscribe to the same channel.

The subscriber side uses the GetChannelData() function to subscribe to channel data.

Channel communication is intended for live trading environments; this feature may be restricted in the backtesting system.

The byte length of the passed-in data parameter after JSON serialization must not exceed 1024 bytes. Any excess is truncated and the data is still published, so subscribers receive incomplete data that cannot be parsed as JSON (the GetChannelData() function returns the raw string). It is recommended to transmit only the necessary status information and to avoid transmitting overly large data objects.

The published data should be used reasonably according to the memory and network bandwidth of the hardware device; avoid publishing overly large data objects.

The data published by the SetChannelData() function can not only be subscribed to by other live trading bots within the FMZ platform, but also supports cross-platform data sending. External platforms (such as TradingView Webhook alerts, third-party trading systems, monitoring software, etc.) can send data to a specified FMZ live trading bot via HTTP POST requests.

How to send data across platforms: External systems send data to the FMZ platform API endpoint via an HTTP POST request: https://www.fmz.com/api/v1?method=pub&robot={robotId}&channel={uuid}, where robotId is the target live trading bot ID and uuid is a 32-character channel identifier. The data to be sent is passed in the request body, and can be in JSON format, plain text, or other formats. Note: a live trading bot must already be subscribed to the specified UUID channel before an external system can successfully send data; the broadcast data will be sent to all live trading bots under the same docker as the robotId bot, and any bot under that docker subscribed to the UUID channel can receive the data.