Skip to content

Python load_markets: no None-guard on market.slug causes KeyError/TypeError #156

@realfishsam

Description

@realfishsam

Inconsistency

The Python SDK's load_markets() assigns self.markets_by_slug[market.slug] = market without checking whether market.slug is None, causing a TypeError (unhashable type NoneType) or KeyError at runtime. The TypeScript SDK correctly guards this assignment.

Current (PMXT)

sdks/python/pmxt/client.pyload_markets() method:

self.markets_by_slug[market.slug] = market  # slug can be None → TypeError

TypeScript SDK correctly guards this:

// core/src/BaseExchange.ts (TypeScript)
if (market.slug) {
    this.marketsBySlug[market.slug] = market;
}

Expected (CCXT convention)

CCXT's loadMarkets skips index entries when the key is falsy. The Python SDK should mirror the TypeScript guard:

if market.slug:
    self.markets_by_slug[market.slug] = market

Impact

Any venue that does not set slug on returned markets (e.g. Kalshi markets) will cause load_markets() to raise a TypeError in Python, making the entire exchange instance unusable. This is a runtime crash, not just a type mismatch.

Found by automated PMXT ↔ CCXT API consistency audit

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions