avatar of 发明者量化-小小梦 发明者量化-小小梦
focar em Mensagem privada
4
focar em
1271
Seguidores

3.2 Template: Biblioteca de negociação de moeda digital (suporte integrado para spot e futuros OKCoin futures/BitVC)

Criado em: 2017-01-04 19:00:10, atualizado em: 2017-10-11 10:27:01
comments   19
hits   5333

3.2 Template: Biblioteca de negociação de moeda digital (suporte integrado para spot e futuros OKCoin futures/BitVC)


O Capítulo 3.1 apresenta um modelo de negociação em tempo real, o que simplifica muito a composição de uma estratégia em tempo real. No entanto, o processamento de negociação em futuros é muito diferente do que em tempo real, então o recurso de negociação em tempo real foi integrado com base no modelo em tempo real e agora está disponível.

3.2 Template: Biblioteca de negociação de moeda digital (suporte integrado para spot e futuros OKCoin futures/BitVC)

O blogueiro também publicou uma foto de uma das vítimas, no Twitter:

3.2 Template: Biblioteca de negociação de moeda digital (suporte integrado para spot e futuros OKCoin futures/BitVC)

  • ### Empréstimos:

A moeda digital é a mesma que a moeda digital de ouro, a moeda de ouro, que é a moeda de ouro.

  • ### Futuros:

parâmetro: 3.2 Template: Biblioteca de negociação de moeda digital (suporte integrado para spot e futuros OKCoin futures/BitVC)

3.2 Template: Biblioteca de negociação de moeda digital (suporte integrado para spot e futuros OKCoin futures/BitVC)

O código de teste da estratégia:

  function main() {
    if (exchange.GetName() === 'Futures_OKCoin') {
        var info = exchange.SetContractType("this_week");
        Log("info 返回值:", info);
        Log("当前持仓信息", exchange.GetPosition(), _C(exchange.GetTicker));
        var depth = exchange.GetDepth();
        var p = $.NewPositionManager();
        p.OpenShort("this_week", 10, depth.Bids[0].Price - 2);
        Log(exchange.GetPosition());
        Sleep(500 * 1000);
        depth = exchange.GetDepth();
        var ret = p.Cover("this_week", depth.Bids[0].Price + 2, 5);
        Log("cover ret:", ret);
        //LogProfit(p.Profit());
        Log(exchange.GetPosition());
        Log("-----------------------------测试分割线----------------------------------------");
        var depth = exchange.GetDepth();
        p.OpenLong("this_week", 20, depth.Bids[0].Price + 2);
        Log(exchange.GetPosition());
        Sleep(500 * 1000);
        depth = exchange.GetDepth();
        var ret = p.Cover("this_week", depth.Bids[0].Price - 2, 10, PD_LONG);
        Log("cover ret:", ret);
        Log(exchange.GetPosition());
        Log("-----------------------------测试分割线----------------------------------------");
        var ret = p.Cover("this_week", depth.Bids[0].Price - 3, 10, PD_LONG);
        Log("cover ret:", ret);
        var ret = p.Cover("this_week", depth.Bids[0].Price + 3, 5, PD_SHORT);
        Log("cover ret:", ret);
        Log(exchange.GetPosition());
    } else if (exchange.GetName() === 'Futures_BitVC') {
        var info = exchange.SetContractType("week");
        Log("info 返回值:", info);
        Log("当前持仓信息", exchange.GetPosition(), _C(exchange.GetTicker));
        var depth = exchange.GetDepth();
        var p = $.NewPositionManager();
        p.OpenLong("week", 500, depth.Bids[0].Price + 2);
        Log(exchange.GetPosition());
        Sleep(500 * 1000);
        depth = exchange.GetDepth();
        var ret = p.Cover("week", depth.Bids[0].Price - 2, 500);
        Log("cover ret:", ret);
        Log(exchange.GetPosition());
        Log("-----------------------------测试分割线----------------------------------------");
        var info = exchange.SetContractType("week");
        Log("info 返回值:", info);
        Log("当前持仓信息", exchange.GetPosition(), _C(exchange.GetTicker));
        var depth = exchange.GetDepth();
        p.OpenShort("week", 600, depth.Bids[0].Price - 2);
        Log(exchange.GetPosition());
        Sleep(500 * 1000);
        depth = exchange.GetDepth();
        var ret = p.Cover("week", depth.Bids[0].Price - 2, 500, PD_SHORT);
        Log("cover ret:", ret);
        Log(exchange.GetPosition());
        Log("-----------------------------测试分割线----------------------------------------");
        var ret = p.Cover("week", depth.Bids[0].Price + 3, 100, PD_SHORT);
        Log("cover ret:", ret);
        //p.Cover("week", depth.Asks[0].Price - 3, 300, PD_LONG);
        Log(exchange.GetPosition());
    } else if(exchange.GetName() === 'huobi' || exchange.GetName() === 'OKCoin'){
        Log($.GetAccount());
        Log($.Buy(0.5));
        Log($.Sell(0.5));
        exchange.Buy(1000, 3);
        $.CancelPendingOrders(exchanges[0]);
        Log($.Cross(30, 7));
        Log($.Cross([1,2,3,2.8,3.5], [3,1.9,2,5,0.6]));
    }
  }

Utilização: 3.2 Template: Biblioteca de negociação de moeda digital (suporte integrado para spot e futuros OKCoin futures/BitVC)

Código de teste na estratégia (selecionar o modelo de referência)

3.2 Template: Biblioteca de negociação de moeda digital (suporte integrado para spot e futuros OKCoin futures/BitVC)

Estratégia de teste:

function main(){
    var p = $.NewPositionManager();
    var i = 0;
    exchanges[0].SetContractType("this_week");
    var isFirst = true;
    var ret = null;
    while(true){
        var depth = _C(exchanges[0].GetDepth);
        var positions = _C(exchanges[0].GetPosition);
        var len = positions.length;
        if(isFirst === true && i % 3 === 0 && len === 0){
            ret = p.OpenLong("this_week", 1 + (i % 3) + (i % 2), depth.Asks[0].Price);
            isFirst = false;
        }else if(isFirst === false){
            ret = p.OpenShort("this_week", 1 + (i % 3) + (i % 2), depth.Bids[0].Price);
            isFirst = true;
        }else{
            for(var j = 0 ; j < len; j++){
                if(positions[j].Type === PD_LONG){
                    ret = p.Cover("this_week", depth.Bids[0].Price - 2, positions[j].Amount, PD_LONG);
                }else if(positions[j].Type === PD_SHORT){
                    ret = p.Cover("this_week", depth.Asks[0].Price + 2, positions[j].Amount, PD_SHORT);    
                }
                Log("ret:", ret);
            }
        }
        Log("ret", ret, "---------------------#FF0000");
        i++;
        Sleep(1000 * 60 * 15);
    }
}

Se você tiver alguma dúvida, BUG, entre em contato com o autor, obrigado!