Files
crypto_monitor/tests/test_price_snapshot_lib.py
T
2026-07-06 22:04:19 +08:00

36 lines
1.0 KiB
Python

import unittest
from lib.hub.price_snapshot_lib import resolve_order_snapshot_price
class TestPriceSnapshotLib(unittest.TestCase):
def test_resolve_from_cached_prices(self):
px = resolve_order_snapshot_price("ETH/USDT", {"ETH/USDT": 1750.5})
self.assertEqual(px, 1750.5)
def test_resolve_from_position_mark(self):
prow = {"info": {"mark_price": 1760.0}, "contracts": 1}
px = resolve_order_snapshot_price("ETH/USDT", {}, position_row=prow)
self.assertEqual(px, 1760.0)
def test_resolve_mark_fn_before_entry(self):
px = resolve_order_snapshot_price(
"ETH/USDT",
{},
get_mark_price_fn=lambda s: 1755.0,
fallback_entry=1700.0,
)
self.assertEqual(px, 1755.0)
def test_resolve_fallback_entry(self):
px = resolve_order_snapshot_price(
"ETH/USDT",
{},
fallback_entry=1700.0,
)
self.assertEqual(px, 1700.0)
if __name__ == "__main__":
unittest.main()