rest version of OKEX cross-currency hedging strategy

Author: The Little Dream, Date: 2019-04-17 13:30:36
Tags: Study

OKEX cross-currency hedging strategy (teachable)

img

  • The only thing that can be done is to make the original set, the reverse set can be modified, the contract can be changed, that is, the reverse set.

  • Add two exchange objects, the first one for the quarter, the second one for the week.

  • There is a lot of room to optimize, the teaching strategy is careful, and there is a certain risk in the transition period.

  • Welcome to feedback BUG.

Teaching strategies, practical use and caution.

Teaching strategies, practical use and caution.

Teaching strategies, practical use and caution.


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(), "\n `" + JSON.stringify(tab) + "`")
        Sleep(500)
    }
}

Related

More

I love Jimmy.Exchanges[0].Go ((() is not mentioned in the documentation of this function. Where did it come from, what does it mean?

ll1998Hi, author, can you tell me if this tactic still works?

fmzeroWhere's the teaching video?

I love Jimmy.Oh, thank you, I saw it, I learned it.

The Little DreamThe API documentation is available at http://www.fmz.com/api#exchange.go...

The Little DreamStrategy is a teaching strategy, practical use. It can be modified, expanded, optimized.

The Little DreamThe source code is very simple and easy to understand.