chore: initial local trading agent import
This commit is contained in:
commit
0591b75401
13 files changed
+1385
No files matched your search
@@ -0,0 +1,44 @@
|
||||
from datetime import datetime, timedelta
|
||||
from types import SimpleNamespace
|
||||
import pytest
|
||||
import validate
|
||||
|
||||
@pytest.fixture
|
||||
def report(monkeypatch, tmp_path, capsys):
|
||||
cfg = {'starting_cash_usd':100, 'scan_interval_seconds':900}
|
||||
state = {'mode':'paper', 'starting_cash_usd':100, 'cash_usd':96,
|
||||
'equity_high_watermark_usd':120,
|
||||
'last_scan':{'ts':datetime.now(validate.LOCAL_TZ).isoformat(), 'equity_usd':96}}
|
||||
monkeypatch.setattr(validate, 'load_json', lambda path, default: cfg if path == validate.CONFIG else state)
|
||||
monkeypatch.setattr(validate, 'TRADES', tmp_path/'absent')
|
||||
monkeypatch.setattr(validate, 'sh', lambda *a, **kw: SimpleNamespace(stdout='active\nactive\nactive\n', returncode=0))
|
||||
class Response:
|
||||
status=200
|
||||
def __enter__(self): return self
|
||||
def __exit__(self,*a): pass
|
||||
def read(self,n): return b'Local Crypto Dip Agent'
|
||||
monkeypatch.setattr(validate, 'urlopen', lambda *a,**kw: Response())
|
||||
def run():
|
||||
status=validate.main()
|
||||
return status, capsys.readouterr().out
|
||||
return state, run
|
||||
|
||||
|
||||
def test_report_separates_health_return_and_peak_drawdown(report):
|
||||
state, run = report
|
||||
status, text = run()
|
||||
assert status == 0
|
||||
assert 'Operational checks: OK | Performance: BELOW START' in text
|
||||
assert 'return -4.00%' in text
|
||||
assert 'drawdown from recorded peak 20.00%' in text
|
||||
assert 'Mode: paper' in text
|
||||
|
||||
|
||||
@pytest.mark.parametrize('stamp', [None, 'bad', '2020-01-01T00:00:00+00:00', '2999-01-01T00:00:00+00:00'])
|
||||
def test_untrustworthy_scan_reports_attention(report, stamp):
|
||||
state, run = report
|
||||
state['last_scan']['ts'] = stamp
|
||||
status, text = run()
|
||||
assert status == 1
|
||||
assert 'Operational checks: ATTENTION' in text
|
||||
assert 'scan timestamp' in text
|
||||
Reference in new issue
Block a user