система авторизации
Offline regression tests / windows (3.11) (push) Canceled after 0s
Offline regression tests / windows (3.12) (push) Canceled after 0s
Offline regression tests / windows (3.13) (push) Canceled after 0s

This commit is contained in:
listik committed 2026-10-23 21:14:57 +03:00
1 parent 85425483c0
commit f6f1ae20c2
21 files changed
+581 -110

No files matched your search

+20 -10
View File
@@ -14,6 +14,7 @@
from __future__ import annotations
import json
import os
import queue
import re
import statistics
@@ -114,7 +115,7 @@ def scanner_add(symbol: str, connections: list[dict]) -> tuple[dict | None, str]
lw.unremove_connection(conn) # deleted earlier and now added again by hand
au.add_connection(conn, lw.CONNECTIONS_FILE)
return conn, f"{symbol} добавлена ({au.SUPPORTED_OWNERS[owner]}) — монета остановлена, нажмите «Старт»"
DATA_DIR = ROOT / "web_sim_data"
DATA_DIR = Path(os.environ.get("CRYPTO_SCAM_DATA_DIR", ROOT / "web_sim_data")).resolve()
SETTINGS_FILE = DATA_DIR / "settings.json"
PAGE = ROOT / "web_sim.html"
STATIC_ASSETS = {
@@ -169,10 +170,9 @@ def exchange_links(conn: dict) -> list[dict]:
"url": f"https://www.kucoin.com/futures/trade/{conn['lead_ticker']}"})
ticker, exchange = conn["follow_ticker"], conn["follow_exchange"]
url = {"bybit": f"https://www.bybit.com/trade/usdt/{ticker}",
"binance": f"https://www.binance.com/en/futures/{ticker}",
"mexc": f"https://futures.mexc.com/exchange/{ticker}"}.get(exchange)
if url:
name = {"bybit": "Bybit", "binance": "Binance", "mexc": "MEXC"}[exchange]
name = {"bybit": "Bybit", "mexc": "MEXC"}[exchange]
links.append({"label": f"{name} фьючерс {ticker}", "url": url})
return links
@@ -369,9 +369,6 @@ class Engine:
if ps.follow_exchange == "mexc":
self.tick, size = sh.mexc_contract(ps.follow_ticker)
follower = sh.MexcFeed(ps.follow_ticker, self.events, size)
elif ps.follow_exchange == "binance":
self.tick = sh.binance_tick(ps.follow_ticker)
follower = sh.BinanceFeed(ps.follow_ticker, self.events)
else:
self.tick = sh.bybit_tick(ps.follow_ticker)
follower = sh.BybitFeed(ps.follow_ticker, self.events)
@@ -736,7 +733,7 @@ def apply_real_fee(exchange: str, pct: float) -> None:
PING_SAMPLES: dict = {} # host → deque of (time, ms)
FUTURES_HOST = {"bybit": "api.bybit.com", "binance": "fapi.binance.com", "mexc": "contract.mexc.com",
FUTURES_HOST = {"bybit": "api.bybit.com", "mexc": "contract.mexc.com",
"htx": "api.hbdm.com", "gate": "api.gateio.ws"}
@@ -832,7 +829,10 @@ class Handler(BaseHTTPRequestHandler):
self._json({"error": "недоверенный адрес страницы"}, 403)
return
path, _, query = self.path.partition("?")
if path in ("/", "/index.html"):
if path == "/health":
tenant_id = DATA_DIR.parent.name if DATA_DIR.parent.parent.name == "users" else "single-user"
self._json({"ok": True, "tenant": tenant_id})
elif path in ("/", "/index.html"):
self._send(200, PAGE.read_bytes(), "text/html")
elif path in STATIC_ASSETS:
asset, kind = STATIC_ASSETS[path]
@@ -1039,6 +1039,11 @@ def local_request(handler) -> bool:
def main() -> None:
import sys
if "--backend" not in sys.argv:
import web_proxy
web_proxy.main()
return
with RuntimeLock(DATA_DIR / "engine.lock"):
_serve()
@@ -1048,7 +1053,8 @@ def _serve() -> None:
global SIM
# --backend: only for this PC on BACKEND_PORT, the public page is served by web_proxy.py (outside the VPN)
if "--backend" in sys.argv:
host, port = "127.0.0.1", BACKEND_PORT
host = "127.0.0.1"
port = int(sys.argv[sys.argv.index("--port") + 1]) if "--port" in sys.argv else BACKEND_PORT
else:
host, port = ("127.0.0.1" if "--local" in sys.argv else HOST), PORT
# Claim the port before starting recovery workers or exchange connections.
@@ -1066,9 +1072,13 @@ def _serve() -> None:
# «Арбитраж»: the simulation and the real engine run from the start (open real positions are watched at once)
basis_engine("cross")
basis_engine("cross_real")
# Public market histories stay warm for the four supported venues even before the page opens the arb panel.
arb_view(market="spot")
arb_view(market="futures")
url = f"http://127.0.0.1:{PORT}"
print(f"Симулятор: {url} (движок слушает {host}:{port}, монет: {len(SIM.engines)})", flush=True)
threading.Timer(1.0, lambda: webbrowser.open(url)).start()
if "--backend" not in sys.argv:
threading.Timer(1.0, lambda: webbrowser.open(url)).start()
try:
server.serve_forever()
except KeyboardInterrupt: