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

插件用途

插件可以执行代码一段时间,可执行一些简单的操作。例如冰山委托、挂单、撤单、计算等任务,和调试工具一样使用return返回结果,也可以直接返回图表和表格。 下面举几个例子,其他功能可以自行探索。

  • 返回深度的快照

    // 返回深度的快照
    function main() {
        var tbl = { 
            type: 'table', 
            title: '深度快照 @ ' + _D(), 
            cols: ['#', 'Amount', 'Ask', 'Bid', 'Amount'], 
            rows: []
        }
        var d = exchange.GetDepth()
        for (var i = 0; i < Math.min(Math.min(d.Asks.length, d.Bids.length), 15); i++) {
            tbl.rows.push([i, d.Asks[i].Amount, d.Asks[i].Price+'#ff0000', d.Bids[i].Price+'#0000ff', d.Bids[i].Amount])
        }
        return tbl
    }
    
    def main():
        tbl = {
            "type": "table",
            "title": "深度快照 @ " + _D(),
            "cols": ["#", "Amount", "Ask", "Bid", "Amount"],
            "rows": []
        }
        d = exchange.GetDepth()
        for i in range(min(min(len(d["Asks"]), len(d["Bids"])), 15)):
            tbl["rows"].append([i, d["Asks"][i]["Amount"], str(d["Asks"][i]["Price"]) + "#FF0000", str(d["Bids"][i]["Price"]) + "#0000FF", d["Bids"][i]["Amount"]])
        return tbl
    
    void main() {
        json tbl = R"({
            "type": "table",
            "title": "abc",
            "cols": ["#", "Amount", "Ask", "Bid", "Amount"],
            "rows": []   
        })"_json;
        
        tbl["title"] = "深度快照 @" + _D(); 
        auto d = exchange.GetDepth();
        for(int i = 0; i < 5; i++) {
            tbl["rows"].push_back({format("%d", i), format("%f", d.Asks[i].Amount), format("%f #FF0000", d.Asks[i].Price), format("%f #0000FF", d.Bids[i].Price), format("%f", d.Bids[i].Amount)});
        }
        
        LogStatus("`" + tbl.dump() + "`");
        // C++ 不支持return json 显示表格,可以创建实盘显示状态栏表格
    }
    
  • 画跨期差价

    // 画跨期差价
    var chart = { 
        __isStock: true,    
        title : { text : '差价分析图'},                     
        xAxis: { type: 'datetime'},                 
        yAxis : {                                        
            title: {text: '差价'},                   
            opposite: false                   
        },
        series : [                    
            {name : "diff", data : []}
        ]
    }  
    
    function main() {
        exchange.SetContractType('rb2205')   // 实际使用时,需要自行修改需要的合约代码
        var recordsA = exchange.GetRecords(PERIOD_M5)
        exchange.SetContractType('rb2201')   // 实际使用时,需要自行修改需要的合约代码
        var recordsB = exchange.GetRecords(PERIOD_M5)
        
        for(var i = 0; i < Math.min(recordsA.length, recordsB.length); i++){
            var diff = recordsA[recordsA.length - Math.min(recordsA.length, recordsB.length) + i].Close - recordsB[recordsB.length - Math.min(recordsA.length, recordsB.length) + i].Close
            chart.series[0].data.push([recordsA[recordsA.length - Math.min(recordsA.length, recordsB.length) + i].Time, diff])
        }
        return chart
    }
    
    chart = {
        "__isStock": True,
        "title": {"text": "差价分析图"},
        "xAxis": {"type": "datetime"},
        "yAxis": {
            "title": {"text": "差价"}, 
            "opposite": False
        }, 
        "series": [
            {"name": "diff", "data": []}
        ]
    }  
    
    def main():
        exchange.SetContractType("rb2205")
        recordsA = exchange.GetRecords(PERIOD_M5)
        exchange.SetContractType("rb2201")
        recordsB = exchange.GetRecords(PERIOD_M5)  
    
        for i in range(min(len(recordsA), len(recordsB))):
            diff = recordsA[len(recordsA) - min(len(recordsA), len(recordsB)) + i].Close - recordsB[len(recordsB) - min(len(recordsA), len(recordsB)) + i].Close
            chart["series"][0]["data"].append([recordsA[len(recordsA) - min(len(recordsA), len(recordsB)) + i]["Time"], diff])
        return chart
    
    // C++ 不支持 return json 结构画图
    

策略广场中还有其它范例可以参考,例如:逐笔小量买入/卖出。

插件编写 使用方式