Welcome to FMZ Quant Trading Platform
Programming Languages
Key Security
Live Trading
Strategy Library
Docker
Exchange
Strategy Editor
Backtesting System
Backtesting System Modes
Impact of Backtest Data Granularity on Backtesting
Backtesting System Supports Multiple Programming Languages
Exchanges Supported by Backtesting System
Backtest System Parameter Optimization
Save Backtest Settings
Custom Data Source
Local Backtesting Engine
Backtest Page Shortcuts
Backtest Data Download
Backtest System Sharpe Ratio Algorithm
Strategy Entry Functions
Strategy Framework and API Functions
Template Library
Strategy Parameters
Interactive Controls
Options Trading
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
JavaScript Strategy Writing Guide
Due to the inherent characteristics of the JavaScript language (JavaScript's built-in strings only support ASCII and UTF-16 encoding, to avoid data loss), when encountering strings that cannot be encoded, an ArrayBuffer type will be returned. In all API interfaces of the FMZ Quant platform, wherever string parameters can be passed, ArrayBuffer type is also supported.
The following example demonstrates this feature in detail:
javascript
function stringToHex(str) {
let hex = '';
for (let i = 0; i < str.length; i++) {
const charCode = str.charCodeAt(i).toString(16);
hex += charCode.length === 1 ? '0' + charCode : charCode;
}
return hex;
}
function main() {
const inputString = "abc𠮷123"; // The Unicode code point of this "𠮷" character exceeds the 16-bit range
// const inputString = "abcG123"; // If using abcG123 string for testing, the variable outputD will not be assigned as ArrayBuffer
// Use the Encode function to encode inputString to hexadecimal encoding
const encodedHex = Encode("raw", "string", "hex", inputString);
Log(encodedHex); // Content: 61 62 63 f0a0aeb7 31 32 33
// Use custom stringToHex function to encode, unable to handle "𠮷" character, resulting in incorrect hexadecimal encoding
const manuallyEncodedHex = stringToHex(inputString);
Log(manuallyEncodedHex); // Content: 61 62 63 d842dfb7 31 32 33
// Successfully restore from hexadecimal encoding to string (variable inputString)
const decodedString = Encode("raw", "hex", "string", encodedHex);
Log(decodedString);
// Unable to decode, returns ArrayBuffer, i.e., variable outputD is of ArrayBuffer type
const outputD = Encode("raw", "hex", "string", manuallyEncodedHex);
Log(outputD);
// Verify the returned ArrayBuffer type variable outputD
const bufferD = new Uint8Array(outputD);
let hexBufferD = '';
for (let i = 0; i < bufferD.length; i++) {
hexBufferD += bufferD[i].toString(16).padStart(2, '0');
}
Log(hexBufferD); // 61 62 63 d842dfb7 31 32 33
}