Bug Report
Use this template only for issues that fit the Bug definition.
| Term |
Definition |
| Bug |
Behavior that contradicts the platform's documented or intended design as per code, docs, or specs. (i.e., the implementation is incorrect.) |
| Expectation mismatch |
Behavior that follows the platform's documented or intended design but differs from what you expected. (i.e., the design/spec might be the problem.) |
| Enhancement request |
A request for new functionality or behavior that is not implied by existing design. (i.e., "It would be great if the platform could…") |
Note:
- Submitting this issue automatically applies the
bug label.
bug-labeled issues are triaged with higher priority because they require corrective implementation work.
- Expectation mismatches and design-level concerns should be opened as Discussions, or RFCs instead, where they can be validated and discussed to consensus before any work is scheduled.
- The absence of a feature is typically not an expectation mismatch, and should be filed as an enhancement request.
Confirmation
Before opening a bug report, please confirm:
Checking a recent development wheel can save time because the issue may already have been fixed.
You can install a development wheel by running:
pip install -U nautilus_trader --pre --index-url https://packages.nautechsystems.io/simple
See the development-wheels section for more details.
Expected Behavior
PolymarketDataLoader.from_market_slug() should efficiently fetch a single market by slug using the Polymarket API's built-in slug filter parameter, resulting in a single O(1) API call.
The API supports direct slug filtering:
curl "https://gamma-api.polymarket.com/markets?slug=<market-slug>"
# Returns exactly 1 market (filtered server-side)
or:
curl "https://gamma-api.polymarket.com/markets/slug/{slug}"
Actual Behavior
PolymarketDataLoader.from_market_slug() uses an inefficient lookup chain that fetches and iterates through potentially thousands of markets:
Call chain:
from_market_slug() → find_market_by_slug() → fetch_markets() → iterates through all markets in-memory
Two bugs identified:
-
Inefficient market lookup: The implementation fetches batches of markets and searches client-side instead of using the API's slug query parameter for server-side filtering. This results in O(n) performance where n = total number of markets.
-
Originally hardcoded limit=100: fetch_markets() had a hardcoded limit=100 with no pagination, meaning markets beyond position 100 were unreachable, causing polymarket_simple_quoter.py to fail with "Market with slug not found" errors.
Current inefficient code (in find_market_by_slug()):
markets = await PolymarketDataLoader.fetch_markets(
limit=100, ## No pagination support
http_client=http_client,
)
for market in markets:
if market.get("slug") == slug:
return market ## Client side fitlering
Steps to Reproduce the Problem
- Try to load a market that's positioned beyond the first 100 in the API results:
import asyncio
from nautilus_trader.adapters.polymarket.loaders import PolymarketDataLoader
async def test():
# This market is at position ~150
loader = await PolymarketDataLoader.from_market_slug("kamala-harris-divorce-in-2025")
print(f"Found: {loader.instrument.id}")
asyncio.run(test())
-
Observe multiple API calls with pagination instead of a single targeted call.
-
Run examples/backtest/polymarket_simple_quoter.py with a market slug that's not in the first 100 results - it fails with the original code.
Code Snippets or Logs
Affected files:
nautilus_trader/adapters/polymarket/loaders.py (lines ~70, ~252, ~310)
Specifications
- OS platform: macOS 26.1 (also affects all platforms)
- Python version: 3.12.12
nautilus_trader version: develop branch (December 2025)
Bug Report
Use this template only for issues that fit the Bug definition.
Note:
buglabel.bug-labeled issues are triaged with higher priority because they require corrective implementation work.Confirmation
Before opening a bug report, please confirm:
devdevelop oranightly) and can still reproduce it.Checking a recent development wheel can save time because the issue may already have been fixed.
You can install a development wheel by running:
See the development-wheels section for more details.
Expected Behavior
PolymarketDataLoader.from_market_slug()should efficiently fetch a single market by slug using the Polymarket API's built-in slug filter parameter, resulting in a single O(1) API call.The API supports direct slug filtering:
or:
curl "https://gamma-api.polymarket.com/markets/slug/{slug}"Actual Behavior
PolymarketDataLoader.from_market_slug()uses an inefficient lookup chain that fetches and iterates through potentially thousands of markets:Call chain:
from_market_slug()→find_market_by_slug()→fetch_markets()→ iterates through all markets in-memoryTwo bugs identified:
Inefficient market lookup: The implementation fetches batches of markets and searches client-side instead of using the API's
slugquery parameter for server-side filtering. This results in O(n) performance where n = total number of markets.Originally hardcoded limit=100:
fetch_markets()had a hardcodedlimit=100with no pagination, meaning markets beyond position 100 were unreachable, causingpolymarket_simple_quoter.pyto fail with "Market with slug not found" errors.Current inefficient code (in
find_market_by_slug()):Steps to Reproduce the Problem
Observe multiple API calls with pagination instead of a single targeted call.
Run
examples/backtest/polymarket_simple_quoter.pywith a market slug that's not in the first 100 results - it fails with the original code.Code Snippets or Logs
Affected files:
nautilus_trader/adapters/polymarket/loaders.py(lines ~70, ~252, ~310)Specifications
nautilus_traderversion: develop branch (December 2025)