tradingSystem/research/signal_independence_20261111/export_daily_readonly.py

22 lines
1.1 KiB
Python
Raw Normal View History

2026-11-11 15:10:55 +08:00
"""执行前由开发机拼接已限定沪深的CODES常量;只读日线。"""
import datetime
import gzip
import json
import re
import sys
from sqlalchemy import event,text
from sqlalchemy.engine import Engine
@event.listens_for(Engine,'before_cursor_execute')
def guard(conn,cursor,statement,parameters,context,executemany):
if not statement.lstrip().upper().startswith(('SELECT','SHOW','DESCRIBE')):raise RuntimeError('read-only')
assert all(re.fullmatch(r'(SH(?:60|68)\d{4}|SZ(?:00|30)\d{4})',c) for c in CODES)
from scripts.backfill_v3f_baseline import _get_external_engine
eng=_get_external_engine()
out=gzip.GzipFile(fileobj=sys.stdout.buffer,mode='wb',mtime=0)
with eng.connect() as conn:
for i in range(0,len(CODES),40):
batch=CODES[i:i+40];params={f'c{j}':c for j,c in enumerate(batch)}
q="SELECT symbol,timestamp,high,low,close FROM gp_day_data WHERE symbol IN ("+','.join(':'+k for k in params)+") AND timestamp >= '2026-05-01' AND timestamp < '2026-11-11' ORDER BY symbol,timestamp"
for r in conn.execute(text(q),params):out.write((json.dumps(dict(r._mapping),default=str)+'\n').encode())
out.close();eng.dispose()