Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions core/src/BaseExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,19 @@ export abstract class PredictionMarketExchange {
* `Object.values(exchange.markets)` locally.
*
* @param reload - Force a fresh fetch from the API even if markets are already loaded
* @param params - Optional exchange-specific fetch parameters (CCXT-compatible trailing bag)
* @returns Dictionary of markets indexed by marketId
*/
async loadMarkets(reload: boolean = false): Promise<Record<string, UnifiedMarket>> {
async loadMarkets(
reload: boolean = false,
params: MarketFetchParams = {}
): Promise<Record<string, UnifiedMarket>> {
Comment on lines +687 to +690
if (this.loadedMarkets && !reload) {
return this.markets;
}

// Fetch all markets (implementation dependent, usually fetches active markets)
const markets = await this.fetchMarkets();
const markets = await this.fetchMarkets(params);

// Reset caches
this.markets = {};
Expand Down
6 changes: 4 additions & 2 deletions core/src/server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ paths:
properties:
args:
type: array
maxItems: 1
maxItems: 2
items:
type: boolean
oneOf:
Comment on lines 182 to +191
- type: boolean
- type: object
credentials:
$ref: '#/components/schemas/ExchangeCredentials'
responses:
Expand Down
12 changes: 12 additions & 0 deletions core/test/unit/baseExchange.core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,16 @@ describe('BaseExchange public read bounds', () => {
expect(markets).toEqual([MARKET_B]);
expect(exchange.marketCalls).toEqual([undefined]);
});

it('forwards params from loadMarkets to fetchMarkets', async () => {
const exchange = new RecordingExchange();

await exchange.loadMarkets(false, { limit: 1 });

expect(exchange.marketCalls).toEqual([{ limit: 1 }]);
expect(exchange.markets).toEqual({
[MARKET_A.id]: MARKET_A,
[MARKET_B.id]: MARKET_B,
});
});
Comment on lines +60 to +71
});
11 changes: 9 additions & 2 deletions docs/api-reference/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -953,9 +953,16 @@
"properties": {
"args": {
"type": "array",
"maxItems": 1,
"maxItems": 2,
"items": {
"type": "boolean"
"oneOf": [
Comment on lines 954 to +960
{
"type": "boolean"
},
{
"type": "object"
}
]
}
},
"credentials": {
Expand Down
7 changes: 5 additions & 2 deletions sdks/python/pmxt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,9 @@ def call_api(self, operation_id: str, params: Optional[Dict[str, Any]] = None) -

# Market Data Methods

def load_markets(self, reload: bool = False) -> Dict[str, UnifiedMarket]:
def load_markets(
self, reload: bool = False, params: Optional[Dict[str, Any]] = None
) -> Dict[str, UnifiedMarket]:
"""
Load and cache all markets from the exchange into self.markets.
Subsequent calls return the cached result without hitting the API again.
Expand All @@ -1278,6 +1280,7 @@ def load_markets(self, reload: bool = False) -> Dict[str, UnifiedMarket]:

Args:
reload: Force a fresh fetch even if markets are already loaded
params: Optional exchange-specific fetch parameters (CCXT-compatible trailing bag)

Returns:
Dict[str, UnifiedMarket] - All markets indexed by marketId
Expand All @@ -1291,7 +1294,7 @@ def load_markets(self, reload: bool = False) -> Dict[str, UnifiedMarket]:
if self._loaded_markets and not reload:
return self.markets

markets = self.fetch_markets()
markets = self.fetch_markets(params or {})

self.markets = {}
self.markets_by_slug = {}
Expand Down
6 changes: 5 additions & 1 deletion sdks/typescript/pmxt/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,11 +1059,15 @@ export abstract class Exchange {
}
}

async loadMarkets(reload: boolean = false): Promise<Record<string, UnifiedMarket>> {
async loadMarkets(
reload: boolean = false,
params: Record<string, unknown> = {}
): Promise<Record<string, UnifiedMarket>> {
await this.initPromise;
try {
const args: any[] = [];
args.push(reload);
args.push(params);
const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/loadMarkets`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
Expand Down