def get_data_allocate(strategy, data_type): dd = Calendar.today() a = Calendar.in_business(dd, day=True) if (a == False): print('非工作日!') exit(0) t1 = time.clock() print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) command = "python {}\daily_{}_{}.py".format(project_dir, data_type, strategy) list = [] if (strategy == 'min5'): list = get_min5_time() if (strategy == 'min15'): list = get_min15_time() if (strategy == 'min30'): list = get_min30_time() if (strategy == 'min60'): list = get_min60_time() if (strategy == 'day'): list = get_day_time() print(strategy) while True: # if in_business(datetime.now(), strategy, True): x = datetime.now().hour * 60 + datetime.now().minute # print ( datetime.now().hour,datetime.now().minute) # print(x) # if(x>list[-1]): if (x > list[-1]): print(list[-1]) print('收盘!') exit(0) if (x == 11 * 60 + 45): print('上午结束') exit(0) if (x in list): print('finded') t1 = time.clock() subprocess.call(command, shell=True) t3 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) print(t3) dit = {'date': t3, 'status': 1, 'kline': strategy, 'other': ''} model_list['kline_data_update_mark'].insert(dit) t2 = time.clock() a = (change_status(strategy)['time']) - ((t2 - t1) / 60) print(a) if (a > 0): time.sleep(a * 60) print('睡眠结束') else: print('finding:') time.sleep(10)
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')
# -*- 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)
def gt(*args): _ = args[0] obj = model_list['XDXR_' + _['category']] obj.insert_batch( calc_xdxr_specified(stock_code_list=_['stock_code_list'], category_name=_['category'], start_date=_['start_date'], end_date=_['end_date'])) # calc_xdxr_specified(stock_code_list=[600015], category_name=_['category'], start_date=_['start_date'], # end_date=_['end_date']) if __name__ == '__main__': d = Calendar.today() if not Calendar.in_business(dt=d, day=True): print('not_ok') exit() print('0000') strategy = 'XDXR_day' # day_XDXR ���ܸIJ��ܸIJ��ܸ�Ӵ try: print('in') mm = ['sz', 'sh'] s = list() sd = None ed = None 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)