示例#1
0
文件: check.py 项目: SPWW/xquant
                    print(
                        ts, " ~ ", klines[i]["open_time"], " ~ ", i, " ~ ",
                        datetime.fromtimestamp(klines[i]["open_time"] / 1000))
                    i += 1

        tick_time += td

    if not miss_start:
        exit(1)

    print("miss start: %s, count: %d " % (miss_start, miss_count))

    if args.k == "1min":
        interval = 60 * 1000
        klines = exchange.get_klines_1min(args.s,
                                          size=miss_count,
                                          since=miss_start)
    elif args.k == "1day":
        interval = 24 * 60 * 60 * 1000
        klines = exchange.get_klines_1day(args.s,
                                          size=miss_count,
                                          since=miss_starts)

    klines_df = pd.DataFrame(klines, exchange.get_kline_column_names())

    records = klines_df.to_dict('records')
    tmp_ts = miss_start
    for record in records:
        if record["open_time"] != tmp_ts:
            print("从交易所获取的k线不符合预期")
            print("tmp_ts: %d  miss" % tmp_ts)
示例#2
0
        exit(1)

    print("collection: ", collection)
    size = 1000
    tmp_time = start_time

    while tmp_time < end_time:
        print(datetime.fromtimestamp(tmp_time / 1000))
        if (tmp_time + size * interval) > end_time:
            batch = int((end_time - tmp_time) / interval)
        else:
            batch = size
        # print(batch)
        if args.k == "1min":
            klines = exchange.get_klines_1min(symbol,
                                              size=batch,
                                              since=tmp_time)
        elif args.k == "1day":
            klines = exchange.get_klines_1day(symbol,
                                              size=batch,
                                              since=tmp_time)

        klines_df = pd.DataFrame(klines, exchange.get_kline_column_names())

        #klen = len(klines)
        #print("klines len: ", klen)
        #print(klines)
        #print("klines[0]: ", klines.ix[0])
        #print("klines[-1]: ", klines.ix[klen-1])
        #print("records: ", klines.to_dict('records'))
        db.insert_many(collection, klines_df.to_dict('records'))