From 23e533ddf385d1118fe2e2ba1c769389a6651e8f Mon Sep 17 00:00:00 2001 From: blade <8019068@qq.com> Date: Tue, 16 Sep 2025 17:09:00 +0800 Subject: [PATCH] update code for date time format issue --- core/biz/huge_volume_chart.py | 2 +- core/db/db_manager.py | 2 +- core/trade/ma_break_statistics.py | 2 +- core/utils.py | 4 ++-- market_data_from_itick_main.py | 2 +- orb_trade_main.py | 2 +- trade_sandbox_main.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/biz/huge_volume_chart.py b/core/biz/huge_volume_chart.py index 6a158e4..1fed973 100644 --- a/core/biz/huge_volume_chart.py +++ b/core/biz/huge_volume_chart.py @@ -404,7 +404,7 @@ class HugeVolumeChart: } """ logger.info(f"输出Excel文件,包含所有{chart_type}图表") - file_name = f"huge_volume_{chart_type}_{get_current_date_time()}.xlsx" + file_name = f"huge_volume_{chart_type}_{get_current_date_time(format="%Y%m%d%H%M%S")}.xlsx" file_path = os.path.join(self.output_folder, file_name) # Create Excel file and worksheet diff --git a/core/db/db_manager.py b/core/db/db_manager.py index 4be1921..6135c8e 100644 --- a/core/db/db_manager.py +++ b/core/db/db_manager.py @@ -13,7 +13,7 @@ class DBData: ): self.table_name = table_name self.temp_table_name = ( - f"temp_{table_name}_{get_current_date_time()}" + f"temp_{table_name}_{get_current_date_time(format="%Y%m%d_%H%M%S")}" ) self.columns = columns if self.columns is None: diff --git a/core/trade/ma_break_statistics.py b/core/trade/ma_break_statistics.py index 12d61b6..45c68a6 100644 --- a/core/trade/ma_break_statistics.py +++ b/core/trade/ma_break_statistics.py @@ -234,7 +234,7 @@ class MaBreakStatistics: ) latest_market_date_time = ma_break_market_data["end_date_time"].max() if latest_market_date_time is None: - latest_market_date_time = get_current_date_time() + latest_market_date_time = get_current_date_time(format="%Y%m%d%H%M%S") latest_market_date_time = re.sub( r"[\:\-\s]", "", str(latest_market_date_time) ) diff --git a/core/utils.py b/core/utils.py index cc67b05..d8e8fa1 100644 --- a/core/utils.py +++ b/core/utils.py @@ -76,8 +76,8 @@ def transform_date_time_to_timestamp(date_time: int | str): return None -def get_current_date_time() -> str: +def get_current_date_time(format: str = "%Y-%m-%d %H:%M:%S") -> str: """ 获取当前日期时间 """ - return datetime.now(timezone(timedelta(hours=8))).strftime("%Y-%m-%d %H:%M:%S") \ No newline at end of file + return datetime.now(timezone(timedelta(hours=8))).strftime(format) \ No newline at end of file diff --git a/market_data_from_itick_main.py b/market_data_from_itick_main.py index 7308372..ceb1096 100644 --- a/market_data_from_itick_main.py +++ b/market_data_from_itick_main.py @@ -40,7 +40,7 @@ def main(): logger.info(f"成功下载 {len(processed_data)} 条数据") # 保存数据 - filename = f"{symbol}_{interval}_{get_current_date_time()}.csv" + filename = f"{symbol}_{interval}_{get_current_date_time(format="%Y%m%d%H%M%S")}.csv" market_data_from_futu.save_to_csv(filename) # 显示数据统计 diff --git a/orb_trade_main.py b/orb_trade_main.py index 28a9111..02771bb 100644 --- a/orb_trade_main.py +++ b/orb_trade_main.py @@ -121,7 +121,7 @@ def main(): statitics_dict = statistics_summary(total_trades_summary_df) output_excel_folder = r"./output/trade_sandbox/orb_strategy/excel/summary/" os.makedirs(output_excel_folder, exist_ok=True) - now_str = get_current_date_time() + now_str = get_current_date_time(format="%Y%m%d%H%M%S") excel_file_name = f"orb_strategy_summary_{now_str}.xlsx" output_file_path = os.path.join(output_excel_folder, excel_file_name) with pd.ExcelWriter(output_file_path) as writer: diff --git a/trade_sandbox_main.py b/trade_sandbox_main.py index 98ec3ba..f85ff5e 100644 --- a/trade_sandbox_main.py +++ b/trade_sandbox_main.py @@ -69,7 +69,7 @@ class MeanReversionSandboxMain: stat_data = self.statistic_data(total_data) excel_save_path = os.path.join(self.save_path, solution, "excel") os.makedirs(excel_save_path, exist_ok=True) - date_time_str = get_current_date_time() + date_time_str = get_current_date_time(format="%Y%m%d%H%M%S") excel_file_path = os.path.join( excel_save_path, f"{solution}_{date_time_str}.xlsx" )