Fix trade detection: remove infinite pagination loop
- API returns latest 100 trades without pagination support - Previous code was stuck in infinite while loop fetching same trades repeatedly - This prevented initial trade fetch from completing and blocked polling - Now fetches once per poll interval, allowing trades to appear in console - Changed FILTER_BTC_15M_ONLY=false to show all market types - Trades now properly detected and logged with full details
This commit is contained in:
parent
13f55b506a
commit
135059d1d0
@ -80,49 +80,26 @@ export class AccountMonitor {
|
||||
}
|
||||
this.lastFetchTime = Date.now();
|
||||
|
||||
// Fetch all trades with pagination support
|
||||
// Fetch all trades - API returns latest trades, no pagination support
|
||||
let allTrades: any[] = [];
|
||||
let offset = 0;
|
||||
const limit = 100;
|
||||
let hasMore = true;
|
||||
let pageCount = 0;
|
||||
|
||||
while (hasMore) {
|
||||
try {
|
||||
const response = await axios.get(
|
||||
`https://data-api.polymarket.com/trades?user=${accountAddress}`,
|
||||
{ timeout: 10000 }
|
||||
);
|
||||
try {
|
||||
logger.debug(`Fetching trades from API for account: ${accountAddress}`);
|
||||
const response = await axios.get(
|
||||
`https://data-api.polymarket.com/trades?user=${accountAddress}`,
|
||||
{ timeout: 10000 }
|
||||
);
|
||||
|
||||
pageCount++;
|
||||
|
||||
if (!Array.isArray(response.data)) {
|
||||
logger.debug(`API response at offset ${offset} is not an array`);
|
||||
break;
|
||||
}
|
||||
|
||||
if (response.data.length === 0) {
|
||||
logger.debug(`No more trades at offset ${offset}`);
|
||||
hasMore = false;
|
||||
break;
|
||||
}
|
||||
|
||||
allTrades = allTrades.concat(response.data);
|
||||
logger.debug(`Fetched ${response.data.length} trades from API at offset ${offset}, total: ${allTrades.length}`);
|
||||
|
||||
// If we got less than limit, we've reached the end
|
||||
if (response.data.length < limit) {
|
||||
hasMore = false;
|
||||
} else {
|
||||
offset += limit;
|
||||
// Small delay between pagination requests to avoid hammering API
|
||||
await this.sleep(100);
|
||||
}
|
||||
} catch (paginationError) {
|
||||
logger.warn(`Error fetching trades at offset ${offset}`, paginationError);
|
||||
hasMore = false;
|
||||
break;
|
||||
if (!Array.isArray(response.data)) {
|
||||
logger.debug(`API response is not an array`);
|
||||
} else if (response.data.length > 0) {
|
||||
allTrades = response.data;
|
||||
logger.debug(`Fetched ${allTrades.length} trades from API`);
|
||||
} else {
|
||||
logger.debug('No trades fetched from API');
|
||||
}
|
||||
} catch (fetchError) {
|
||||
logger.warn(`Error fetching trades from API`, fetchError);
|
||||
}
|
||||
|
||||
// Reset error counter on successful fetch
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user