O recurso está a ser carregado... Carregamento...

Detecte as políticas de interface GetAccount, GetTicker de várias exchanges Código

Autora:Inventor quantificado - sonho pequeno, Criado: 2018-03-09 20:00:48, Atualizado: 2018-03-11 15:09:33

Detecte as políticas de interface GetAccount, GetTicker de várias exchanges Código

O site do Facebook, que é o mais popular do mundo, mostra a lista de todas as principais bolsas de valores.

img

  • Código fonte do JavaScript (Executar diretamente sem parâmetros de política)
function E(obj) {
    if (!obj) {
        return obj
    }

    var cloneObj = function(obj) { // 深拷贝 对象函数
        var str, newobj = obj.constructor === Array ? [] : {};
        if (typeof obj !== 'object') {
            return;
        } else if (JSON) {
            str = JSON.stringify(obj); //系列化对象
            newobj = JSON.parse(str); //还原
        } else {
            for (var i in obj) {
                newobj[i] = typeof obj[i] === 'object' ?
                    cloneObj(obj[i]) : obj[i];
            }
        }
        return newobj;
    }

    if (obj && typeof(obj) == "object" && typeof(obj.Info) !== "undefined") {
        var newObj = cloneObj(obj)
        delete newObj.Info
        return newObj
    } else if (typeof(obj.length) == "number") {
        ///*
        var newArray = []
        for (var n = 0; n < obj.length; n++) {
            newArray.push(E(obj[n]))
        }
        return newArray
        //*/
        /*
        var newObj = cloneObj(obj)
        delete newObj.Info
        return newObj
        */
    } else {
        // Log(obj, "is not object or not have attribute 'Info'")
        return obj
    }
}

function main() {
    LogReset(1)
    var count = 0
    while(true){
        Log("第", count , "轮监测!", "#FF0000")
        count++
        var es = []
        for(var i = 0; i < exchanges.length; i++){
            if(exchanges[i].GetName().split("_")[0] == "Futures"){
                // BitMEX
                if(exchanges[i].GetName().split("_")[1] == "BitMEX"){
                    exchanges[i].SetContractType("XBTUSD")
                }
                // OKCoin
                if(exchanges[i].GetName().split("_")[1] == "OKCoin"){
                    exchanges[i].SetContractType("this_week")
                }
            }
            
            var beginTime = new Date().getTime()
            var ticker = exchanges[i].GetTicker()
            var endTickerTime = new Date().getTime()
            
            var account = exchanges[i].GetAccount()
            var endAccountTime = new Date().getTime()
            
            var e = {
                ticker : ticker ? "true #007FFF" : "false #FF0000" ,
                account : account ? "true #007FFF" : "false #FF0000" ,
                name : exchanges[i].GetName() ,
                tickerDelay : endTickerTime - beginTime ,
                accountDelay : endAccountTime - beginTime ,
            }
            Log(e.name, "延迟:", e.tickerDelay, "ticker:", E(ticker), e.ticker)
            Log(e.name, "延迟:", e.accountDelay, "account:", E(account), e.account)
            es.push(e)
        }
        
        var tab = {
            type : "table",
            title : "test",
            cols : ["name", "account", "Delay(ms)", "ticker", "Delay(ms)"],
            rows : [],
        }
        
        for(var j = 0; j < es.length; j++){
            tab.rows.push([es[j].name, es[j].account, es[j].accountDelay, es[j].ticker, es[j].tickerDelay])
        }
        
        LogStatus("更新于:", _D(), '\n`' + JSON.stringify(tab) + '`')
        Sleep(1000 * 30)
    }
}
  • Atualização para suporte a funções de proxy

    Adicionar dois parâmetros.

    Variações Descrição Tipo de variável Valor padrão
    isUseSetProxy Usar ou não um agente Bol (true/false) Falso
    IP_AddAndPass@isUseSetProxy== 1 Agente Configuração String (string) Socks5://username:password@127.0.0.1:8889

    É necessário configurar e configurar o serviço SS5 no servidor proxy (nome de usuário, senha, etc.)

    Quando estou a correr, os meus parâmetros são configurados assim: Socks5://botvs:botvs123456@174.XXX.XXX.XX:1080

    # - 代理服务器SS5服务 设置的 用户名: botvs
    # -                        密码: botvs123456
    # -                 代理服务器IP: 174.XXX.XXX.XX
    # -                        端口: 1080
    
function E(obj) {
    if (!obj) {
        return obj
    }

    var cloneObj = function(obj) { // 深拷贝 对象函数
        var str, newobj = obj.constructor === Array ? [] : {};
        if (typeof obj !== 'object') {
            return;
        } else if (JSON) {
            str = JSON.stringify(obj); //系列化对象
            newobj = JSON.parse(str); //还原
        } else {
            for (var i in obj) {
                newobj[i] = typeof obj[i] === 'object' ?
                    cloneObj(obj[i]) : obj[i];
            }
        }
        return newobj;
    }

    if (obj && typeof(obj) == "object" && typeof(obj.Info) !== "undefined") {
        var newObj = cloneObj(obj)
        delete newObj.Info
        return newObj
    } else if (typeof(obj.length) == "number") {
        ///*
        var newArray = []
        for (var n = 0; n < obj.length; n++) {
            newArray.push(E(obj[n]))
        }
        return newArray
        //*/
        /*
        var newObj = cloneObj(obj)
        delete newObj.Info
        return newObj
        */
    } else {
        // Log(obj, "is not object or not have attribute 'Info'")
        return obj
    }
}

function main() {
    LogReset(1)
    var count = 0
    
    if(isUseSetProxy){
        var ret
        for(var n = 0; n < exchanges.length; n++){
        ret = exchanges[n].SetProxy(IP_AddAndPass)
        }
        Log("设置代理为:", IP_AddAndPass, ret, "#FF0000")
    }
    
    while(true){
        Log("第", count , "轮监测!", "#FF0000")
        count++
        var es = []
        for(var i = 0; i < exchanges.length; i++){
            if(exchanges[i].GetName().split("_")[0] == "Futures"){
                // BitMEX
                if(exchanges[i].GetName().split("_")[1] == "BitMEX"){
                    exchanges[i].SetContractType("XBTUSD")
                }
                // OKCoin
                if(exchanges[i].GetName().split("_")[1] == "OKCoin"){
                    exchanges[i].SetContractType("this_week")
                }
            }
            
            var beginTime = new Date().getTime()
            var ticker = exchanges[i].GetTicker()
            var endTickerTime = new Date().getTime()
            
            var account = exchanges[i].GetAccount()
            var endAccountTime = new Date().getTime()
            
            var e = {
                ticker : ticker ? "true #007FFF" : "false #FF0000" ,
                account : account ? "true #007FFF" : "false #FF0000" ,
                name : exchanges[i].GetName() ,
                tickerDelay : endTickerTime - beginTime ,
                accountDelay : endAccountTime - beginTime ,
            }
            Log(e.name, "延迟:", e.tickerDelay, "ticker:", E(ticker), e.ticker)
            Log(e.name, "延迟:", e.accountDelay, "account:", E(account), e.account)
            es.push(e)
        }
        
        var tab = {
            type : "table",
            title : "test",
            cols : ["name", "account", "Delay(ms)", "ticker", "Delay(ms)"],
            rows : [],
        }
        
        for(var j = 0; j < es.length; j++){
            tab.rows.push([es[j].name, es[j].account, es[j].accountDelay, es[j].ticker, es[j].tickerDelay])
        }
        
        LogStatus("更新于:", _D(), '\n`' + JSON.stringify(tab) + '`')
        Sleep(1000 * 30)
    }
}

Mais.