The resource loading... loading...

Get the K-line from a third-party website (0804 updates)

Author: The number is crazy., Date: 2016-04-08 00:01:57
Tags: Extent-API

For platforms that do not support obtaining K-string data (BitVC futures, BTC spot for BTCCC, ETH for Chinese Bitcoin, ETC), this template can be used to obtain the platform's historical K-string data directly from a third-party website if enough K-string data must be obtained at the start of the strategy. Please note: K-line data is updated every 3 seconds, so high-frequency calls are not possible. This applies only to real-world transactions. The authors do not guarantee the accuracy of third-party data and the correctness of the procedure, only for educational reference.

0427 Update: An exception may be thrown when Parse JSON data is processed, returning a uniform value of null when an exception occurs.



$.AltRecords = function(exchange, timeframe, size, includeLastBar) {
    var symbol;
    var info;
    var record = [];
    if (!size) size="";
    // 目前只支持以下三个交易所,其余交易所接口可参考https://www.btc123.com/api
    if (exchange.GetName().indexOf('Futures_BitVC') != -1) { 
        symbol = "bitvcbtccnyfuture";
    }
    else if (exchange.GetName().indexOf('BTCC') != -1 && exchange.GetCurrency().indexOf('BTC') != -1) {
        symbol = "btcchinabtccny";
    }
    else if (exchange.GetName().indexOf('CHBTC') != -1 && exchange.GetCurrency().indexOf('ETH') != -1) {
        symbol = "chbtcethcny";
    }
    else if (exchange.GetName().indexOf('CHBTC') != -1 && exchange.GetCurrency().indexOf('ETC') != -1) {
        symbol = "chbtcetccny";
    }
    
    if (symbol) {
        try {
            info = JSON.parse(HttpQuery('https://www.btc123.com/market/kline?symbol='+symbol+'&type='+timeframe+'&size='+(includeLastBar ? size : size+1)));
            if (info && info.isSuc) {
                info = JSON.parse(info.datas.data);
            }
            else {
                Log("获取K线时发生错误:", info && info.des ? info.des : "网络错误");
                return null;
            }
        } catch (e) {
            Log("获取K线时发生错误:", info && info.des ? info.des : "网络错误");
            return null;
        }
        for (var i = 0; i < (includeLastBar ? info.length : info.length-1); i++) {
            record.push({"Time": info[i][0], "Open": info[i][1], "High": info[i][2], "Low": info[i][3], "Close": info[i][4], "Volume": info[i][5]});
        }
        return record;
    }
    return exchange.GetRecords(); // 不支持的交易所采用默认方式处理(忽略所有参数,如时间周期、长度等)。
};

function main() {
    Log(exchange.GetName());
    var rec = $.AltRecords(exchange, "5min", 100); // 获取5分钟K线, 100条, 不含最后一条Bar
    if (rec) Log(rec.length, rec[rec.length-1]);
    rec = $.AltRecords(exchange, "4hour", 100, 1); // 获取4小时K线, 100条, 含最后一条Bar
    if (rec) Log(rec.length, rec[rec.length-1]);
}

Related

More

The bride too.Good things.

kirinI hope that the traditional futures market can also provide an example.

JIt's good, put it down.

The NinjaGood stuff, thanks for sharing

The short-line king won selling the high-price strategyIt's good, but I haven't figured it out yet.