GetMeta
Get the Meta value written when generating the strategy registration code.
GetMeta()Examples
-
Read the Meta written when the registration code was generated.
javascriptfunction main() { var meta = GetMeta() Log("Meta", meta) // Output: Meta level1 (the value written with the registration code; null if none) }pythondef main(): meta = GetMeta() Log("Meta", meta) # Output: Meta level1 (the value written with the registration code; null if none)rustfn main() { let meta = GetMeta(); Log!("Meta", meta); // Output: Meta level1 (the value written with the registration code; null if none) } -
Application scenario example: Use
Metato limit the number of assets the strategy can operate.javascriptfunction main() { // The maximum asset value of the quote currency allowed by the strategy var maxBaseCurrency = null // Get the metadata when creating the registration code var level = GetMeta() // Check the condition corresponding to Meta if (level == "level1") { // -1 means no limit maxBaseCurrency = -1 } else if (level == "level2") { maxBaseCurrency = 10 } else if (level == "level3") { maxBaseCurrency = 1 } else { maxBaseCurrency = 0.5 } while(1) { Sleep(1000) var ticker = exchange.GetTicker() // Check the asset value var acc = exchange.GetAccount() if (maxBaseCurrency != -1 && maxBaseCurrency < acc.Stocks + acc.FrozenStocks) { // Stop executing the strategy trading logic LogStatus(_D(), "level:", level, "Position exceeds registration code limit, strategy trading logic will not execute!") continue } // Other trading logic // Normally output the status bar information LogStatus(_D(), "level:", level, "Strategy running normally! ticker data:\n", ticker) } }pythondef main(): maxBaseCurrency = None level = GetMeta() if level == "level1": maxBaseCurrency = -1 elif level == "level2": maxBaseCurrency = 10 elif level == "level3": maxBaseCurrency = 1 else: maxBaseCurrency = 0.5 while True: Sleep(1000) ticker = exchange.GetTicker() acc = exchange.GetAccount() if maxBaseCurrency != -1 and maxBaseCurrency < acc["Stocks"] + acc["FrozenStocks"]: LogStatus(_D(), "level:", level, "Position exceeds registration code limit, strategy trading logic will not execute!") continue # Other trading logic # Normally output the status bar information LogStatus(_D(), "level:", level, "Strategy running normally! ticker data:\n", ticker)rustfn main() { // The maximum asset value of the quote currency allowed by the strategy let maxBaseCurrency; // Get the metadata when creating the registration code, Rust's GetMeta() returns a JsonValue // type let meta = GetMeta(); let level = meta.as_str().unwrap_or(""); // Check the condition corresponding to Meta if level == "level1" { // -1 means no limit maxBaseCurrency = -1.0; } else if level == "level2" { maxBaseCurrency = 10.0; } else if level == "level3" { maxBaseCurrency = 1.0; } else { maxBaseCurrency = 0.5; } loop { Sleep(1000); let ticker = exchange.GetTicker(None).unwrap(); // Check the asset value let acc = exchange.GetAccount().unwrap(); if maxBaseCurrency != -1.0 && maxBaseCurrency < acc.Stocks + acc.FrozenStocks { // Stop executing the strategy trading logic LogStatus!(_D(None), "level:", level, "Position exceeds registration code limit, strategy trading logic will not execute!"); continue; } // Other trading logic // Normally output the status bar information LogStatus!(_D(None), "level:", level, "Strategy running normally! ticker data:\n", ticker); } }
Returns
| Type | Description |
string |
|
See Also
Remarks
Application scenario: You need to impose fund restrictions on different strategy lessees. The length of the Meta value set when generating the registration code cannot exceed 190 characters. The GetMeta() function is only supported in live trading and does not work in the backtesting system. If the metadata (Meta) is not set when generating the strategy registration code, the GetMeta() function will return an empty value.