Files
QuantEngineByItz/tests/unit/test_storage_backend_v1.py
kjh2064 4cb206a269 KIS Open API 조회전용 연동 + 직접매매 절대금지 안전게이트
매수/매도 주문 및 계좌 잔고조회를 API로 직접 실행하지 않는다는 원칙을
코드 레벨에서 강제하는 안전게이트(governance/rules/06, 07)와 함께,
시세/호가/공매도거래비중 등 조회전용 KIS Open API 연동 및 SQLite
수집 파이프라인을 추가한다.

- kis_api_client_v1: 모든 요청이 _assert_read_only를 통과해야 하며
  /trading/ 경로·주문 TR_ID는 RuntimeError로 즉시 차단
- kis_data_collection_v1: KIS 우선 + Naver 폴백, 네트워크 실패는
  개별 ticker 단위로 흡수(배치 전체 중단 없음)
- data_collection_store_v1 / storage_backend_v1: SQLite 캐노니컬
  저장소, PostgreSQL 전환 대비 백엔드 추상화
- Gitea 영업일 스케줄(2시간 간격) + CI 강제 게이트
  (validate_no_direct_api_trading_v1, validate_kis_api_credentials_v1)
2026-06-21 20:04:44 +09:00

33 lines
1.2 KiB
Python

from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from src.quant_engine.storage_backend_v1 import StoreSpec, default_sqlite_store_path, normalize_store_spec
def test_default_sqlite_store_path_uses_named_subdir(tmp_path):
path = default_sqlite_store_path(tmp_path, "qualitative_sell_strategy/qualitative_sell_strategy.db")
assert str(path).endswith("qualitative_sell_strategy.db")
def test_normalize_store_spec_supports_sqlite_and_postgresql(tmp_path):
backend_sqlite, sqlite_location = normalize_store_spec(StoreSpec(location=tmp_path / "collector.db"), ROOT)
assert backend_sqlite == "sqlite"
assert str(sqlite_location).endswith("collector.db")
backend_pg, pg_location = normalize_store_spec(
StoreSpec(backend="postgresql", location="postgresql://user:pass@localhost/db"),
ROOT,
)
assert backend_pg == "postgresql"
assert "postgresql://" in str(pg_location)
def test_postgresql_upgrade_stub_script_exists():
assert (ROOT / "tools" / "generate_postgresql_upgrade_stub_v1.py").exists()