资源加载中... loading...

Template Libraries

Template libraries are reusable code modules in the FMZ Quant Trading Platform, a category of strategy code. Programming languages that support the template library feature in the FMZ Quant Trading Platform are JavaScript, Python, C++, and Blockly. If the category is set to Template Class Library when creating a strategy, a template library will be created in the strategy library of the currently logged in account of the FMZ Quant Trading Platform, and it is not possible to change the category to a normal strategy after creation. Create template library page

Export function of template library

The export function is an interface function of template library, and it can be called by the strategy that refers to template library.

/*
-- After the strategy references the template, call this method directly with $.Test()
-- The main function is not triggered in the strategy, it is only the entry point for template debugging
*/
$.Test = function() {
    Log('Test')
}

function main() {
    $.Test()
}
def Test():
    Log("template call")

# Export the Test function, the main strategy can be called via ext.Test().
ext.Test = Test 
// After the strategy references the template, call this method directly with ext::Test()
void Test() {
    Log("template call");
}

The template library is written in a different format for different programming languages. An example code for exporting functions to be declared in the template library and implemented is as follows: The Blockly Visualization approach to strategy usage library functionality can be implemented by writing a template class library in the JavaScript language, written using the following writing format.

/*blockly
    {
        "type": "ext_testA",
        "message0": "testA|testA",
        "template": "function(){return 99;}()",
        "order": "ORDER_ATOMIC",
        "output": "Number"
    },{
        "type": "ext_MA",
        "message0": "MA 周期 %1| MA Period %1",
        "args0": [{
            "type": "input_value",
            "check": "Number"
        }],
        "template": "(function(){var r = exchange.GetRecords(); return (!r || r.length < %1) ? false : TA.MA(r, %1); })()",
        "order": "ORDER_ATOMIC",
        "output": null,
        "colour": 85
    }
*/

Template Library Parameters

Template library can also set its own interface parameters, which are used in the form of global variables in the code of template library. For example, we set the parameters of a template class library:

Template parameters

Variable name of the parameter in the strategy code Name of the parameter displayed on the strategy screen Type Default value
param1 param1 number 99
$.SetParam1 = function(p1) {
    param1 = p1
}

$.GetParam1 = function() {
    Log("param1:", param1)
    return param1
}
def SetParam1(p1):
    global param1
    param1 = p1

def GetParam1():
    Log("param1:", param1)
    return param1

ext.SetParam1 = SetParam1
ext.GetParam1 = GetParam1
void SetParam1(float p1) {
    param1 = p1;
}

float GetParam1() {
    Log("param1:", param1);
    return param1;
}

Template class library code for testing param1 parameters:

function main () {
    Log("Call $.GetParam1:", $.GetParam1())
    Log("Call $.SetParam1:", "#FF0000")
    $.SetParam1(20)
    Log("Call $.GetParam1:", $.GetParam1())
}
def main():
    Log("Call ext.GetParam1:", ext.GetParam1())
    Log("Call ext.SetParam1:", "#FF0000")
    ext.SetParam1(20)
    Log("Call ext.GetParam1:", ext.GetParam1())
void main() {
    Log("Call ext::GetParam1:", ext::GetParam1());
    Log("Call ext::SetParam1:", "#FF0000");
    ext::SetParam1(20);
    Log("Call ext::GetParam1:", ext::GetParam1());
}

Reference the strategy code of the template class library example above and use the export function of the template class library to get the parameter param1 and modify the parameter param1.

Reference Template Library

When a strategy references a template library, it requires that the currently logged-in FMZ Quant Trading Platform account has an available template library in its strategy library. After checking the reference in the template column of the strategy editing page, save the strategy. Screenshot of template reference

Strategy Framework and API Functions Strategy Parameters