Exemple #1
0
def main(argv):
    #get_all_tick_data('000001')
    try:
        opts, args = getopt.getopt(argv[1:], "dhe:m:i:t:s:a:")
    except getopt.GetoptError as err:
        print(err)
        return -1
    log_level = logging.INFO
    mode = ''
    index = 0
    thread = 1
    symbol = '000000'
    date = date_time.get_today_str()
    for ok, ov in opts:
        if ok in ('-d', '--debug'):
            log_level = logging.DEBUG
        if ok in ('-e', '--expire'):
            global g_expire
            g_expire = int(ov)
        if ok in ('-m', '--mode'):
            mode = ov
        if ok in ('-i', '--index'):
            index = int(ov)
        if ok in ('-t', '--thread'):
            thread = int(ov)
        if ok in ('-s', '--symbol'):
            symbol = ov
        if ok in ('-a', '--date'):
            date = ov
        if ok in ('-h', '--help'):
            help()
            return

    logging.basicConfig(
        level=log_level,
        format=
        '%(levelname)s: %(asctime)s [%(pathname)s:%(lineno)d] %(message)s',
        datefmt='%Y-%M-%d %H:%M:%S',
        filename=CT.LOG_DIR + 'tick.log',
        filemode='a')

    log_str = 'running model[%s] index[%d] thread[%d] symbol[%s] date[%s]' % (
        mode, index, thread, symbol, date)
    print(log_str)
    logging.info(log_str)
    if mode == 'symbol':
        get_tick_data_symbol(symbol, index, thread)
    elif mode == 'date':
        get_tick_data_date(date, index, thread)
    elif mode == 'allsince':
        get_tick_data_since(date, index, thread)
    elif mode == 'since':
        get_symbol_tick_data_since(symbol, date)
    elif mode == 'tick':
        q = Quotation()
        q.get_tick_data(symbol, date)
    else:
        print(('args err mode[%s]' % (mode)))
        logging.error('args err mode[%s]' % (mode))
    return
Exemple #2
0
def get_symbol_tick_data_since(symbol, date):
    """
    获取一支股票从指定日期至今所有的tick数据
    --------
    symbol: string,000001
    date: string,1900-01-01
    """
    since = date_time.str_to_date(date)
    today = datetime.datetime.today()
    days = (today - since).days
    q = Quotation()
    for delta in range(0, days + 1):
        day = date_time.compute_date(since, delta)
        q.get_tick_data(symbol, day)

    return True
Exemple #3
0
def get_tick_data_date(date, index, thrd_cnt):
    """
    获取一天内所有股票tick数据
    """
    symbols = open(CT.BASICS_DIR + 'symbols.csv')
    symbols_list = []
    for c in symbols:
        symbols_list.append(c.strip())

    sep_list_len = (len(symbols_list) + thrd_cnt - 1) / thrd_cnt

    start = sep_list_len * index
    end = sep_list_len * (index + 1)
    sep_symbols_list = symbols_list[start:end]
    q = Quotation()
    for s in sep_symbols_list:
        q.get_tick_data(s, date)
    return True
 def test_get_tick_data(self):
     q = Quotation()
     d = q.get_tick_data('000001', '2021-03-05')
     self.assertTrue(len(d) > 100)
Exemple #5
0
 def run(self):
     q = Quotation()
     for date in self.dates:
         q.get_tick_data(self.symbol, date)