forked from WW-shan/poly_strategy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_success.py
More file actions
287 lines (249 loc) · 11.8 KB
/
test_success.py
File metadata and controls
287 lines (249 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import json
import tempfile
import unittest
from pathlib import Path
from poly_strategy.success import success_status_report, write_success_status
class SuccessStatusTests(unittest.TestCase):
def test_success_status_prefers_dry_run_execution_plan(self):
with tempfile.TemporaryDirectory() as tmp:
monitor = Path(tmp) / "monitor.jsonl"
plans = Path(tmp) / "plans.ndjson"
maker = Path(tmp) / "maker.json"
monitor.write_text(
json.dumps(
{
"type": "realtime_monitor_iteration",
"stable_paper_trade_count": 1,
"stable_paper_edge": 0.1,
}
)
+ "\n"
)
plans.write_text(
json.dumps(
{
"type": "execution_plan",
"dry_run": True,
"orders": [{"token_id": "yes"}],
"pretrade_check": {"passed": True},
"risk_check": {"passed": True},
}
)
+ "\n"
)
maker.write_text(json.dumps({"status": "positive_ev_config_found", "ranked_configs": []}) + "\n")
report = success_status_report(monitor, plans, maker, generated_at="2026-05-10T00:00:00Z")
self.assertEqual(report["status"], "dry_run_executable")
self.assertTrue(report["dry_run_executable"])
self.assertEqual(report["execution_plans"]["dry_run_passed_count"], 1)
def test_success_status_reports_no_success_for_negative_maker(self):
with tempfile.TemporaryDirectory() as tmp:
maker = Path(tmp) / "maker.json"
maker.write_text(json.dumps({"status": "no_positive_ev_config", "ranked_configs": []}) + "\n")
report = success_status_report(maker_adaptive_path=maker)
self.assertEqual(report["status"], "no_success")
self.assertFalse(report["paper_success_candidate"])
def test_success_status_reports_maker_hedge_positive_ev(self):
with tempfile.TemporaryDirectory() as tmp:
hedge = Path(tmp) / "maker-hedge.json"
hedge.write_text(
json.dumps(
{
"status": "positive_ev_hedge_found",
"batch_count": 10,
"candidate_observation_count": 5,
"completed_count": 1,
"unsafe_fill_count": 0,
"completed_realized_edge_at_cap": 0.25,
"max_completed_realized_edge_at_cap": 0.25,
"top_completed": [{"realized_edge_at_cap": 0.25}],
}
)
+ "\n"
)
report = success_status_report(maker_hedge_path=hedge)
self.assertEqual(report["status"], "maker_hedge_positive_ev")
self.assertTrue(report["paper_success_candidate"])
self.assertEqual(report["maker_hedge"]["completed_count"], 1)
def test_success_status_reports_maker_hybrid_positive_ev(self):
with tempfile.TemporaryDirectory() as tmp:
hybrid = Path(tmp) / "maker-hybrid.json"
hybrid.write_text(
json.dumps(
{
"status": "positive_ev_hybrid_found",
"batch_count": 10,
"candidate_observation_count": 5,
"completed_count": 1,
"unsafe_fill_count": 0,
"partial_maker_fill_count": 0,
"completed_realized_edge_at_cap": 0.35,
"max_completed_realized_edge_at_cap": 0.35,
"top_completed": [{"realized_edge_at_cap": 0.35}],
}
)
+ "\n"
)
report = success_status_report(maker_hybrid_path=hybrid)
self.assertEqual(report["status"], "maker_hybrid_positive_ev")
self.assertTrue(report["paper_success_candidate"])
self.assertEqual(report["maker_hybrid"]["completed_count"], 1)
def test_success_status_ignores_diagnostic_touch_bid_hybrid(self):
with tempfile.TemporaryDirectory() as tmp:
hybrid = Path(tmp) / "maker-hybrid-touch.json"
hybrid.write_text(
json.dumps(
{
"status": "positive_ev_hybrid_found",
"fill_model": "touch_bid",
"completed_count": 1,
"completed_realized_edge_at_cap": 0.35,
"top_completed": [{"realized_edge_at_cap": 0.35}],
}
)
+ "\n"
)
report = success_status_report(maker_hybrid_path=hybrid)
self.assertEqual(report["status"], "no_success")
self.assertFalse(report["paper_success_candidate"])
self.assertEqual(report["maker_hybrid"]["fill_model"], "touch_bid")
def test_success_status_reports_maker_hybrid_tape_candidate(self):
with tempfile.TemporaryDirectory() as tmp:
tape = Path(tmp) / "maker-hybrid-tape.json"
tape.write_text(
json.dumps(
{
"status": "tape_positive_ev_candidate_found",
"fill_model": "trade_tape_sell_through",
"diagnostic_only": True,
"batch_count": 10,
"trade_count": 100,
"candidate_observation_count": 5,
"completed_count": 3,
"unique_completed_count": 1,
"unique_completed_realized_edge_at_cap": 0.21,
"top_unique_completed": [{"realized_edge_at_cap": 0.21}],
}
)
+ "\n"
)
report = success_status_report(maker_hybrid_tape_path=tape)
self.assertEqual(report["status"], "maker_hybrid_tape_positive_ev_candidate")
self.assertTrue(report["paper_success_candidate"])
self.assertTrue(report["maker_hybrid_tape"]["diagnostic_only"])
self.assertEqual(report["maker_hybrid_tape"]["unique_completed_count"], 1)
def test_success_status_requires_min_tape_edge_for_actionable_candidate(self):
with tempfile.TemporaryDirectory() as tmp:
tape = Path(tmp) / "maker-hybrid-tape.json"
tape.write_text(
json.dumps(
{
"status": "tape_positive_ev_candidate_found",
"unique_completed_count": 1,
"unique_completed_realized_edge_at_cap": 0.02,
"top_unique_completed": [{"realized_edge_at_cap": 0.02}],
}
)
+ "\n"
)
report = success_status_report(
maker_hybrid_tape_path=tape,
min_maker_hybrid_tape_edge_at_cap=0.25,
)
self.assertEqual(report["status"], "no_success")
self.assertFalse(report["paper_success_candidate"])
self.assertEqual(report["maker_hybrid_tape"]["actionable_unique_completed_count"], 0)
def test_success_status_reports_cross_platform_paper_opportunity(self):
with tempfile.TemporaryDirectory() as tmp:
scan = Path(tmp) / "cross.json"
scan.write_text(
json.dumps(
{
"type": "cross_platform_scan_report",
"pair_count": 1,
"opportunity_count": 1,
"opportunities": [
{
"net_edge_per_share": 0.001,
"total_edge": 6.0,
"capital_capped": {"edge": 0.1},
"pair": {
"trade_allowed": True,
"status": "verified_same_binary_event",
"llm_verification": {"trade_allowed": True, "risk_flags": []},
},
}
],
}
)
+ "\n"
)
report = success_status_report(cross_platform_scan_path=scan)
self.assertEqual(report["status"], "cross_platform_paper_opportunity")
self.assertTrue(report["paper_success_candidate"])
self.assertEqual(report["cross_platform"]["verified_positive_count"], 1)
self.assertEqual(report["cross_platform"]["actionable_verified_positive_count"], 1)
self.assertEqual(report["cross_platform"]["top_capital_capped_edge"], 0.1)
def test_success_status_ignores_cross_platform_below_actionable_edge(self):
with tempfile.TemporaryDirectory() as tmp:
scan = Path(tmp) / "cross.json"
scan.write_text(
json.dumps(
{
"type": "cross_platform_scan_report",
"pair_count": 1,
"opportunity_count": 1,
"opportunities": [
{
"net_edge_per_share": 0.001,
"total_edge": 6.0,
"capital_capped": {"edge": 0.1},
"pair": {
"trade_allowed": True,
"status": "verified_same_binary_event",
"llm_verification": {"trade_allowed": True, "risk_flags": []},
},
}
],
}
)
+ "\n"
)
report = success_status_report(cross_platform_scan_path=scan, min_cross_platform_capital_edge=0.5)
self.assertEqual(report["status"], "no_success")
self.assertEqual(report["cross_platform"]["verified_positive_count"], 1)
self.assertEqual(report["cross_platform"]["actionable_verified_positive_count"], 0)
def test_success_status_ignores_unverified_cross_platform_positive(self):
with tempfile.TemporaryDirectory() as tmp:
scan = Path(tmp) / "cross.json"
scan.write_text(
json.dumps(
{
"type": "cross_platform_scan_report",
"pair_count": 1,
"opportunity_count": 1,
"opportunities": [
{
"net_edge_per_share": 0.001,
"total_edge": 6.0,
"capital_capped": {"edge": 0.1},
"pair": {"trade_allowed": True},
}
],
}
)
+ "\n"
)
report = success_status_report(cross_platform_scan_path=scan)
self.assertEqual(report["status"], "no_success")
self.assertEqual(report["cross_platform"]["verified_positive_count"], 0)
def test_write_success_status_only_appends_non_empty_statuses(self):
with tempfile.TemporaryDirectory() as tmp:
out = Path(tmp) / "status.json"
log = Path(tmp) / "events.ndjson"
write_success_status(out, {"status": "no_success"}, success_log_path=log)
write_success_status(out, {"status": "maker_positive_ev"}, success_log_path=log)
rows = [json.loads(line) for line in log.read_text().splitlines()]
self.assertEqual(rows, [{"status": "maker_positive_ev"}])
if __name__ == "__main__":
unittest.main()