删除永续下单监控与划转强平,保留关键位监控并完成回归审计。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+4
-67
@@ -40,9 +40,7 @@ def apply_sim_hooks(app_module: Any) -> None:
|
||||
_orig_ensure = app_module.ensure_okx_live_ready
|
||||
_orig_capitals = app_module.get_exchange_capitals
|
||||
_orig_avail = app_module.get_available_trading_usdt
|
||||
_orig_place = app_module.place_exchange_order
|
||||
_orig_close = app_module.close_exchange_order
|
||||
_orig_live_contracts = app_module.get_live_position_contracts
|
||||
_orig_live_contracts = getattr(app_module, "get_live_position_contracts", None)
|
||||
|
||||
def ensure_okx_live_ready():
|
||||
if is_sim_mode(app_module.get_db):
|
||||
@@ -60,67 +58,6 @@ def apply_sim_hooks(app_module: Any) -> None:
|
||||
return float(broker().balances_header()["trading_usdt"])
|
||||
return _orig_avail()
|
||||
|
||||
def place_exchange_order(
|
||||
exchange_symbol, direction, amount, leverage, stop_loss=None, take_profit=None
|
||||
):
|
||||
if is_sim_mode(app_module.get_db):
|
||||
ex = getattr(app_module, "exchange", None)
|
||||
if ex is None:
|
||||
raise RuntimeError("sim: exchange 未就绪(公开行情)")
|
||||
ensure = getattr(app_module, "ensure_markets_loaded", None)
|
||||
if callable(ensure):
|
||||
try:
|
||||
ensure()
|
||||
except Exception:
|
||||
pass
|
||||
return broker().place_perp_market(
|
||||
ex,
|
||||
symbol=exchange_symbol,
|
||||
direction=direction,
|
||||
contracts=float(amount),
|
||||
leverage=int(leverage or 1),
|
||||
fee_rate=sim_fee_rate(),
|
||||
stop_loss=stop_loss,
|
||||
take_profit=take_profit,
|
||||
)
|
||||
return _orig_place(
|
||||
exchange_symbol, direction, amount, leverage, stop_loss=stop_loss, take_profit=take_profit
|
||||
)
|
||||
|
||||
def close_exchange_order(order_row):
|
||||
if is_sim_mode(app_module.get_db):
|
||||
ex = getattr(app_module, "exchange", None)
|
||||
if ex is None:
|
||||
raise RuntimeError("sim: exchange 未就绪")
|
||||
ensure = getattr(app_module, "ensure_markets_loaded", None)
|
||||
if callable(ensure):
|
||||
try:
|
||||
ensure()
|
||||
except Exception:
|
||||
pass
|
||||
normalize = getattr(app_module, "normalize_okx_symbol", None) or getattr(
|
||||
app_module, "normalize_exchange_symbol", None
|
||||
)
|
||||
try:
|
||||
symbol = order_row["exchange_symbol"] or None
|
||||
except Exception:
|
||||
symbol = None
|
||||
if not symbol:
|
||||
try:
|
||||
symbol = order_row["symbol"]
|
||||
except Exception:
|
||||
symbol = None
|
||||
if callable(normalize):
|
||||
symbol = normalize(symbol)
|
||||
direction = order_row["direction"]
|
||||
db_amt = float(order_row["order_amount"] or 0)
|
||||
live = broker().get_perp_contracts(symbol, direction)
|
||||
amt = live if live and live > 0 else db_amt
|
||||
return broker().close_perp_market(
|
||||
ex, symbol=symbol, direction=direction, contracts=amt, fee_rate=sim_fee_rate()
|
||||
)
|
||||
return _orig_close(order_row)
|
||||
|
||||
def get_live_position_contracts(exchange_symbol, direction):
|
||||
if is_sim_mode(app_module.get_db):
|
||||
normalize = getattr(app_module, "normalize_okx_symbol", None)
|
||||
@@ -128,13 +65,13 @@ def apply_sim_hooks(app_module: Any) -> None:
|
||||
if callable(normalize):
|
||||
sym = normalize(exchange_symbol or "")
|
||||
return broker().get_perp_contracts(sym, direction)
|
||||
return _orig_live_contracts(exchange_symbol, direction)
|
||||
if callable(_orig_live_contracts):
|
||||
return _orig_live_contracts(exchange_symbol, direction)
|
||||
return 0.0
|
||||
|
||||
app_module.ensure_okx_live_ready = ensure_okx_live_ready
|
||||
app_module.get_exchange_capitals = get_exchange_capitals
|
||||
app_module.get_available_trading_usdt = get_available_trading_usdt
|
||||
app_module.place_exchange_order = place_exchange_order
|
||||
app_module.close_exchange_order = close_exchange_order
|
||||
app_module.get_live_position_contracts = get_live_position_contracts
|
||||
|
||||
_orig_xfer = getattr(app_module, "execute_transfer_usdt", None)
|
||||
|
||||
@@ -56,8 +56,6 @@ def install_sim_trading(app: Flask, repo_root: str, app_module: Any = None) -> N
|
||||
if isinstance(cfg, dict):
|
||||
patch_options_cfg(cfg)
|
||||
for fn_name in (
|
||||
"place_exchange_order",
|
||||
"close_exchange_order",
|
||||
"get_exchange_capitals",
|
||||
"get_available_trading_usdt",
|
||||
"ensure_okx_live_ready",
|
||||
|
||||
Reference in New Issue
Block a user