fix: synology py38 compatibility and KIS validation deps
This commit is contained in:
@@ -26,8 +26,6 @@ import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
@@ -36,6 +34,14 @@ REAL_DOMAIN = "https://openapi.koreainvestment.com:9443"
|
||||
MOCK_DOMAIN = "https://openapivts.koreainvestment.com:29443"
|
||||
TOKEN_CACHE_DIR = ROOT / "Temp"
|
||||
|
||||
|
||||
def _requests():
|
||||
try:
|
||||
import requests # type: ignore
|
||||
except Exception as exc: # pragma: no cover - surfaced as runtime validation error
|
||||
raise RuntimeError(f"import_error: {exc}") from exc
|
||||
return requests
|
||||
|
||||
# ── [CRITICAL] 주문 차단 목록 — 절대 수정/완화 금지 (governance/rules/06_no_direct_api_trading.yaml) ──
|
||||
# "/trading/" 하위 경로는 주문(order)뿐 아니라 계좌잔고조회(inquire-balance)도 포함한다.
|
||||
# 계좌 보유종목/잔고는 governance/rules/07_no_kis_account_balance_query.yaml에 의해
|
||||
@@ -126,6 +132,7 @@ def _issue_or_reuse_token(creds: KisCredentials) -> str:
|
||||
except (json.JSONDecodeError, KeyError, ValueError):
|
||||
pass
|
||||
|
||||
requests = _requests()
|
||||
resp = requests.post(
|
||||
f"{creds.domain}/oauth2/tokenP",
|
||||
json={"grant_type": "client_credentials", "appkey": creds.app_key, "appsecret": creds.app_secret},
|
||||
@@ -155,6 +162,7 @@ def _send_request(creds: KisCredentials, path: str, tr_id: str, params: dict[str
|
||||
"tr_id": tr_id,
|
||||
"custtype": "P",
|
||||
}
|
||||
requests = _requests()
|
||||
resp = requests.get(f"{creds.domain}{path}", headers=headers, params=params, timeout=15)
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
|
||||
@@ -3,11 +3,10 @@ from __future__ import annotations
|
||||
import json
|
||||
import re
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import yaml
|
||||
|
||||
@@ -15,7 +14,7 @@ import yaml
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
DEFAULT_DB = ROOT / "outputs" / "snapshot_admin" / "snapshot_admin.db"
|
||||
DEFAULT_SEED_JSON = ROOT / "GatherTradingData.json"
|
||||
KST = ZoneInfo("Asia/Seoul")
|
||||
KST = timezone(timedelta(hours=9))
|
||||
|
||||
SETTINGS_TABLE = "settings"
|
||||
SNAPSHOT_TABLE = "account_snapshot"
|
||||
|
||||
Reference in New Issue
Block a user