币本位开仓:张数留手续费缓冲,延长买币落账等待并修正51008文案
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -19,7 +19,7 @@ from lib.options.options_pricing_lib import (
|
||||
)
|
||||
|
||||
_OKX_OPTION_ERR_ZH: dict[str, str] = {
|
||||
"51008": "可用余额或保证金不足(期权买入请确认交易账户 USDC 足够)",
|
||||
"51008": "可用余额或保证金不足(币本位请确认交易账户 ETH/BTC 足够;USDC 模式请确认 USDC 足够)",
|
||||
"51018": "期权账户不能持有净空头头寸",
|
||||
"51019": "期权买入须使用逐仓模式(全仓模式下不能持有多头净头寸)",
|
||||
}
|
||||
@@ -47,11 +47,18 @@ def _okx_trade_error_message(exc: BaseException | None = None, resp: Any = None)
|
||||
msg = str(row.get("sMsg") or "").strip()
|
||||
low = msg.lower()
|
||||
if code == "51008":
|
||||
# 勿写死「资金账户 USDT」:期权开仓常因交易户 USDC 不足
|
||||
# 勿写死「资金账户 USDT」:USDC 模式常因交易户 USDC 不足;币本位则是标的币不足
|
||||
if "usdc" in low:
|
||||
return "交易账户 USDC 可用余额不足"
|
||||
if "usdt" in low:
|
||||
return "USDT 可用余额不足(期权请先兑成 USDC 并划入交易账户)"
|
||||
return "USDT 可用余额不足"
|
||||
try:
|
||||
from lib.options.options_margin_mode_lib import is_coin_margin_mode
|
||||
|
||||
if is_coin_margin_mode():
|
||||
return "可用余额或保证金不足(币本位请确认交易账户 ETH/BTC 足够,或减少张数)"
|
||||
except Exception:
|
||||
pass
|
||||
return _OKX_OPTION_ERR_ZH["51008"]
|
||||
zh = _OKX_OPTION_ERR_ZH.get(code)
|
||||
if zh:
|
||||
|
||||
@@ -126,7 +126,13 @@ def open_coin_option_buy_full(
|
||||
message="已买币,待开期权",
|
||||
)
|
||||
# 等余额落账
|
||||
time.sleep(0.6)
|
||||
time.sleep(1.5)
|
||||
try:
|
||||
from lib.exchange.okx_options_lib import invalidate_options_balance_cache
|
||||
|
||||
invalidate_options_balance_cache()
|
||||
except Exception:
|
||||
pass
|
||||
coin_after = fetch_trading_coin_available(ex, underlying)
|
||||
if coin_after is None:
|
||||
rb = rollback_bought_coin_to_usdt(
|
||||
|
||||
@@ -143,12 +143,14 @@ def calc_sheets_from_coin_balance(
|
||||
mult = float(ct_mult or 0.01)
|
||||
need = max(1, int(min_sz or 1))
|
||||
coin = max(0.0, float(coin_available or 0))
|
||||
# 留一点手续费/精度缓冲,避免算满张后下单 51008
|
||||
coin_eff = coin * 0.97
|
||||
if ask <= 0 or mult <= 0:
|
||||
return {"ok": False, "msg": "卖一价无效", "sheets": 0, "coin_premium": 0.0}
|
||||
per_sheet = ask * mult
|
||||
if per_sheet <= 0:
|
||||
return {"ok": False, "msg": "无法计算单张权利金(币)", "sheets": 0, "coin_premium": 0.0}
|
||||
sheets = int(math.floor((coin / per_sheet) + 1e-12))
|
||||
sheets = int(math.floor((coin_eff / per_sheet) + 1e-12))
|
||||
if sheets < need:
|
||||
return {
|
||||
"ok": False,
|
||||
|
||||
Reference in New Issue
Block a user