websocket 버전 OKEX 연장간 헤지킹 전략 (교육)

저자:작은 꿈, 날짜: 2019-04-17 10:10:55
태그:울타리웹스코켓

매우 간결한 버전의 OKEX 연장 헤지킹 전략 (교육)

  • 실제 사진:img

  • 이 모든 것은 단지 정서일 뿐이고, 반서는 수정될 수 있고, 계약은 교체될 수 있다.

  • 두 개의 거래소 객체를 추가합니다. 첫 번째 분기, 두 번째 주간.

  • 모든 단순화 가능한 코드를 간소화하고, 최적화 할 수있는 공간이 많으며, 교육 전략은 신중하고, 시간이 넘어가면 위험이 있습니다.

  • 다른 가격으로 주문하십시오.

  • 이 글은 이 부분의 다른 부분과 같습니다.

교육 전략, 실제 사용.

교육 전략, 실제 사용.

교육 전략, 실제 사용.


function Hedge (isOpen, retSetA, retSetB) {
    exchanges[0].SetDirection(isOpen ? "sell" : "closesell")
    exchanges[1].SetDirection(isOpen ? "buy" : "closebuy");
    (function (routineA, routineB) {
        Log(routineA.wait(), routineB.wait(), retSetA, retSetB)
    })(exchanges[0].Go(isOpen ? "Sell" : "Buy", -1, _ContractNum), exchanges[1].Go(isOpen ? "Buy" : "Sell", -1, _ContractNum))
}

function main () {
    var param = {"op": "subscribe", "args": ["futures/ticker:" + _Instrument_id_A, "futures/ticker:" + _Instrument_id_B]}
    var client = Dial("wss://real.okex.com:8443/ws/v3|compress=gzip_raw&mode=recv&reconnect=true&payload=" + JSON.stringify(param))
    client.write(JSON.stringify(param))
    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})
    }
    while (1) {
        var tab = {type: "table", title: "状态", cols: ["节点信息"], rows: []}
        Sleep(10) 
        var ret = client.read(-2)
        if (!ret || ret == "") {
            continue
        }

        var obj = null
        try {
            obj = JSON.parse(ret)
        } catch (e) {
            Log(e)
            continue
        }

        if (obj.table == "futures/ticker" && obj.data[0].instrument_id == _Instrument_id_A) {   
            tickerA = obj.data[0]
        } else if (obj.table == "futures/ticker" && obj.data[0].instrument_id == _Instrument_id_B) {
            tickerB = obj.data[0]
        }

        if (tickerA && tickerB) {
            $.PlotLine(tickerA.instrument_id + "-" + tickerB.instrument_id, tickerA.last - tickerB.last)
            for (var j = 0 ; j < arr.length; j++) {
                if (tickerA.best_bid - tickerB.best_ask > arr[j].open && !arr[j].isHold) {   
                    Hedge(true, exchanges[0].SetContractType("quarter"), exchanges[1].SetContractType("this_week"))
                    arr[j].isHold = true
                }
                if (tickerA.best_ask - tickerB.best_bid < arr[j].cover && arr[j].isHold) {
                    Hedge(false, exchanges[0].SetContractType("quarter"), exchanges[1].SetContractType("this_week"))
                    arr[j].isHold = false 
                }
                tab.rows.push([JSON.stringify(arr[j])])
            }
        }
        LogStatus(_D(), "\n `" + JSON.stringify(tab) + "`")
    }
}

관련

더 많은

차오이제 V5이 아니죠? OK V5는 이제 개인 채널입니다.

제이미를 사랑해요이 모든 것이 어떻게 해결될 수 있는지에 대한 질문입니다. 시간 플랫폼 유형 가격 수량 정보 2021-02-13 00:00:00 오류 main:12:12 - TypeError: Cannot read property 'write' of undefined 문자를 입력할 수 없습니다 2021-02-13 00:00:00 오류 샌드박스 지원되지 않습니다 다이얼

fmzero교육용 비디오는 어디 있어요?

작은 꿈다이얼 함수를 지원하지 않는 경우, 이 정책은 다이얼할 수 없습니다.