Skip to content

Commit

Permalink
Merge pull request #96 from Polymarket/feat/orderbook-ts
Browse files Browse the repository at this point in the history
Adding `timestamp` to orderbook summaries
  • Loading branch information
poly-rodr authored Sep 24, 2024
2 parents e712c58 + 3989a19 commit 9d35d1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions py_clob_client/clob_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def json(self):
class OrderBookSummary:
market: str = None
asset_id: str = None
timestamp: str = None
bids: list[OrderSummary] = None
asks: list[OrderSummary] = None
hash: str = None
Expand Down
1 change: 1 addition & 0 deletions py_clob_client/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def parse_raw_orderbook_summary(raw_obs: any) -> OrderBookSummary:
orderbookSummary = OrderBookSummary(
market=raw_obs["market"],
asset_id=raw_obs["asset_id"],
timestamp=raw_obs["timestamp"],
bids=bids,
asks=asks,
hash=raw_obs["hash"],
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="py_clob_client",
version="0.17.5",
version="0.18.0",
author="Polymarket Engineering",
author_email="[email protected]",
maintainer="Polymarket Engineering",
Expand Down
21 changes: 14 additions & 7 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_parse_raw_orderbook_summary(self):
],
"asks": [],
"hash": "9d6d9e8831a150ac4cd878f99f7b2c6d419b875f",
"timestamp": "123456789",
}

orderbook_summary = parse_raw_orderbook_summary(raw_obs)
Expand All @@ -46,6 +47,7 @@ def test_parse_raw_orderbook_summary(self):
self.assertEqual(
orderbook_summary.hash, "9d6d9e8831a150ac4cd878f99f7b2c6d419b875f"
)
self.assertEqual(orderbook_summary.timestamp, "123456789")

self.assertIsNotNone(orderbook_summary.asks)
self.assertIsNotNone(orderbook_summary.bids)
Expand All @@ -68,6 +70,7 @@ def test_parse_raw_orderbook_summary(self):
"bids": [],
"asks": [],
"hash": "7f81a35a09e1933a96b05edb51ac4be4a6163146",
"timestamp": "123456789",
}

orderbook_summary = parse_raw_orderbook_summary(raw_obs)
Expand All @@ -83,6 +86,7 @@ def test_parse_raw_orderbook_summary(self):
self.assertEqual(
orderbook_summary.hash, "7f81a35a09e1933a96b05edb51ac4be4a6163146"
)
self.assertEqual(orderbook_summary.timestamp, "123456789")

self.assertIsNotNone(orderbook_summary.asks)
self.assertIsNotNone(orderbook_summary.bids)
Expand All @@ -103,21 +107,23 @@ def test_generate_orderbook_summary_hash(self):
{"price": "0.7", "size": "100"},
],
"hash": "",
"timestamp": "123456789",
}

orderbook_summary = parse_raw_orderbook_summary(raw_obs)
self.assertEqual(
generate_orderbook_summary_hash(orderbook_summary),
"b8b72c72c6534d1b3a4e7fb47b81672d0e94d5a5",
"5489da29343426f88622d61044975dc5fd828a27",
)
self.assertEqual(
orderbook_summary.hash,
"b8b72c72c6534d1b3a4e7fb47b81672d0e94d5a5",
"5489da29343426f88622d61044975dc5fd828a27",
)

raw_obs = {
"market": "0xaabbcc",
"asset_id": "100",
"timestamp": "123456789",
"bids": [
{"price": "0.3", "size": "100"},
{"price": "0.4", "size": "100"},
Expand All @@ -126,22 +132,23 @@ def test_generate_orderbook_summary_hash(self):
{"price": "0.6", "size": "100"},
{"price": "0.7", "size": "100"},
],
"hash": "b8b72c72c6534d1b3a4e7fb47b81672d0e94d5a5",
"hash": "5489da29343426f88622d61044975dc5fd828a27",
}

orderbook_summary = parse_raw_orderbook_summary(raw_obs)
self.assertEqual(
generate_orderbook_summary_hash(orderbook_summary),
"b8b72c72c6534d1b3a4e7fb47b81672d0e94d5a5",
"5489da29343426f88622d61044975dc5fd828a27",
)
self.assertEqual(
orderbook_summary.hash,
"b8b72c72c6534d1b3a4e7fb47b81672d0e94d5a5",
"5489da29343426f88622d61044975dc5fd828a27",
)

raw_obs = {
"market": "0xaabbcc",
"asset_id": "100",
"timestamp": "",
"bids": [],
"asks": [],
"hash": "",
Expand All @@ -150,11 +157,11 @@ def test_generate_orderbook_summary_hash(self):
orderbook_summary = parse_raw_orderbook_summary(raw_obs)
self.assertEqual(
generate_orderbook_summary_hash(orderbook_summary),
"7f81a35a09e1933a96b05edb51ac4be4a6163146",
"6d754a2f0304a83544f91a076fa3faa9cbfb9f63",
)
self.assertEqual(
orderbook_summary.hash,
"7f81a35a09e1933a96b05edb51ac4be4a6163146",
"6d754a2f0304a83544f91a076fa3faa9cbfb9f63",
)

def test_order_to_json_0_1(self):
Expand Down

0 comments on commit 9d35d1c

Please sign in to comment.