fix: validate active five-market trader
This commit is contained in:
1 parent
9fd3077cae
commit
dc297399d4
3 files changed
+10
-7
No files matched your search
@@ -21,7 +21,7 @@ def test_closed_report_counts_entry_fee_once(tmp_path, monkeypatch, capsys, pref
|
|||||||
status = 200
|
status = 200
|
||||||
def __enter__(self): return self
|
def __enter__(self): return self
|
||||||
def __exit__(self, *args): pass
|
def __exit__(self, *args): pass
|
||||||
def read(self, size): return b'Local Crypto Dip Agent'
|
def read(self, size): return b'Local Trading Agent'
|
||||||
monkeypatch.setattr(validate, 'urlopen', lambda *a, **kw: Response())
|
monkeypatch.setattr(validate, 'urlopen', lambda *a, **kw: Response())
|
||||||
assert validate.main() == 0
|
assert validate.main() == 0
|
||||||
output = capsys.readouterr().out
|
output = capsys.readouterr().out
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ def report(monkeypatch, tmp_path, capsys):
|
|||||||
status=200
|
status=200
|
||||||
def __enter__(self): return self
|
def __enter__(self): return self
|
||||||
def __exit__(self,*a): pass
|
def __exit__(self,*a): pass
|
||||||
def read(self,n): return b'Local Crypto Dip Agent'
|
def read(self,n): return b'Local Trading Agent'
|
||||||
monkeypatch.setattr(validate, 'urlopen', lambda *a,**kw: Response())
|
monkeypatch.setattr(validate, 'urlopen', lambda *a,**kw: Response())
|
||||||
def run():
|
def run():
|
||||||
status=validate.main()
|
status=validate.main()
|
||||||
|
|||||||
+8
-5
@@ -8,9 +8,9 @@ from urllib.request import urlopen
|
|||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
ROOT = Path(__file__).resolve().parent
|
ROOT = Path(__file__).resolve().parent
|
||||||
STATE = ROOT / "data" / "state.json"
|
STATE = ROOT / "data" / "five-market" / "state.json"
|
||||||
TRADES = ROOT / "data" / "trades.jsonl"
|
TRADES = ROOT / "data" / "five-market" / "trades.jsonl"
|
||||||
CONFIG = ROOT / "config.json"
|
CONFIG = ROOT / "config-five.json"
|
||||||
LOCAL_TZ = ZoneInfo("America/New_York")
|
LOCAL_TZ = ZoneInfo("America/New_York")
|
||||||
|
|
||||||
|
|
||||||
@@ -49,13 +49,13 @@ def main():
|
|||||||
with urlopen("https://trader.nannery.pro", timeout=20) as r:
|
with urlopen("https://trader.nannery.pro", timeout=20) as r:
|
||||||
body = r.read(200).decode("utf-8", "ignore")
|
body = r.read(200).decode("utf-8", "ignore")
|
||||||
public_code = str(r.status)
|
public_code = str(r.status)
|
||||||
public_ok = r.status == 200 and "Local Crypto Dip Agent" in body
|
public_ok = r.status == 200 and "Local Trading Agent" in body
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
public_code = type(e).__name__
|
public_code = type(e).__name__
|
||||||
if not public_ok:
|
if not public_ok:
|
||||||
problems.append(f"public dashboard validation failed: {public_code}")
|
problems.append(f"public dashboard validation failed: {public_code}")
|
||||||
|
|
||||||
cfg_check = sh("python3 bot.py --config-check", timeout=30)
|
cfg_check = sh("python3 five_market.py --config-check", timeout=30)
|
||||||
if cfg_check.returncode != 0:
|
if cfg_check.returncode != 0:
|
||||||
problems.append("bot config-check failed")
|
problems.append("bot config-check failed")
|
||||||
|
|
||||||
@@ -88,7 +88,10 @@ def main():
|
|||||||
drawdown_pct = ((peak - equity) / peak * 100) if peak else 0.0
|
drawdown_pct = ((peak - equity) / peak * 100) if peak else 0.0
|
||||||
positions = st.get("positions", {})
|
positions = st.get("positions", {})
|
||||||
exposure = sum(float(p.get("notional_usd", 0)) for p in positions.values())
|
exposure = sum(float(p.get("notional_usd", 0)) for p in positions.values())
|
||||||
|
if "max_total_position_pct_of_equity" in cfg:
|
||||||
max_exposure = equity * float(cfg.get("max_total_position_pct_of_equity", 1.0))
|
max_exposure = equity * float(cfg.get("max_total_position_pct_of_equity", 1.0))
|
||||||
|
else:
|
||||||
|
max_exposure = equity * float(cfg.get("max_total_exposure_pct", 100.0)) / 100.0
|
||||||
if exposure > max_exposure + 0.01:
|
if exposure > max_exposure + 0.01:
|
||||||
problems.append(f"exposure too high: {money(exposure)} > cap {money(max_exposure)}")
|
problems.append(f"exposure too high: {money(exposure)} > cap {money(max_exposure)}")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user