Normalize fullwidth punctuation to ASCII across codebase.
Add scripts/normalize_ambiguous_unicode.py; fix corrupted patch_instance_theme_templates.py. Preserves curly quotes in string literals; removes Git homoglyph warnings on .env.example. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""OKX USDⓈ 期权 API 封装(主账户 exchange_options 专用)。"""
|
||||
"""OKX USDⓈ 期权 API 封装(主账户 exchange_options 专用)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
@@ -19,7 +19,7 @@ from lib.options.options_pricing_lib import (
|
||||
|
||||
_OKX_OPTION_ERR_ZH: dict[str, str] = {
|
||||
"51018": "期权账户不能持有净空头头寸",
|
||||
"51019": "期权买入须使用逐仓模式(全仓模式下不能持有多头净头寸)",
|
||||
"51019": "期权买入须使用逐仓模式(全仓模式下不能持有多头净头寸)",
|
||||
}
|
||||
|
||||
_OPTIONS_BALANCE_CACHE: dict[str, Any] = {"updated_at": 0.0, "data": None}
|
||||
@@ -59,7 +59,7 @@ def _okx_trade_error_message(exc: BaseException | None = None, resp: Any = None)
|
||||
|
||||
|
||||
def td_mode_for_option_buy(configured: str | None = None) -> str:
|
||||
"""OKX 买入期权(多头)必须使用逐仓。"""
|
||||
"""OKX 买入期权(多头)必须使用逐仓."""
|
||||
mode = (configured or "isolated").strip().lower()
|
||||
return "isolated" if mode == "cross" else mode or "isolated"
|
||||
|
||||
@@ -94,7 +94,7 @@ def _safe_float(v: Any) -> float | None:
|
||||
|
||||
|
||||
def round_option_px(px: float, tick_sz: Any, side: str) -> float:
|
||||
"""按 OKX tickSz 对齐:买入向上取整,卖出向下取整。"""
|
||||
"""按 OKX tickSz 对齐:买入向上取整,卖出向下取整."""
|
||||
tick = _safe_float(tick_sz)
|
||||
if tick is None or tick <= 0 or px <= 0:
|
||||
return px
|
||||
@@ -132,7 +132,7 @@ def _resolve_chain_quote(
|
||||
strike: float,
|
||||
index_px: float,
|
||||
) -> dict[str, Any]:
|
||||
"""链列表报价:卖一缺失时用标记价/内在价值估算(深度实值常见无卖一)。"""
|
||||
"""链列表报价:卖一缺失时用标记价/内在价值估算(深度实值常见无卖一)."""
|
||||
tick_sz = meta.get("tickSz")
|
||||
ask = _safe_float(ticker.get("askPx"))
|
||||
bid = _safe_float(ticker.get("bidPx"))
|
||||
@@ -209,7 +209,7 @@ def _pos_side_from_position(pos: dict[str, Any] | None) -> str | None:
|
||||
|
||||
|
||||
def inst_family_from_inst_id(inst_id: str) -> str | None:
|
||||
"""从 instId 解析 instFamily,如 ETH-USD_UM-260707-1790-C → ETH-USD_UM。"""
|
||||
"""从 instId 解析 instFamily,如 ETH-USD_UM-260707-1790-C → ETH-USD_UM."""
|
||||
parts = (inst_id or "").strip().split("-")
|
||||
if len(parts) < 4:
|
||||
return None
|
||||
@@ -217,7 +217,7 @@ def inst_family_from_inst_id(inst_id: str) -> str | None:
|
||||
|
||||
|
||||
def option_fields_from_inst_id(inst_id: str) -> tuple[str | None, float | None]:
|
||||
"""从 instId 解析 optType 与 strike,如 ETH-USD_UM-260709-1700-P。"""
|
||||
"""从 instId 解析 optType 与 strike,如 ETH-USD_UM-260709-1700-P."""
|
||||
parts = (inst_id or "").strip().split("-")
|
||||
if len(parts) < 2:
|
||||
return None, None
|
||||
@@ -228,7 +228,7 @@ def option_fields_from_inst_id(inst_id: str) -> tuple[str | None, float | None]:
|
||||
|
||||
|
||||
def expiry_ms_from_inst_id(inst_id: str) -> int | None:
|
||||
"""从 instId 日期段解析到期时刻(OKX 期权默认 08:00 UTC)。"""
|
||||
"""从 instId 日期段解析到期时刻(OKX 期权默认 08:00 UTC)."""
|
||||
parts = (inst_id or "").strip().split("-")
|
||||
if len(parts) < 3:
|
||||
return None
|
||||
@@ -246,7 +246,7 @@ def expiry_ms_from_inst_id(inst_id: str) -> int | None:
|
||||
|
||||
|
||||
def normalize_option_exp_ms(exp_time: Any, inst_id: str = "") -> int | None:
|
||||
"""统一期权到期毫秒时间戳(优先 API expTime,否则从 instId 推算)。"""
|
||||
"""统一期权到期毫秒时间戳(优先 API expTime,否则从 instId 推算)."""
|
||||
raw = _safe_float(exp_time)
|
||||
if raw is not None and raw > 0:
|
||||
ms = int(raw)
|
||||
@@ -345,7 +345,7 @@ def options_header_balances(
|
||||
*,
|
||||
force: bool = False,
|
||||
) -> tuple[float | None, float | None, float | None]:
|
||||
"""顶栏三格:交易 USDC、资金 USDC、资金 USDT(单次拉取 + 缓存)。"""
|
||||
"""顶栏三格:交易 USDC,资金 USDC,资金 USDT(单次拉取 + 缓存)."""
|
||||
bal = fetch_options_balances(ex, force=force)
|
||||
|
||||
def _round(v: Any) -> float | None:
|
||||
@@ -645,7 +645,7 @@ def fetch_option_positions(ex: ccxt.okx) -> list[dict[str, Any]]:
|
||||
|
||||
|
||||
def fetch_options_unrealized_pnl_usdc(ex: ccxt.okx) -> float | None:
|
||||
"""期权持仓未实现盈亏合计(USDC,统计口径与 USDT 1:1)。"""
|
||||
"""期权持仓未实现盈亏合计(USDC,统计口径与 USDT 1:1)."""
|
||||
total = 0.0
|
||||
found = False
|
||||
for pos in fetch_option_positions(ex):
|
||||
@@ -752,7 +752,7 @@ def spot_market_swap_usdt_usdc(
|
||||
direction: str,
|
||||
amount: float,
|
||||
) -> dict[str, Any]:
|
||||
"""现货市价兑换 USDC-USDT。direction: usdt_to_usdc | usdc_to_usdt。"""
|
||||
"""现货市价兑换 USDC-USDT.direction: usdt_to_usdc | usdc_to_usdt."""
|
||||
if amount <= 0:
|
||||
return {"ok": False, "msg": "数量须大于 0"}
|
||||
d = (direction or "").lower()
|
||||
@@ -798,7 +798,7 @@ def transfer_main_sub_account(
|
||||
from_account: str = "funding",
|
||||
to_account: str = "funding",
|
||||
) -> dict[str, Any]:
|
||||
"""主账户与子账户之间划转(须主账户 API)。"""
|
||||
"""主账户与子账户之间划转(须主账户 API)."""
|
||||
if amount <= 0:
|
||||
return {"ok": False, "msg": "划转金额须大于 0"}
|
||||
sub = (sub_acct or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user