Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdks/python/pmxt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ def load_markets(self, reload: bool = False) -> Dict[str, UnifiedMarket]:

for market in markets:
self.markets[market.market_id] = market
self.markets_by_slug[market.slug] = market

self._loaded_markets = True
return self.markets
Expand Down
10 changes: 10 additions & 0 deletions sdks/python/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ def test_load_markets_caches(self):
"data": [
{
"marketId": "m1",
"slug": "s1",
"title": "Cached",
"outcomes": [],
"volume24h": 0,
Expand All @@ -847,20 +848,25 @@ def test_load_markets_caches(self):
],
})
result1 = ex.load_markets()
markets_by_slug1 = ex.markets_by_slug
assert "m1" in result1
assert "s1" in markets_by_slug1

# Second call should not hit the API again
ex._api_client.call_api.reset_mock()
result2 = ex.load_markets()
markets_by_slug2 = ex.markets_by_slug
ex._api_client.call_api.assert_not_called()
assert result2 is result1
assert markets_by_slug2 is markets_by_slug1

def test_load_markets_reload(self):
ex = self._setup_exchange_with_response({
"success": True,
"data": [
{
"marketId": "m1",
"slug": "s1",
"title": "Orig",
"outcomes": [],
"volume24h": 0,
Expand All @@ -877,6 +883,7 @@ def test_load_markets_reload(self):
"data": [
{
"marketId": "m2",
"slug": "s2",
"title": "New",
"outcomes": [],
"volume24h": 0,
Expand All @@ -889,6 +896,9 @@ def test_load_markets_reload(self):
result = ex.load_markets(reload=True)
assert "m2" in result
assert "m1" not in result
markets_by_slug = ex.markets_by_slug
assert "s2" in markets_by_slug
assert "s1" not in markets_by_slug

# -- close --

Expand Down
Loading