Beispiel #1
0
 def data_csv2db(self, symbol: str, exchange: Exchange, interval: Interval,
                 start_dt: datetime, end_dt: datetime):
     csv_file_name = self.make_csvfile_name(symbol=symbol,
                                            exchange=exchange,
                                            interval=interval,
                                            start_dt=start_dt,
                                            end_dt=end_dt)
     if not os.path.exists(csv_file_name):
         print(csv_file_name + "不存在,错误")
         return None
     engine = CsvLoaderEngine(None, None)
     engine.load_by_handle(
         open(csv_file_name, "r"),
         symbol=symbol,
         exchange=exchange,
         interval=interval,
         datetime_head="datetime",
         open_head=exchange.value + '.' + symbol + ".open",
         close_head=exchange.value + '.' + symbol + ".close",
         low_head=exchange.value + '.' + symbol + ".low",
         high_head=exchange.value + '.' + symbol + ".high",
         volume_head=exchange.value + '.' + symbol + ".volume",
         datetime_format="%Y-%m-%d %H:%M:%S.000000000",
     )
     engine.close()
 def setUp(self) -> None:
     self.engine = CsvLoaderEngine(None, None)  # no engine is necessary for CsvLoader
Beispiel #3
0
# 下载从 2018-05-01凌晨0点 到 2018-06-01凌晨0点 的 T1809 盘口Tick数据
# download_tasks["T_tick"] = DataDownloader(api, symbol_list=["SHFE.cu1801"], dur_sec=0,
#                                           start_dt=datetime(2017, 1, 1), end_dt=datetime(2018, 1, 1),
#                                           csv_file_name="SHFE.cu1801_tick.csv")
# 使用with closing机制确保下载完成后释放对应的资源
with closing(api):
    while not all([v.is_finished() for v in download_tasks.values()]):
        api.wait_update()
        print("progress: ", {
            k: ("%.2f%%" % v.get_progress())
            for k, v in download_tasks.items()
        })

print("下载完成,开始写入数据库")

engine = CsvLoaderEngine(None, None)
engine.load_by_handle(
    open(set_csv_file_name, "r"),
    symbol=set_symbol,
    exchange=Exchange.SHFE,
    interval=Interval.MINUTE,
    datetime_head="datetime",
    open_head=set_exchange + '.' + set_symbol + ".open",
    close_head=set_exchange + '.' + set_symbol + ".close",
    low_head=set_exchange + '.' + set_symbol + ".low",
    high_head=set_exchange + '.' + set_symbol + ".high",
    volume_head=set_exchange + '.' + set_symbol + ".volume",
    datetime_format="%Y-%m-%d %H:%M:%S.000000000",
)
engine.close()
print("写入数据库完成")
Beispiel #4
0
 def __init__(self, class_task: Type[Model],
              class_task_detail: Type[Model]):
     self.class_task = class_task
     self.class_task_detail = class_task_detail
     self.tq_down = TQDownload()
     self.engine = CsvLoaderEngine(None, None)