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,29 @@
|
||||
import json
|
||||
from types import SimpleNamespace
|
||||
import pytest
|
||||
import validate
|
||||
|
||||
|
||||
@pytest.mark.parametrize('prefix', ['paper', 'shadow'])
|
||||
@pytest.mark.parametrize('events, expected', [
|
||||
([('buy', {'fee_usd': .04}), ('sell', {'buy_fee_usd': .04, 'realized_pnl_usd': .1192})], '$0.12'),
|
||||
([('buy', {'fee_usd': .04}), ('sell', {'realized_pnl_usd': .1592})], '$0.12'),
|
||||
([('buy', {'fee_usd': .04}), ('sell', {'buy_fee_usd': .04, 'realized_pnl_usd': .1192}),
|
||||
('buy', {'fee_usd': .08}), ('sell', {'realized_pnl_usd': .20})], '$0.24'),
|
||||
])
|
||||
def test_closed_report_counts_entry_fee_once(tmp_path, monkeypatch, capsys, prefix, events, expected):
|
||||
trades = tmp_path / 'trades.jsonl'
|
||||
trades.write_text('\n'.join(json.dumps(dict(type=prefix+'_'+kind, symbol='TST-USD', **values)) for kind, values in events))
|
||||
monkeypatch.setattr(validate, 'TRADES', trades)
|
||||
monkeypatch.setattr(validate, 'load_json', lambda path, default: {'watch_only_symbols': ['TST-USD']} if path == validate.CONFIG else {'last_scan': {'ts': validate.datetime.now(validate.LOCAL_TZ).isoformat()}})
|
||||
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, *args): pass
|
||||
def read(self, size): return b'Local Crypto Dip Agent'
|
||||
monkeypatch.setattr(validate, 'urlopen', lambda *a, **kw: Response())
|
||||
assert validate.main() == 0
|
||||
output = capsys.readouterr().out
|
||||
label = 'Fee-adjusted closed net: paper ' if prefix == 'paper' else 'Fee-adjusted shadow net: '
|
||||
assert label + expected + ' |' in output
|
||||
Reference in new issue
Block a user