update 数据导出优化
This commit is contained in:
39
all_day_avg.py
Normal file
39
all_day_avg.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from UpdateFutuData.KLineUpdater import KLineUpdater
|
||||
from base.LogHelper import LogHelper
|
||||
from base import MySQLHelper,Config
|
||||
from DataAnalysis import DataExporter, MarketDataCalculator
|
||||
from DataAnalysis.checktable import StockTableChecker
|
||||
from UpdateFutuData.ConditionalSelection import FutuStockFilter
|
||||
from datetime import datetime, timedelta
|
||||
from tqdm import tqdm
|
||||
from pathlib import Path
|
||||
import time
|
||||
|
||||
def main():
|
||||
calculator = MarketDataCalculator(Config.ConfigInfo.db_hk_kline_1d)
|
||||
|
||||
# 读取代码
|
||||
reserved_codes = calculator.read_stock_codes_list(Path.cwd() / "config" / "all_day.txt")
|
||||
for code in reserved_codes:
|
||||
source_table = 'hk_' + code[3:]
|
||||
with MySQLHelper(**Config.ConfigInfo.db_hk_kline_1d) as db:
|
||||
sql = """
|
||||
SELECT AVG(close_price * float_share) as avg_close
|
||||
FROM {}
|
||||
WHERE stock_code = %s
|
||||
AND trade_date BETWEEN %s AND %s
|
||||
AND close_price IS NOT NULL
|
||||
AND float_share IS NOT NULL
|
||||
""".format(source_table)
|
||||
|
||||
result = db.execute_query(sql, (code, "2025-01-01 00:00:00", "2025-10-01 00:00:00"))
|
||||
# 保存小数点后两位,以亿为单位
|
||||
# monthly_data[month_col] = float(result[0]['avg_close']) * 1000 if result and result[0]['avg_close'] else None
|
||||
avg = round(float(result[0]['avg_close']) * 1000 / 100000000, 3) if result and result[0]['avg_close'] else None
|
||||
print(code,":",avg)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user