Skip to content

Commit 768c2e8

Browse files
committed
docs: fetchOrderBook example + limit docs in JSDoc
- Add 2028 Presidential Election example to description - Document default 100, max 1000 for range queries - Explain live vs historical query modes
1 parent 5e47b4a commit 768c2e8

2 files changed

Lines changed: 34 additions & 19 deletions

File tree

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [2.43.6] - 2026-05-23
6+
7+
### Improved
8+
9+
- **Docs**: `fetchOrderBook` description now includes a 2028 Presidential Election example, explains historical query modes, and documents default/max limits (100/1000) for range queries.
10+
511
## [2.43.5] - 2026-05-22
612

713
### Fixed

core/src/BaseExchange.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
UserTrade,
1717
} from './types';
1818
import { ExecutionPriceResult, getExecutionPrice, getExecutionPriceDetailed } from './utils/math';
19+
import { logger } from './utils/logger';
1920
import { Throttler } from './utils/throttler';
2021
import type {
2122
FetchMarketMatchesParams,
@@ -467,9 +468,9 @@ export abstract class PredictionMarketExchange {
467468
// Request Interceptor
468469
this.http.interceptors.request.use((config: InternalAxiosRequestConfig) => {
469470
if (this.verbose) {
470-
console.log(`\n[pmxt] → ${config.method?.toUpperCase()} ${config.url}`);
471-
if (config.params) console.log('[pmxt] params:', config.params);
472-
if (config.data) console.log('[pmxt] body:', JSON.stringify(config.data, null, 2));
471+
logger.debug(`-> ${config.method?.toUpperCase()} ${config.url}`);
472+
if (config.params) logger.debug('params:', { params: config.params });
473+
if (config.data) logger.debug('body:', { body: config.data });
473474
}
474475
return config;
475476
});
@@ -478,20 +479,17 @@ export abstract class PredictionMarketExchange {
478479
this.http.interceptors.response.use(
479480
(response: AxiosResponse) => {
480481
if (this.verbose) {
481-
console.log(`\n[pmxt] ← ${response.status} ${response.statusText} ${response.config.url}`);
482-
// console.log('[pmxt] response:', JSON.stringify(response.data, null, 2));
483-
// Commented out full body log to avoid spam, but headers might be useful
482+
logger.debug(`<- ${response.status} ${response.statusText} ${response.config.url}`);
484483
}
485484
return response;
486485
},
487486
(error: any) => {
488487
if (this.verbose) {
489-
console.log(`\n[pmxt] ✖ REQUEST FAILED: ${error.config?.url}`);
490-
console.log('[pmxt] error:', error.message);
491-
if (error.response) {
492-
console.log('[pmxt] status:', error.response.status);
493-
console.log('[pmxt] data:', JSON.stringify(error.response.data, null, 2));
494-
}
488+
logger.debug(`REQUEST FAILED: ${error.config?.url}`, {
489+
error: error.message,
490+
status: error.response?.status,
491+
data: error.response?.data,
492+
});
495493
}
496494
return Promise.reject(error);
497495
}
@@ -854,9 +852,23 @@ export abstract class PredictionMarketExchange {
854852
/**
855853
* Fetch the order book (bids/asks) for a specific outcome.
856854
*
855+
* Supports live and historical queries. For historical data, pass `since`
856+
* to get a single snapshot, or `since` + `until` to get an array of fully
857+
* reconstructed L2 books from the archive. Range queries return up to
858+
* `limit` snapshots (default 100, max 1000).
859+
*
860+
* Example — 2028 Presidential Election order book from last week:
861+
*
862+
* const book = await poly.fetchOrderBook(
863+
* '0xce9a5fa30fe74e323b4a8f15afbb0b7a41a537aa880779ddf7dee22223b2f34a',
864+
* undefined,
865+
* { since: Date.now() - 7 * 24 * 60 * 60 * 1000 }
866+
* );
867+
*
857868
* @param outcomeId - The Outcome ID (outcomeId) or market slug
858-
* @param limit - Max number of bid/ask levels to return (CCXT-style).
859-
* For range queries, limits the number of snapshots returned.
869+
* @param limit - Max number of bid/ask levels to return. For range
870+
* queries (since + until), limits the number of snapshots returned
871+
* (default 100, max 1000).
860872
* @param params - Optional parameters:
861873
* - `side`: 'yes' or 'no' — explicitly indicate the outcome side
862874
* (required for exchanges like Limitless where the API returns a
@@ -898,10 +910,7 @@ export abstract class PredictionMarketExchange {
898910
async fetchTrades(outcomeId: string, params: TradesParams | HistoryFilterParams): Promise<Trade[]> {
899911
// Deprecation warning for resolution parameter
900912
if ('resolution' in params && params.resolution !== undefined) {
901-
console.warn(
902-
'[pmxt] Warning: The "resolution" parameter is deprecated for fetchTrades() and will be ignored. ' +
903-
'It will be removed in v3.0.0. Please remove it from your code.'
904-
);
913+
logger.warn('The "resolution" parameter is deprecated for fetchTrades() and will be ignored. It will be removed in v3.0.0.');
905914
}
906915
throw new Error("Method fetchTrades not implemented.");
907916
}
@@ -1419,7 +1428,7 @@ export abstract class PredictionMarketExchange {
14191428
* @deprecated Use {@link fetchMarketMatches} instead.
14201429
*/
14211430
async fetchMatches(params: FetchMatchesParams): Promise<MatchResult[]> {
1422-
console.warn('[pmxt] fetchMatches is deprecated, use fetchMarketMatches instead');
1431+
logger.warn('fetchMatches is deprecated, use fetchMarketMatches instead');
14231432
return this.fetchMarketMatches(params);
14241433
}
14251434

0 commit comments

Comments
 (0)