예제 #1
0
    def _run(self):
        src_dir = self.config['tdx']['dir']
        dest_dir = self.config['hdf5']['dir']
        hdf5_import_progress = {'SH': {'DAY': 0, '1MIN': 0, '5MIN': 0},
                                'SZ': {'DAY': 0, '1MIN': 0, '5MIN': 0}}

        #正在导入代码表
        self.send_message(['START_IMPORT_CODE'])

        connect = sqlite3.connect(dest_dir + "/stock.db")
        create_database(connect)

        tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\shm.tnf", 'SH', self.quotations)
        tdx_import_stock_name_from_file(connect, src_dir + "\\T0002\\hq_cache\\szm.tnf", 'SZ', self.quotations)

        self.send_message(['FINISHED_IMPORT_CODE'])

        self.process_list.clear()
        for task in self.tasks:
            p = Process(target=task)
            self.process_list.append(p)
            p.start()

        finished_count = len(self.tasks)
        while finished_count > 0:
            message = self.queue.get()
            taskname, market, ktype, progress, total = message
            if progress is None:
                finished_count -= 1
                if taskname == 'IMPORT_KDATA':
                    self.send_message(['IMPORT_KDATA', 'FINISHED', market, ktype, total])
                else:
                    self.send_message([taskname, 'FINISHED'])
                continue

            if taskname == 'IMPORT_WEIGHT':
                if market == 'INFO':
                    self.send_message(['INFO', ktype])
                self.send_message(['IMPORT_WEIGHT', market, total])
            elif taskname == 'IMPORT_KDATA':
                hdf5_import_progress[market][ktype] = progress
                current_progress = (hdf5_import_progress['SH'][ktype] + hdf5_import_progress['SZ'][ktype]) // 2
                self.send_message(['IMPORT_KDATA', ktype, current_progress])
            else:
                print("Unknow task: ", taskname)
예제 #2
0
    def _run(self):
        src_dir = self.config['tdx']['dir']
        dest_dir = self.config['hdf5']['dir']
        hdf5_import_progress = {
            'SH': {
                'DAY': 0,
                '1MIN': 0,
                '5MIN': 0
            },
            'SZ': {
                'DAY': 0,
                '1MIN': 0,
                '5MIN': 0
            }
        }
        trans_progress = {'SH': 0, 'SZ': 0}
        time_progress = {'SH': 0, 'SZ': 0}

        #正在导入代码表
        self.send_message(['INFO', '导入股票代码表'])

        connect = sqlite3.connect(dest_dir + "/stock.db")
        create_database(connect)

        pytdx_api = TdxHq_API()
        pytdx_api.connect(self.hosts[0][2], self.hosts[0][3])

        count = import_stock_name(connect, pytdx_api, 'SH', self.quotations)
        if count > 0:
            self.send_message(['INFO', '上证新增股票数:%s' % count])
        count = import_stock_name(connect, pytdx_api, 'SZ', self.quotations)
        if count > 0:
            self.send_message(['INFO', '深证新增股票数:%s' % count])

        self.process_list.clear()
        for task in self.tasks:
            p = Process(target=task)
            self.process_list.append(p)
            p.start()

        finished_count = len(self.tasks)
        while finished_count > 0:
            message = self.queue.get()
            taskname, market, ktype, progress, total = message
            if progress is None:
                finished_count -= 1
                if taskname in ('IMPORT_KDATA', 'IMPORT_TRANS', 'IMPORT_TIME'):
                    self.send_message(
                        [taskname, 'FINISHED', market, ktype, total])
                else:
                    self.send_message([taskname, 'FINISHED'])
                continue

            if taskname == 'IMPORT_WEIGHT':
                if market == 'INFO':
                    self.send_message(['INFO', ktype])
                self.send_message([taskname, market, total])
            elif taskname == 'IMPORT_FINANCE':
                self.send_message([taskname, progress])
            elif taskname == 'IMPORT_KDATA':
                hdf5_import_progress[market][ktype] = progress
                current_progress = (hdf5_import_progress['SH'][ktype] +
                                    hdf5_import_progress['SZ'][ktype]) // 2
                self.send_message([taskname, ktype, current_progress])
            elif taskname == 'IMPORT_TRANS':
                trans_progress[market] = progress
                current_progress = (trans_progress['SH'] +
                                    trans_progress['SZ']) // 2
                self.send_message([taskname, ktype, current_progress])
            elif taskname == 'IMPORT_TIME':
                time_progress[market] = progress
                current_progress = (time_progress['SH'] +
                                    time_progress['SZ']) // 2
                self.send_message([taskname, ktype, current_progress])
            else:
                print("Unknow task: ", taskname)
