Enable options by default and allow full sim trading without OKX API keys.
Relax hedge start gates in sim, route perp open/close through sim broker, and mount strategy templates for records pages. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -74,6 +74,69 @@ def apply_sim_hooks(app_module: Any) -> None:
|
||||
app_module.get_available_trading_usdt = get_available_trading_usdt
|
||||
app_module.get_live_position_contracts = get_live_position_contracts
|
||||
|
||||
_orig_place = getattr(app_module, "place_exchange_order", None)
|
||||
_orig_close = getattr(app_module, "close_exchange_order", None)
|
||||
if callable(_orig_place):
|
||||
|
||||
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),
|
||||
stop_loss=stop_loss,
|
||||
take_profit=take_profit,
|
||||
)
|
||||
return _orig_place(
|
||||
exchange_symbol,
|
||||
direction,
|
||||
amount,
|
||||
leverage,
|
||||
stop_loss=stop_loss,
|
||||
take_profit=take_profit,
|
||||
)
|
||||
|
||||
app_module.place_exchange_order = place_exchange_order
|
||||
|
||||
if callable(_orig_close):
|
||||
|
||||
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")
|
||||
row = order_row or {}
|
||||
symbol = row.get("exchange_symbol") or row.get("symbol")
|
||||
direction = row.get("direction")
|
||||
contracts = float(row.get("order_amount") or 0)
|
||||
return broker().close_perp_market(
|
||||
ex,
|
||||
symbol=str(symbol or ""),
|
||||
direction=str(direction or ""),
|
||||
contracts=contracts if contracts > 0 else None,
|
||||
)
|
||||
return _orig_close(order_row)
|
||||
|
||||
app_module.close_exchange_order = close_exchange_order
|
||||
|
||||
_orig_xfer = getattr(app_module, "execute_transfer_usdt", None)
|
||||
if callable(_orig_xfer):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user