async fetchMarketData() {
        for (let appID of this.appIDs) {
            this.logger.info(`Fetching prices for app ${appID}`);
            let pageIndex = 1;
            let total = 1;
            let fetched = 0;
            do {

                // Make request to API
                let response = await this.queue.resolve(() => fetch(`${API_URL}&appid=${appID}`
                    + `&start=${fetched}&count=${PAGE_SIZE}`));

                if (response.status === 429) {
                    this.logger.warn('Made too many requests (429 status code)');
                    this.logger.warn(`Retrying in ${REQUEST_COOL_DOWN}ms`);
                    await new Promise(resolve => setTimeout(resolve, REQUEST_COOL_DOWN));
                    continue;
                } else if (response.status !== 200) {
                    throw new Error(`Unable to fetch page #${pageIndex}: response code was ${response.status}`);
                }

                let page = await response.json();
                if (!page || Object.keys(page).length === 0)
                    throw new Error('Response is empty');

                if (!page.success)
                    throw new Error(`Unable to fetch page #${pageIndex}`);

                // Adjust total item counter
                if (total !== page['total_count'])
                    total = page['total_count'];

                let results = page['results'];

                // Save to DB
                await this.pushToDB(results);

                fetched += results.length;
                this.logger.info(`Fetched ${fetched} items of ${total}`
                    + ` (${pageIndex} pages, ${Math.floor((fetched / total) * 100)}%)`);
                ++pageIndex;
            } while (fetched < total);
            this.logger.info(`Successfully fetched all prices for app ${appID}`);
        }
    }
/**
     * Retrieves market listings details from Steam.
     * @returns {Promise<void>}
     */
Retrieves market listings details from Steam.
@returns {Promise}
Retrieves market listings details from Steam . @returns { Promise }
async fetchMarketData() {
        for (let appID of this.appIDs) {
            this.logger.info(`Fetching prices for app ${appID}`);
            let pageIndex = 1;
            let total = 1;
            let fetched = 0;
            do {
                let response = await this.queue.resolve(() => fetch(`${API_URL}&appid=${appID}`
                    + `&start=${fetched}&count=${PAGE_SIZE}`));
                if (response.status === 429) {
                    this.logger.warn('Made too many requests (429 status code)');
                    this.logger.warn(`Retrying in ${REQUEST_COOL_DOWN}ms`);
                    await new Promise(resolve => setTimeout(resolve, REQUEST_COOL_DOWN));
                    continue;
                } else if (response.status !== 200) {
                    throw new Error(`Unable to fetch page #${pageIndex}: response code was ${response.status}`);
                }
                let page = await response.json();
                if (!page || Object.keys(page).length === 0)
                    throw new Error('Response is empty');
                if (!page.success)
                    throw new Error(`Unable to fetch page #${pageIndex}`);
                if (total !== page['total_count'])
                    total = page['total_count'];
                let results = page['results'];
                await this.pushToDB(results);
                fetched += results.length;
                this.logger.info(`Fetched ${fetched} items of ${total}`
                    + ` (${pageIndex} pages, ${Math.floor((fetched / total) * 100)}%)`);
                ++pageIndex;
            } while (fetched < total);
            this.logger.info(`Successfully fetched all prices for app ${appID}`);
        }
    }
async fetchMarketData ( ) { for ( let appID of this . appIDs ) { this . logger . info ( ` ${ appID } ` ) ; let pageIndex = 1 ; let total = 1 ; let fetched = 0 ; do { let response = await this . queue . resolve ( ( ) => fetch ( ` ${ API_URL } ${ appID } ` + ` ${ fetched } ${ PAGE_SIZE } ` ) ) ; if ( response . status === 429 ) { this . logger . warn ( 'Made too many requests (429 status code)' ) ; this . logger . warn ( ` ${ REQUEST_COOL_DOWN } ` ) ; await new Promise ( resolve => setTimeout ( resolve , REQUEST_COOL_DOWN ) ) ; continue ; } else if ( response . status !== 200 ) { throw new Error ( ` ${ pageIndex } ${ response . status } ` ) ; } let page = await response . json ( ) ; if ( ! page || Object . keys ( page ) . length === 0 ) throw new Error ( 'Response is empty' ) ; if ( ! page . success ) throw new Error ( ` ${ pageIndex } ` ) ; if ( total !== page [ 'total_count' ] ) total = page [ 'total_count' ] ; let results = page [ 'results' ] ; await this . pushToDB ( results ) ; fetched += results . length ; this . logger . info ( ` ${ fetched } ${ total } ` + ` ${ pageIndex } ${ Math . floor ( ( fetched / total ) * 100 ) } ` ) ; ++ pageIndex ; } while ( fetched < total ) ; this . logger . info ( ` ${ appID } ` ) ; } }
Retrieves market listings details from Steam.
Retrieves market listings details from Steam .
// Make request to API // Adjust total item counter // Save to DB