feat: приблизить симуляцию к реальной торговле и добавить задержки исполнения
This commit is contained in:
1 parent
dbc044fc49
commit
ffe587787b
8 files changed
+220
-7
No files matched your search
+17
-1
@@ -132,7 +132,7 @@ COMMON_FIELDS = [f.name for f in fields(sp.PaperSettings)
|
||||
"vector_min_move_pct", "auto_tp", "auto_tp_share_pct", "auto_tp_learn",
|
||||
"auto_tp_horizon_seconds", "one_per_tick", "cut_loss", "cut_loss_ticks",
|
||||
"max_data_age_ms", "require_leader", "leader_min_edge", "auto_stop_pct",
|
||||
"basis_window_seconds",
|
||||
"basis_window_seconds", "simulation_entry_delay_ms", "simulation_exit_delay_ms",
|
||||
"basis_entry_z", "basis_exit_z", "basis_min_gap_pct"}]
|
||||
SERIES_STEP = 0.5 # chart sampling, s
|
||||
SERIES_KEEP = 1200 # 10 minutes
|
||||
@@ -207,6 +207,15 @@ def load_common() -> dict:
|
||||
|
||||
def check_common(values: dict) -> tuple[dict, str]:
|
||||
"""Cast and validate settings coming from the page."""
|
||||
import math
|
||||
for name in ('simulation_entry_delay_ms', 'simulation_exit_delay_ms'):
|
||||
if name in values:
|
||||
try:
|
||||
value = float(str(values[name]).replace(',', '.'))
|
||||
if not math.isfinite(value) or not 0 <= value <= 60000:
|
||||
raise ValueError()
|
||||
except (ValueError, TypeError):
|
||||
return {}, 'Задержка должна быть от 0 до 60000 мс'
|
||||
out = {}
|
||||
defaults = sp.PaperSettings()
|
||||
for k in COMMON_FIELDS:
|
||||
@@ -306,6 +315,9 @@ class Engine:
|
||||
self.paper.ledger.signal_only = self.signal_mode
|
||||
self.paper.ledger.hooks = [self.mirror.hook] if real_signals else []
|
||||
self.paper.gate = self.mirror.gate if real_signals else None
|
||||
if not real_signals and getattr(self, 'execution_live', False):
|
||||
import paper_execution
|
||||
paper_execution.install(self)
|
||||
|
||||
def switch_real(self, enabled: bool) -> str:
|
||||
"""Switch only while flat, using independent real-signal and paper ledgers."""
|
||||
@@ -351,6 +363,8 @@ class Engine:
|
||||
|
||||
# --- lifecycle ---------------------------------------------------------------------------
|
||||
def start(self) -> None:
|
||||
self.execution_live = True
|
||||
self._connect_trader()
|
||||
ps = self.paper.settings
|
||||
if ps.follow_exchange == "mexc":
|
||||
self.tick, size = sh.mexc_contract(ps.follow_ticker)
|
||||
@@ -448,6 +462,8 @@ class Engine:
|
||||
if self.paper.ledger.storage_error:
|
||||
self.close_error = self.paper.ledger.storage_error
|
||||
return f"Закрыто позиций: {closed}; ошибка: {self.paper.ledger.storage_error}"
|
||||
if not closed and getattr(self.paper, '_execution_installed', False) and self.paper.ledger.positions:
|
||||
return 'Запрос закрытия поставлен в очередь с заданной задержкой'
|
||||
return f"закрыто позиций: {closed}"
|
||||
|
||||
def _auto_stop(self, now: float) -> None:
|
||||
|
||||
Reference in new issue
Block a user