Пример #1
0
    def test_QA_SU_save_stock_day_lastdate(self):
        # 交易时间QA.QAFetch.QATdx.QA_fetch_get_stock_day返回的数据会实时更新
        codelist = QA.QA_fetch_stock_list_adv().code.tolist()
        days = 300
        start = datetime.datetime.now() - datetime.timedelta(days)
        end = datetime.datetime.now()
        if QA_util_if_tradetime(end):
            end2 = end - datetime.timedelta(1)
        else:
            end2 = end
        codeListCount = 200
        a = time.time()
        ps = Parallelism(cpu_count())
        data1 = QA.QAFetch.QATdx.QA_fetch_get_stock_day(
            codelist[0], start, end)
        data2 = QA.QAFetch.QATdx.QA_fetch_get_stock_day(
            codelist[0], start, end2)
        # 交易时间段
        self.assertTrue(
            len(data1) == len(data2),
            '数据长度:{} {} 日期: {} {}'.format(len(data1), len(data2), end, end2))
        print('数据长度:{} {} 日期: {} {}'.format(len(data1), len(data2), end, end2))
        print('当前数据: {} {}'.format(data1.close[-1], data2.close[-1]))

        # 设定在交易时间内
        end = datetime.datetime(end.year, end.month, end.day, 10, 0)
        end2 = end
        while not QA_util_if_tradetime(end):
            end = end - datetime.timedelta(1)
        end = end - datetime.timedelta(7)
        codeListCount = 200
        a = time.time()
        ps = Parallelism(cpu_count())
        data1 = QA.QAFetch.QATdx.QA_fetch_get_stock_day(
            codelist[0], start, end)
        data2 = QA.QAFetch.QATdx.QA_fetch_get_stock_day(
            codelist[0], start, end2)
        # 交易时间段
        self.assertFalse(
            len(data1) == len(data2),
            '数据长度应不等:{} {} 日期: {} {}'.format(len(data1), len(data2), end,
                                             end2))
        print('数据长度:{} {} 日期: {} {}'.format(len(data1), len(data2), end, end2))
        print('当前数据: {} {}'.format(data1.close[-1], data2.close[-1]))
Пример #2
0
 def test_gen_param(self):
     codelist = QA.QA_fetch_stock_list_adv().code.tolist()
     days = 300
     start = datetime.datetime.now().date() - datetime.timedelta(days)
     end = datetime.datetime.now().date() - datetime.timedelta(10)
     codeListCount = 200
     ips = get_ip_list_by_multi_process_ping(QA.QAUtil.stock_ip_list,
                                             _type='stock')
     param = gen_param(codelist[:codeListCount],
                       start,
                       end,
                       IPList=ips[:cpu_count()])
     a = time.time()
     ps = Parallelism(cpu_count())
     ps.run(QA.QAFetch.QATdx.QA_fetch_get_stock_day, param)
     data = ps.get_results()
     b = time.time()
     t1 = b - a
     data = list(data)
     print('返回数据{}条,用时:{}秒'.format(len(data), t1))
     # print(data)
     # print([x.code.unique() for x in data])
     self.assertTrue(
         len(data) == codeListCount,
         '返回结果和输入参数个数不匹配: {} {}'.format(len(data), codeListCount))
     i, j = 0, 0
     for x in data:
         try:
             # print(x)
             i += 1
             self.assertTrue((x is None) or (len(x) > 0),
                             '返回数据太少:{}'.format(len(x)))
             if not ((x is None) or (len(x) > 0)):
                 print('data is None')
             if i % 10 == 0:
                 print(x)
         except Exception as e:
             j += 1
     print(i, j)