예제 #1
0
파일: dbmd.py 프로젝트: xiebing77/xquant
 def get_latest_time(self, symbol, kline_type):
     collection = kl.get_kline_collection(symbol, kline_type)
     interval = timedelta(seconds=kl.get_interval_seconds(kline_type))
     klines = self.md_db.find_sort(collection, {}, self.kline_key_open_time,
                                   -1, 1)
     if len(klines) <= 0:
         return None
     return (self.get_kline_open_time(klines[0]) + interval)
예제 #2
0
def chart(title,
          md,
          symbol,
          interval,
          start_time,
          end_time,
          ordersets,
          args,
          signalsets=[]):
    display_count = int((end_time - start_time).total_seconds() /
                        kl.get_interval_seconds(interval))
    print("display_count: %s" % display_count)

    klines = md.get_klines(symbol, interval, 150 + display_count)
    chart_mpf(title, args, symbol, ordersets, klines, md, display_count,
              signalsets)
예제 #3
0
def chart(title,
          md,
          symbol,
          interval,
          start_time,
          end_time,
          ordersets,
          args,
          signalsets=[]):
    display_count = int((end_time - start_time).total_seconds() /
                        kl.get_interval_seconds(interval))
    print("display_count: %s" % display_count)

    #klines = md.get_klines(symbol, interval, 150+display_count)
    klines = md.get_original_klines(kl.get_kline_collection(symbol, interval),
                                    start_time, end_time)
    #print("klines: %s"%klines)
    if len(klines) > 0:
        chart_mpf(title, args, symbol, ordersets, klines, md, display_count,
                  signalsets)
예제 #4
0
import common.kline as kl
from exchange.binanceExchange import BinanceExchange
from setup import *
import pandas as pd
from importer import add_common_arguments, split_time_range

if __name__ == "__main__":
    parser = add_common_arguments('Binance Importer')
    args = parser.parse_args()
    # print(args)
    if not (args.s and args.k and args.m):
        parser.print_help()
        exit(1)

    symbol = args.s
    interval = timedelta(seconds=kl.get_interval_seconds(args.k))

    collection = kl.get_kline_collection(symbol, args.k)
    #print("collection: ", collection)

    db = md.MongoDB(mongo_user, mongo_pwd, args.m, db_url)
    db.ensure_index(collection, [("open_time",1)], unique=True)

    # 注意,下面代码有隐患,在上午8点前取1d、12h时,最后的一个是不完整的,后续再整改
    if args.r:
        start_time, end_time = split_time_range(args.r)
    else:
        # 续接db中最后一条记录,至今天之前
        klines = db.find_sort(collection, {}, 'open_time', -1, 1)
        if len(klines) > 0:
            start_time = (datetime.fromtimestamp(klines[0]["open_time"]/1000) + interval).replace(hour=0,minute=0,second=0,microsecond=0)
예제 #5
0
파일: fix.py 프로젝트: xiebing77/xquant
if __name__ == "__main__":
    parser = add_common_arguments('fix')
    args = parser.parse_args()
    # print(args)

    if not (args.s and args.r and args.k and args.m):
        parser.print_help()
        exit(1)

    start_time, end_time = split_time_range(args.r)

    interval = args.k
    collection = kl.get_kline_collection(args.s, interval)
    td = kl.get_interval_timedelta(interval)
    period = kl.get_interval_seconds(interval)
    tick_time = kl.get_open_time(interval, start_time)
    if tick_time < start_time:
        tick_time = kl.get_open_time(interval, start_time+td)

    db = md.MongoDB(mongo_user, mongo_pwd, args.m, db_url)

    klines = db.find_sort(collection, {"open_time": {
        "$gte": int(start_time.timestamp())*1000,
        "$lt": int(end_time.timestamp())*1000}}, 'open_time', 1)

    i = 0
    miss_count = 0
    print(len(klines))

    period_ms = period * 1000
예제 #6
0
파일: show.py 프로젝트: leezizi/xquant
    parser.add_argument('-s', help='symbol (btc_usdt)')
    parser.add_argument('-i', help='interval')
    parser.add_argument('-r', help='time range')
    #parser.add_argument('-di', nargs='*', help='display indicators,egg: MACD KDJ RSI')

    parser.add_argument('--volume', action="store_true", help='volume')
    parser.add_argument('--okls', nargs='*', help='other klines')
    chart_add_all_argument(parser)

    args = parser.parse_args()
    # print(args)

    if not (args.r and args.i and args.s and args.e):
        parser.print_help()
        exit(1)

    symbol = args.s
    interval = args.i
    start_time, end_time = ts.parse_date_range(args.r)
    display_count = int((end_time - start_time).total_seconds()/kl.get_interval_seconds(interval))
    print("display_count: %s" % display_count)

    md = DBMD(args.e)
    md.tick_time = datetime.now()

    title = symbol + '  ' + interval

    ordersets = []
    chart(title, md, symbol, interval, start_time, end_time, ordersets, args)

예제 #7
0
    parser.add_argument('-s', help='symbol (btc_usdt)')
    parser.add_argument('-i', help='interval')
    parser.add_argument('-r', help='time range')
    #parser.add_argument('-di', nargs='*', help='display indicators,egg: MACD KDJ RSI')

    parser.add_argument('--volume', action="store_true", help='volume')
    parser.add_argument('--okls', nargs='*', help='other klines')
    chart_add_all_argument(parser)

    args = parser.parse_args()
    # print(args)

    if not (args.r and args.i and args.s and args.e):
        parser.print_help()
        exit(1)

    symbol = args.s
    interval = args.i
    start_time, end_time = ts.parse_date_range(args.r)
    display_count = int((end_time - start_time).total_seconds() /
                        kl.get_interval_seconds(interval))
    print("display_count: %s" % display_count)

    md = DBMD(args.e)
    md.tick_time = datetime.now()

    title = symbol + '  ' + interval

    ordersets = []
    chart(title, md, symbol, interval, start_time, end_time, ordersets, args)