• 极简版OKEX比特币跨期对冲策略


    策略特点

    • 只做正套,反套可以修改下,合约调换一下,即是反套。

    • 添加两个 交易所对象,第一个季度,第二个当周。

    • 精简了所有能简化的代码,优化空间还很大,教学策略谨慎实盘,跨期有一定风险。

    • 欢迎反馈BUG。

    策略源码复制地址:https://www.fmz.com/strategy/144406
     
    function Hedge (isOpen, priceA, priceB) {
        exchanges[0].SetDirection(isOpen ? "sell" : "closesell")
        exchanges[1].SetDirection(isOpen ? "buy" : "closebuy");
        (function (routineA, routineB) {
            Log(routineA.wait(), routineB.wait(), priceA, priceB)
        })(exchanges[0].Go(isOpen ? "Sell" : "Buy", priceA, _ContractNum), exchanges[1].Go(isOpen ? "Buy" : "Sell", priceB, _ContractNum));
    }
    
    var slidePrice = 5
    function main () {
        var tickerA, tickerB 
        var arr = []
        for (var i = 0 ; i < _Count ; i++) {
            arr.push({open: _Begin + i * _Add, cover: _Begin + i * _Add - _Profit, isHold: false})
        }
        exchanges[0].SetContractType("quarter")
        exchanges[1].SetContractType("this_week")
        while (1) {
            var tab = {type: "table", title: "状态", cols: ["节点信息"], rows: []}
            tickerA = exchanges[0].GetTicker()
            tickerB = exchanges[1].GetTicker()
    
            if (tickerA && tickerB) {
                $.PlotLine("差价:A所-B所", tickerA.Last - tickerB.Last)
                for (var j = 0 ; j < arr.length; j++) {
                    if (tickerA.Buy - tickerB.Sell > arr[j].open && !arr[j].isHold) {
                        Hedge(true, tickerA.Buy - slidePrice, tickerB.Sell + slidePrice)
                        arr[j].isHold = true
                    }
                    if (tickerA.Sell - tickerB.Buy < arr[j].cover && arr[j].isHold) {
                        Hedge(false, tickerA.Sell + slidePrice, tickerB.Buy - slidePrice)
                        arr[j].isHold = false 
                    }
                    tab.rows.push([JSON.stringify(arr[j])])
                }
            }
            LogStatus(_D(), "
     `" + JSON.stringify(tab) + "`")
            Sleep(500)
        }
    }
  • 相关阅读:
    前端大文件上传方法(深度好文)
    windows版idea 2018.3.5版 永久激活教程
    性能优化随笔
    使用java画一张海报
    Gson杂记录
    Gson转Map时,Int会变成double解决方法
    浅析VO、DTO、DO、PO的概念、区别和用处
    SpringCloud框架搭建+实际例子+讲解+系列五
    raid总结
    MD5与SHA1
  • 原文地址:https://www.cnblogs.com/botvsing/p/10981222.html
Copyright © 2020-2023  润新知