This commit is contained in:
薇薇安 2026-01-23 19:21:37 +08:00
parent 95abbf50be
commit cb7b091280
2 changed files with 5 additions and 4 deletions

View File

@ -27,8 +27,8 @@ async def _ensure_exchange_sltp_for_symbol(symbol: str, account_id: int = 1):
""" """
# 从 accounts 表读取账号私有API密钥 # 从 accounts 表读取账号私有API密钥
account_id_int = int(account_id or 1) account_id_int = int(account_id or 1)
api_key, api_secret, use_testnet = Account.get_credentials(account_id_int) api_key, api_secret, use_testnet, status = Account.get_credentials(account_id_int)
if not api_key or not api_secret: if (not api_key or not api_secret) and status == "active":
logger.error(f"[account_id={account_id_int}] API密钥未配置") logger.error(f"[account_id={account_id_int}] API密钥未配置")
raise HTTPException(status_code=400, detail=f"API密钥未配置account_id={account_id_int}") raise HTTPException(status_code=400, detail=f"API密钥未配置account_id={account_id_int}")

View File

@ -101,19 +101,20 @@ class Account:
return "", "", False return "", "", False
try: try:
from security.crypto import decrypt_str from security.crypto import decrypt_str
status = row.get("status") or "active"
api_key = decrypt_str(row.get("api_key_enc") or "") api_key = decrypt_str(row.get("api_key_enc") or "")
api_secret = decrypt_str(row.get("api_secret_enc") or "") api_secret = decrypt_str(row.get("api_secret_enc") or "")
except Exception: except Exception:
# 兼容:无 cryptography 或未配 master key 时: # 兼容:无 cryptography 或未配 master key 时:
# - 若库里是明文,仍可工作 # - 若库里是明文,仍可工作
# - 若库里是 enc:v1 密文但未配 ATS_MASTER_KEY则不能解密也不能把密文当作 Key 使用 # - 若库里是 enc:v1 密文但未配 ATS_MASTER_KEY则不能解密也不能把密文当作 Key 使用
status = "disabled"
api_key_raw = row.get("api_key_enc") or "" api_key_raw = row.get("api_key_enc") or ""
api_secret_raw = row.get("api_secret_enc") or "" api_secret_raw = row.get("api_secret_enc") or ""
api_key = "" if str(api_key_raw).startswith("enc:v1:") else str(api_key_raw) api_key = "" if str(api_key_raw).startswith("enc:v1:") else str(api_key_raw)
api_secret = "" if str(api_secret_raw).startswith("enc:v1:") else str(api_secret_raw) api_secret = "" if str(api_secret_raw).startswith("enc:v1:") else str(api_secret_raw)
use_testnet = bool(row.get("use_testnet") or False) use_testnet = bool(row.get("use_testnet") or False)
return api_key, api_secret, use_testnet return api_key, api_secret, use_testnet, status
class User: class User: