Fix trades API 500 by supporting sqlite Row in hold timing.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -55,9 +55,32 @@ def test_hold_dual_leg_uses_group_close():
|
||||
assert h["hold_basis"] == "group"
|
||||
|
||||
|
||||
def test_hold_open_no_close():
|
||||
g = {"open_at_ms": 100, "close_at_ms": None, "status": "open", "close_reason": None}
|
||||
h = hold_timing(g, [])
|
||||
assert h["hold_close_at_ms"] is None
|
||||
assert h["hold_ms"] is None
|
||||
assert h["hold_basis"] == "open"
|
||||
def test_hold_sqlite_row_like_without_get():
|
||||
"""sqlite3.Row 无 .get,需能转 dict。"""
|
||||
|
||||
class Row:
|
||||
def __init__(self, d):
|
||||
self._d = d
|
||||
|
||||
def keys(self):
|
||||
return self._d.keys()
|
||||
|
||||
def __getitem__(self, k):
|
||||
return self._d[k]
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._d)
|
||||
|
||||
g = Row(
|
||||
{
|
||||
"open_at_ms": 100,
|
||||
"close_at_ms": None,
|
||||
"status": "option_residual",
|
||||
"close_reason": "target_perp_only",
|
||||
}
|
||||
)
|
||||
fills = [Row({"leg": "perp", "action": "close", "ts_ms": 400})]
|
||||
h = hold_timing(g, fills)
|
||||
assert h["hold_close_at_ms"] == 400
|
||||
assert h["hold_ms"] == 300
|
||||
|
||||
|
||||
Reference in New Issue
Block a user