示例#1
0
def get_kline_data(strategy):
    # print('kline_in')
    # file_log(strategy,'time:'+str(datetime.now())+'\n'+'op:start')
    # t = Calendar.today()
    print('step into')
    t = Calendar.today()
    # 111=555
    if Calendar().query(date=t):
        mm = ['sh', 'sz']
        # cc = ['day', 'min60', 'min30', 'min15', 'min5']
        cc = [strategy]
        strategy = 'kline_' + strategy
        s = list()
        # ss = datetime.now()
        # print(ss)
        for m in mm:
            sl = get_stock_code_list(markets[m])
            num = 10
            aa = (lambda a: map(lambda b: a[b:b + num], range(0, len(a), num))
                  )(sl)
            print(aa)
            for a in aa:
                for k in cc:
                    s.append(
                        dict(market=m,
                             category=k,
                             stock_code_list=a,
                             start_date=None,
                             end_date=None))
        # e = datetime.now()
        # print(e)
        # file_log(strategy, 'time:' + str(datetime.now()) + '\n' + 'op:get stock_code')
        print('step getstocks')
        model_list[strategy].remove(date=t)
        print('remove over')
        # file_log(strategy, 'time:' + str(datetime.now()) + '\n' + 'op:remove today')
        # f = datetime.now()
        # print(f)

        pool = Pool(10)
        pool.map(gt_kline, s)
        # for i in s:
        #     gt_kline(i)

        # pool.close()
        # pool.join()

        # print('s=',s)
        # p = multiprocessing.Process(target=gt_kline, args=s)
        # p.start()
        # p.join(timeout=300)
        # for i in s:
        #     gt_kline(i)
        # model_list[strategy].remove(volume=0)
        # file_log(strategy, 'time:' + str(datetime.now()) + '\n' + 'op:complate')
        print('kline_done')
        return 0
示例#2
0
def get_kline_data(strategy):
    """
    this function acts on kline
    first get all stock code
    then call the function named get_kline by multiprocessing
    :param strategy:
    :return:
    """
    dd = Calendar.today()
    if not Calendar.in_business(dt=Calendar.today(), day=True):
        exit()
    print('kline_in')
    # t = Calendar.today()
    st = None
    et = None
    t = Calendar.today()
    if Calendar().query(date=t):
        mm = ['sh', 'sz']
        #cc = ['day', 'min60', 'min30', 'min15', 'min5']
        cc = [strategy]
        strategy = 'kline_' + strategy
        s = list()
        for m in mm:
            sl = get_stock_code_list(markets[m])
            num = 50
            aa = (lambda a: map(lambda b: a[b:b + num], range(0, len(a), num))
                  )(sl)
            for a in aa:
                for k in cc:
                    s.append(
                        dict(market=m,
                             category=k,
                             stock_code_list=a,
                             start_date=st,
                             end_date=et))
        # if st == None and et == None:
        # model_list[strategy].remove(date=t)
        # else:
        # sql = analyzer('date >= {} and date <= {}'.format(st, et))
        # model_list[strategy].remove(sql)

        pool = multiprocessing.Pool(processes=10)
        for i in s:
            pool.apply_async(gt_kline, (i, ))
        pool.close()
        pool.join()
        # for i in s:
        #     gt_kline(i)
        # model_list[strategy].remove(volume=0)
        print('-----------------' + str())
        print('kline_done')
示例#3
0
def get_kline_data(strategy):
    print('kline_in')
    t = Calendar.today()
    if Calendar().query(date=t):
        mm = ['sh', 'sz']
        cc = [strategy]
        strategy = 'kline_' + strategy
        s = list()
        for m in mm:
            sl = get_stock_code_list(markets[m])
            num = 50
            aa = (lambda a: map(lambda b: a[b:b + num], range(0, len(a), num))
                  )(sl)
            for a in aa:
                for k in cc:
                    s.append(
                        dict(market=m,
                             category=k,
                             stock_code_list=a,
                             start_date=None,
                             end_date=None))

        # model_list[strategy].remove(date=t)
        # model_list['kline_min15'].remove(date=t)
        # model_list['kline_min5'].remove(date=t)
        # model_list['kline_min30'].remove(date=t)
        # model_list['kline_min60'].remove(date=t)
        # model_list['kline_day'].remove(date=t)
        print("((((((((((((")
        print(len(s))
        freeze_support()
        pool = Pool(5)
        r = pool.map(gt_kline, s)
        df = pd.concat(r, join='outer', ignore_index=False)
        df.reset_index(inplace=True)
        # print(df.head(10))
        pool.close()
        pool.join()
        return df
    sd = _['start_date']
    ed = _['end_date']
    his = _['his']
    for s_c in _['stock_code_list']:
        day_feature(s_c, sd, ed, his)


if __name__ == '__main__':
    s = list()
    market_name = ["sz", 'sh']
    sd = None
    ed = None

    mm = ['sz', 'sh']
    for m in mm:
        stock_codes = get_stock_code_list(markets[m])
        sl = len(stock_codes)
        t = int(ceil(sl * 1.0 / cpus))
        for i in range(cpus):
            s.append(dict(stock_code_list=stock_codes[i * t: (i + 1) * t], market_name=m,
                          start_date=sd,
                          end_date=ed,
                          his=True))
    print('done')
    model_list['feature_day'].remove(analyzer('date >= {} and date <= {}'.format(sd, ed)))
    freeze_support()
    pool = Pool(cpus)
    pool.map(gt, s)
    pool.close()
    pool.join()
    print('ok')
示例#5
0
# -*- coding: utf-8 -*-

from os.path import abspath, pardir, join
from sys import path

from app import markets
from app.models import Calendar
from app.actions import get_stock_code_list, get_xdxr

path.append(abspath(join(abspath(join(abspath(__file__), pardir)), pardir)))

if __name__ == '__main__':
    if not Calendar.in_business(dt=Calendar.today(), day=True):
        exit()
    start_date = None
    end_date = None
    stock_code_list = []
    for m in ['sh', 'sz']:
        stock_code_list = get_stock_code_list(market=markets[m])
        get_xdxr(market_name=m,
                 stock_code_list=stock_code_list,
                 start_date=start_date,
                 end_date=end_date)