Type/to search
Welcome to FMZ Quant Trading Platform
Programming Languages
JavaScript
TypeScript
Python
Rust
C++
MyLanguage
PINE Language
Blockly Visual Programming
Workflow
Key Security
Live Trading
Strategy Library
Docker
Deploy Docker
One-Click Docker Rental
Manual Deployment of Bot
Docker Operation Precautions
Global IP Address Specification
Command Line Parameters for Bot Program
Live Trading Data Migration
Docker Monitor
Exchange
Strategy Editor
Backtesting System
Strategy Entry Functions
Strategy Framework and API Functions
Template Library
Strategy Parameters
Interactive Controls
Options Trading
Rust Strategy Development Guide
C++ Strategy Writing Guide
JavaScript Strategy Writing Guide
Web3
Built-in Libraries
Extended API Interface
MCP Service
Trading Terminal
Data Explorer
Alpha Factor Analysis Tool
General Protocol
Debugging Tool
Remote Editing
Import and Export of Complete Strategies
Multi-language Support
Live Trading and Strategy Grouping
Live Trading Display
Strategy Sharing and Renting
Live Trading Message Push
Common Causes of Live Trading Errors and Abnormal Exits
Exchange-Specific Notes

  1. The difference between writing strategies in Rust and in JavaScript lies mainly in the different form of data returned by the platform API functions. Take the exchange.GetTicker() function as an example:
  • JavaScript
    exchange.GetTicker() returns an object on a successful call; if the call fails (e.g., due to exchange server issues, network issues, etc.), it returns null.

    javascript
    function main() { var ticker = exchange.GetTicker() // Check whether the exchange.GetTicker call failed (returns null) if (ticker) { Log(ticker) } }
  • Rust
    API calls that may fail uniformly return the Result<T> type, and errors can be handled in idiomatic Rust style:

    rust
    fn main() { // Approach 1: pattern matching to check whether the exchange.GetTicker call succeeded if let Ok(ticker) = exchange.GetTicker(None) { Log!(ticker); } // Approach 2: use the _C! macro to retry automatically until the call succeeds let ticker = _C!(exchange.GetTicker(None)); Log!(ticker); }

    Optional parameters (such as the symbol parameter of GetTicker) use None as a placeholder when not passed, and are passed directly when a value is needed, e.g., exchange.GetTicker("BTC_USDT").

  1. Strategy entry point and lifecycle: The entry point of a Rust strategy is fn main() (which shares the same name as the entry point of a standard Rust program, but is invoked by the platform and has no return value). As with JavaScript, you can optionally define fn init() (executed automatically first when the strategy starts running) and fn onexit() (executed to perform cleanup when the strategy exits), which the bootstrap layer will call automatically. In addition, you can also call OnExit() within the strategy code to register additional exit hooks:
rust
fn main() { // Strategy logic... } fn init() { Log!("Initializing"); } fn onexit() { Log!("Strategy exiting, performing cleanup"); }
  1. Logging and global features are provided in the form of macros: Log!(), LogStatus!(), Panic!(), _G!(), _C!(), etc. are Rust macros (note the trailing exclamation mark); whereas LogProfit(), Sleep(), _D(), _N(), HttpQuery(), etc. are regular functions.

  2. Strategy parameters are injected as global constants: strategy parameters configured in the UI are injected into the strategy code according to their value types (number maps to f64, boolean to bool, string/password to &str, and dropdowns according to the value type of their options), and can be referenced directly by parameter name. If you need to use them as integers, convert them yourself, e.g., let n = Period as usize;. The complete parameter set can be obtained as JSON text via the params() function and parsed yourself.

  3. JSON data handling: The raw JSON text returned by the platform API (such as the return value of exchange.IO() and the Info field of various structs) can be parsed into a JsonValue using the built-in JSONParse() function, and navigated by indexing in the form of v["key"] and v[0], then obtaining scalar values via methods such as as_f64(), as_str(), and as_bool(). Since the SDK does not have built-in JSON serialization, you can assemble JSON text using the format! macro, or introduce a third-party crate (such as serde_json).

  4. Third-party crates and TLS notes: The strategy source code is the only code file, and dependencies must be declared in a [dependencies] frontmatter block wrapped by --- at the very top of the source code (see the "Programming Languages - Rust" section for details). Since the compilation sandbox does not have system OpenSSL, for crates that require TLS please choose the pure-Rust implementation rustls and avoid depending on native-tls/openssl-sys; for WebSocket connections, prefer the built-in Dial() function.