Skip to content

Commit 119543d

Browse files
committed
WIP
Signed-off-by: Herklos <herklos@drakkar.software>
1 parent 113dd63 commit 119543d

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

ts/src/polymarket.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,8 +1140,24 @@ export default class polymarket extends Exchange {
11401140
*/
11411141
async fetchTicker (symbol: string, params = {}): Promise<Ticker> {
11421142
await this.loadMarkets ();
1143-
const market = this.market (symbol);
1144-
const marketInfo = this.safeDict (market, 'info', {});
1143+
let market: Market = undefined;
1144+
try {
1145+
market = this.market (symbol);
1146+
} catch (e) {
1147+
market = undefined;
1148+
}
1149+
if (market === undefined) {
1150+
const conditionId = this.safeString2 (params, 'condition_id', 'conditionId');
1151+
const slug = this.safeString (params, 'slug');
1152+
const tokenIdParam = this.safeString (params, 'token_id');
1153+
const fallbackId = conditionId || slug || tokenIdParam || symbol;
1154+
try {
1155+
market = this.safeMarketWithFallback (fallbackId, undefined, params);
1156+
} catch (e) {
1157+
market = undefined;
1158+
}
1159+
}
1160+
const marketInfo = market ? this.safeDict (market, 'info', {}) : {};
11451161
// Get token ID from params or market
11461162
// Use market['id'] which is the specific token ID for this outcome (YES/NO)
11471163
// Do NOT use clobTokenIds[0] as that always picks the first outcome regardless of symbol
@@ -1357,7 +1373,21 @@ export default class polymarket extends Exchange {
13571373
*/
13581374
parseTicker (ticker: Dict, market: Market = undefined): Ticker {
13591375
// Polymarket ticker format from market data
1360-
const symbol = market ? market['symbol'] : undefined;
1376+
let symbol = market ? market['symbol'] : undefined;
1377+
if (market === undefined) {
1378+
const conditionId = this.safeString2 (ticker, 'condition_id', 'conditionId');
1379+
const slug = this.safeString (ticker, 'slug');
1380+
const tokenId = this.safeString (ticker, 'token_id');
1381+
const fallbackId = conditionId || slug || tokenId;
1382+
if (fallbackId !== undefined || slug !== undefined) {
1383+
try {
1384+
market = this.safeMarketWithFallback (fallbackId || slug, undefined, ticker);
1385+
symbol = this.safeString (market, 'symbol', symbol);
1386+
} catch (e) {
1387+
// Ignore fallback errors and proceed without market
1388+
}
1389+
}
1390+
}
13611391
// Parse outcome prices
13621392
const outcomePricesStr = this.safeString (ticker, 'outcomePrices');
13631393
const outcomePrices = [];
@@ -6004,4 +6034,3 @@ export default class polymarket extends Exchange {
60046034
return undefined;
60056035
}
60066036
}
6007-

0 commit comments

Comments
 (0)