feat: Enhance trading system with new permanent subscription features and order book management
Changes: - Added a new API endpoint for managing permanent subscriptions, allowing users to enable or disable subscriptions dynamically. - Implemented a function to fill candle data from Kiwoom, ensuring that only relevant data is inserted into the database. - Introduced a mechanism to handle master subscription states, improving the management of subscription statuses. - Updated the database schema to include new fields for managing subscription states and order book filtering. Impact: - These enhancements improve the flexibility and reliability of the trading system, allowing for better management of subscriptions and order book data, while reducing the risk of data inconsistencies. 히스토리 align 제거 븅신같은 초기설계 아예 제거 진입모드에 구멍메움 호가진입을 켜도 호가가 안들어올때 호가 안보고 그냥 사버림
This commit is contained in:
@@ -68,22 +68,67 @@ def universe_exit_debounce_sec_for_strategy(strategy_id: str) -> int:
|
||||
|
||||
|
||||
def _event_time_to_key(event_time: str) -> str:
|
||||
"""YYYYMMDDHHMMSSffffff (20자). 초만 있으면 마이크로=000000."""
|
||||
et = str(event_time or "")
|
||||
if len(et) < 19:
|
||||
return ""
|
||||
return (
|
||||
base = (
|
||||
et[0:4] + et[5:7] + et[8:10]
|
||||
+ et[11:13] + et[14:16] + et[17:19]
|
||||
)
|
||||
frac = "000000"
|
||||
if len(et) > 19 and et[19] == ".":
|
||||
frac = (et[20:26] + "000000")[:6]
|
||||
frac = "".join(ch if ch.isdigit() else "0" for ch in frac)
|
||||
frac = (frac + "000000")[:6]
|
||||
return base + frac
|
||||
|
||||
|
||||
def event_time_query_upper(at_time: str) -> str:
|
||||
"""초 단위 조회 상한 = 그 초의 마지막 마이크로초 스냅샷까지."""
|
||||
s = str(at_time or "").strip()
|
||||
if not s:
|
||||
return s
|
||||
if "." in s:
|
||||
return s
|
||||
if len(s) >= 19:
|
||||
return s[:19] + ".999999"
|
||||
return s
|
||||
|
||||
|
||||
def _codes_at_key(scan_key: str) -> str:
|
||||
"""codes_at 비교키. 14자리(초)면 그 초 끝(999999)까지."""
|
||||
sk = str(scan_key or "")
|
||||
if not sk:
|
||||
return ""
|
||||
if len(sk) <= 14:
|
||||
return (sk + "0" * 14)[:14] + "999999"
|
||||
if len(sk) < 20:
|
||||
return (sk + "9" * 20)[:20]
|
||||
return sk[:20]
|
||||
|
||||
|
||||
def _parse_scan_key(scan_key: str) -> datetime:
|
||||
return datetime.strptime(str(scan_key)[:14], "%Y%m%d%H%M%S")
|
||||
s = str(scan_key or "")
|
||||
base = s[:14]
|
||||
dt = datetime.strptime(base, "%Y%m%d%H%M%S")
|
||||
if len(s) > 14:
|
||||
frac = "".join(ch for ch in s[14:20] if ch.isdigit())
|
||||
frac = (frac + "000000")[:6]
|
||||
try:
|
||||
dt = dt.replace(microsecond=int(frac))
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return dt
|
||||
|
||||
|
||||
def _add_minutes_to_scan_key(scan_key: str, minutes: int) -> str:
|
||||
dt = _parse_scan_key(scan_key)
|
||||
return (dt + timedelta(minutes=int(minutes))).strftime("%Y%m%d%H%M%S")
|
||||
s = str(scan_key or "")
|
||||
frac = s[14:20] if len(s) > 14 else "000000"
|
||||
frac = ("".join(ch for ch in frac if ch.isdigit()) + "000000")[:6]
|
||||
dt = datetime.strptime(s[:14], "%Y%m%d%H%M%S")
|
||||
out = (dt + timedelta(minutes=int(minutes))).strftime("%Y%m%d%H%M%S")
|
||||
return out + frac
|
||||
|
||||
|
||||
def _dedupe_codes_preserve_order(codes: Sequence[str]) -> List[str]:
|
||||
@@ -205,8 +250,10 @@ class UniverseTimeline:
|
||||
self._strict_avail = strict_avail
|
||||
|
||||
def codes_at(self, scan_key: str) -> List[str]:
|
||||
"""scan_key(YYYYMMDDHHMMSS) 시점 유니버스 — 실매 get_universe_at 동일."""
|
||||
sk = str(scan_key or "")[:14]
|
||||
"""scan_key(YYYYMMDDHHMMSS 또는 +마이크로) 시점 유니버스 — 실매 get_universe_at 동일.
|
||||
초만 주면 그 초의 **마지막** 스냅샷.
|
||||
"""
|
||||
sk = _codes_at_key(scan_key)
|
||||
if not sk or not self._keys:
|
||||
return []
|
||||
idx = bisect_right(self._keys, sk) - 1
|
||||
@@ -250,7 +297,7 @@ def build_universe_timeline(
|
||||
ext = get_db()
|
||||
start_time = f"{start_ymd[:4]}-{start_ymd[4:6]}-{start_ymd[6:8]} 00:00:00"
|
||||
start_time = apply_ls_session_filter_to_start(start_time, source=hs)
|
||||
end_time = f"{end_ymd[:4]}-{end_ymd[4:6]}-{end_ymd[6:8]} 23:59:59"
|
||||
end_time = f"{end_ymd[:4]}-{end_ymd[4:6]}-{end_ymd[6:8]} 23:59:59.999999"
|
||||
events = ext.iter_universe_events(
|
||||
strategy_id=strategy_id,
|
||||
start_time=start_time,
|
||||
|
||||
Reference in New Issue
Block a user