54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
from poly_updown.prices import _parse_chainlink_message
|
|
|
|
|
|
def test_parse_chainlink_rtds_message() -> None:
|
|
ticks = _parse_chainlink_message(
|
|
{
|
|
"topic": "crypto_prices",
|
|
"type": "update",
|
|
"payload": {
|
|
"symbol": "btc/usd",
|
|
"data": [
|
|
{"timestamp": 1779376675000, "value": 77123.45},
|
|
{"timestamp": 1779376676000, "value": 77124.45},
|
|
],
|
|
},
|
|
}
|
|
)
|
|
|
|
assert len(ticks) == 2
|
|
tick = ticks[-1]
|
|
assert tick is not None
|
|
assert tick.source == "polymarket_rtds_chainlink"
|
|
assert tick.symbol == "btc/usd"
|
|
assert tick.price == 77124.45
|
|
|
|
|
|
def test_parse_chainlink_rtds_sorts_batch_by_timestamp() -> None:
|
|
ticks = _parse_chainlink_message(
|
|
{
|
|
"topic": "crypto_prices",
|
|
"type": "update",
|
|
"payload": {
|
|
"symbol": "btc/usd",
|
|
"data": [
|
|
{"timestamp": 1779376676000, "value": 77124.45},
|
|
{"timestamp": 1779376675000, "value": 77123.45},
|
|
],
|
|
},
|
|
}
|
|
)
|
|
|
|
assert [tick.source_timestamp_ms for tick in ticks] == [1779376675000, 1779376676000]
|
|
assert ticks[-1].price == 77124.45
|
|
|
|
|
|
def test_parse_chainlink_rtds_ignores_other_symbols() -> None:
|
|
assert _parse_chainlink_message(
|
|
{
|
|
"topic": "crypto_prices",
|
|
"type": "update",
|
|
"payload": {"symbol": "eth/usd", "value": 3000},
|
|
}
|
|
) == []
|