Esempio n. 1
0
def getKrakenData(interval=1440, since=0):
    directory = krakenutl.SRCDIR
    if not os.path.exists(directory):
        os.makedirs(directory)
    for p in krakenutl.PAIRS:
        logger.debug('download data for: ' + p + ' interval: ' +
                     str(interval) + ' since:' +
                     str(krakenutl.localTimeFromEpoch(since)))
        pdata = getOhlc(p, interval, since)
        storeHdf5(pdata, krakenutl.getTagFromPair(p, interval),
                  krakenutl.getH5source())
Esempio n. 2
0
def getOhlc(pair, interval=1440, since=0):
    last = since
    last1 = -1
    totEntr = 0

    columns = [
        "time", "open", "high", "low", "close", "vwap", "volume", "count"
    ]
    df = pd.DataFrame(columns=columns)
    while last1 != last:
        body = {"pair": pair, "interval": interval, "since": last}
        url = 'https://api.kraken.com/0/public/OHLC'
        try:
            logger.debug(body)
            r = rest.restPOST(url, body)
            if not "result" in r.keys():
                break

            #print r
            last1 = last
            last = r["result"]["last"] if "last" in r["result"].keys() else 0
            ent = len(r["result"][pair])
            logger.debug('ent: ' + str(ent))
            totEntr = totEntr + ent
            #pivot data into  multi l=column format
            d = r["result"][pair]
            if len(columns) != len(d[0]):
                logger.error("len(columns)!=len(d) " + str(len(columns)) +
                             " " + str(len(d)))
                return None

            for i in range(0, len(d)):
                d[i][0] = krakenutl.localTimeFromEpoch(d[i][0])
                df.loc[i] = [krakenutl.toUtf8(x) for x in d[i]]

            time.sleep(1)
        except Exception as e:
            logger.error('Exception while calling: ' + url + " exception: " +
                         str(e))
            return None

    logger.debug("Total entries: " + str(totEntr))
    df = df.drop_duplicates("time").set_index("time").sort_index()
    #remove the last row the data may not be complete
    df.drop(df.index[len(df) - 1], inplace=True)
    return df
Esempio n. 3
0
def getOhlc(pair,interval=1440,since=0):
    last = since
    last1 = -1
    totEntr = 0

    columns = ["time", "open", "high", "low", "close", "vwap", "volume", "count"]
    df=pd.DataFrame(columns=columns)
    while last1!=last:
        body={
        "pair":pair,
        "interval":interval,
        "since":last
        }
        url = 'https://api.kraken.com/0/public/OHLC'
        try:
            logger.debug(body)
            r = rest.restPOST(url,body)
            if not "result" in r.keys():
                break
                
            #print r
            last1=last
            last = r["result"]["last"] if "last" in r["result"].keys() else 0
            ent=len(r["result"][pair])
            logger.debug('ent: '+str(ent))
            totEntr = totEntr+ent
            #pivot data into  multi l=column format
            d=r["result"][pair]
            if len(columns)!=len(d[0]):
                logger.error("len(columns)!=len(d) "+str(len(columns))+" "+str(len(d)))
                return None
                
            for i in range(0,len(d)):
                d[i][0]=krakenutl.localTimeFromEpoch(d[i][0])
                df.loc[i]=[krakenutl.toUtf8(x) for x in d[i]]

            time.sleep(1)
        except Exception as e:
            logger.error('Exception while calling: '+url+" exception: "+str(e))
            return None
            
    logger.debug("Total entries: "+str(totEntr))
    df= df.drop_duplicates("time").set_index("time").sort_index()
    #remove the last row the data may not be complete
    df.drop(df.index[len(df)-1], inplace=True)
    return df
Esempio n. 4
0
def getKrakenData(interval=1440,since=0):
    directory = krakenutl.SRCDIR
    if not os.path.exists(directory):
        os.makedirs(directory)
    for p in krakenutl.PAIRS:
        logger.debug('download data for: '+p+' interval: '+str(interval)+' since:'+str(krakenutl.localTimeFromEpoch(since)))
        pdata = getOhlc(p, interval,since)
        storeHdf5(pdata,krakenutl.getTagFromPair(p,interval),krakenutl.getH5source())