예제 #3
0
    def _run(self):
        src_dir = self.config['tdx']['dir']
        dest_dir = self.config['hdf5']['dir']
        hdf5_import_progress = {
            'SH': {
                'DAY': 0,
                '1MIN': 0,
                '5MIN': 0
            },
            'SZ': {
                'DAY': 0,
                '1MIN': 0,
                '5MIN': 0
            }
        }

        #正在导入代码表
        self.send_message(['START_IMPORT_CODE'])

        connect = sqlite3.connect(dest_dir + "/stock.db")
        create_database(connect)

        tdx_import_stock_name_from_file(connect,
                                        src_dir + "\\T0002\\hq_cache\\shm.tnf",
                                        'SH', self.quotations)
        tdx_import_stock_name_from_file(connect,
                                        src_dir + "\\T0002\\hq_cache\\szm.tnf",
                                        'SZ', self.quotations)

        self.send_message(['FINISHED_IMPORT_CODE'])

        self.process_list.clear()
        for task in self.tasks:
            p = Process(target=task)
            self.process_list.append(p)
            p.start()

        finished_count = len(self.tasks)
        while finished_count > 0:
            message = self.queue.get()
            taskname, market, ktype, progress, total = message
            if progress is None:
                finished_count -= 1
                if taskname == 'IMPORT_KDATA':
                    self.send_message(
                        ['IMPORT_KDATA', 'FINISHED', market, ktype, total])
                else:
                    self.send_message([taskname, 'FINISHED'])
                continue

            if taskname == 'IMPORT_WEIGHT':
                if market == 'INFO':
                    self.send_message(['INFO', ktype])
                self.send_message(['IMPORT_WEIGHT', market, total])
            elif taskname == 'IMPORT_KDATA':
                hdf5_import_progress[market][ktype] = progress
                current_progress = (hdf5_import_progress['SH'][ktype] +
                                    hdf5_import_progress['SZ'][ktype]) // 2
                self.send_message(['IMPORT_KDATA', ktype, current_progress])
            else:
                self.logger.error("Unknow task: {}".format(taskname))
예제 #4
0
    def _run(self):
        src_dir = self.config['tdx']['dir']
        dest_dir = self.config['hdf5']['dir']
        hdf5_import_progress = {'SH': {'DAY': 0, '1MIN': 0, '5MIN': 0},
                                'SZ': {'DAY': 0, '1MIN': 0, '5MIN': 0}}
        trans_progress = {'SH': 0, 'SZ': 0}
        time_progress = {'SH': 0, 'SZ': 0}

        #正在导入代码表
        self.send_message(['INFO', '导入股票代码表'])

        connect = sqlite3.connect(dest_dir + "/stock.db")
        create_database(connect)

        pytdx_api = TdxHq_API()
        pytdx_api.connect(self.hosts[0][2], self.hosts[0][3])

        count = import_stock_name(connect, pytdx_api, 'SH', self.quotations)
        if count > 0:
            self.send_message(['INFO', '上证新增股票数:%s' % count])
        count = import_stock_name(connect, pytdx_api, 'SZ', self.quotations)
        if count > 0:
            self.send_message(['INFO', '深证新增股票数:%s' % count])

        self.process_list.clear()
        for task in self.tasks:
            p = Process(target=task)
            self.process_list.append(p)
            p.start()

        finished_count = len(self.tasks)
        while finished_count > 0:
            message = self.queue.get()
            taskname, market, ktype, progress, total = message
            if progress is None:
                finished_count -= 1
                if taskname in ('IMPORT_KDATA', 'IMPORT_TRANS', 'IMPORT_TIME'):
                    self.send_message([taskname, 'FINISHED', market, ktype, total])
                else:
                    self.send_message([taskname, 'FINISHED'])
                continue

            if taskname == 'IMPORT_WEIGHT':
                if market == 'INFO':
                    self.send_message(['INFO', ktype])
                self.send_message([taskname, market, total])
            elif taskname == 'IMPORT_FINANCE':
                self.send_message([taskname, progress])
            elif taskname == 'IMPORT_KDATA':
                hdf5_import_progress[market][ktype] = progress
                current_progress = (hdf5_import_progress['SH'][ktype] + hdf5_import_progress['SZ'][ktype]) // 2
                self.send_message([taskname, ktype, current_progress])
            elif taskname == 'IMPORT_TRANS':
                trans_progress[market] = progress
                current_progress = (trans_progress['SH'] + trans_progress['SZ']) // 2
                self.send_message([taskname, ktype, current_progress])
            elif taskname == 'IMPORT_TIME':
                time_progress[market] = progress
                current_progress = (time_progress['SH'] + time_progress['SZ']) // 2
                self.send_message([taskname, ktype, current_progress])
            else:
                print("Unknow task: ", taskname)
예제 #5
0
    connect.commit()
    h5file.close()
    return add_record_count


if __name__ == '__main__':

    import time
    starttime = time.time()

    src_dir = "D:\\TdxW_HuaTai"
    dest_dir = "c:\\stock"
    quotations = ['stock', 'fund']  #通达信盘后数据没有债券

    connect = sqlite3.connect(dest_dir + "\\stock.db")
    create_database(connect)

    add_count = 0

    print("导入股票代码表")
    add_count = tdx_import_stock_name_from_file(
        connect, src_dir + "\\T0002\\hq_cache\\shm.tnf", 'SH', quotations)
    add_count += tdx_import_stock_name_from_file(
        connect, src_dir + "\\T0002\\hq_cache\\szm.tnf", 'SZ', quotations)
    print("新增股票数:", add_count)

    print("\n导入上证日线数据")
    add_count = tdx_import_data(connect, 'SH', 'DAY', quotations,
                                src_dir + "\\vipdoc\\sh\\lday", dest_dir)
    print("\n导入数量:", add_count)