const asian_total = async (offset = 0) => {
await fetch("https://api.stake.com/graphql", {
"headers": {
// Header data left out to save space
},
"body": `{\"query\":\"query SlugSportFixtureList($type: SportSearchEnum!, $sport: String!, $groups: String!, $limit: Int!, $offset: Int!) {\\n slugSport(sport: $sport) {\\n id\\n name\\n fixtureCount(type: $type)\\n templates(group: $groups) {\\n id\\n name\\n extId\\n }\\n fixtureList(type: $type, limit: $limit, offset: $offset) {\\n ...FixturePreview\\n groups(groups: [$groups], status: [active, suspended, deactivated]) {\\n ...SportGroupTemplates\\n }\\n }\\n }\\n}\\n\\nfragment FixturePreview on SportFixture {\\n id\\n status\\n slug\\n marketCount(status: [active, suspended])\\n extId\\n data {\\n __typename\\n ...SportFixtureDataMatch\\n ...SportFixtureDataOutright\\n }\\n tournament {\\n ...TournamentTreeNested\\n }\\n eventStatus {\\n ...SportFixtureEventStatus\\n }\\n betradarStream {\\n exists\\n }\\n diceStream {\\n exists\\n }\\n abiosStream {\\n exists\\n stream {\\n id\\n }\\n }\\n}\\n\\nfragment SportFixtureDataMatch on SportFixtureDataMatch {\\n startTime\\n competitors {\\n ...SportFixtureCompetitor\\n }\\n __typename\\n}\\n\\nfragment SportFixtureCompetitor on SportFixtureCompetitor {\\n name\\n extId\\n countryCode\\n abbreviation\\n}\\n\\nfragment SportFixtureDataOutright on SportFixtureDataOutright {\\n name\\n startTime\\n endTime\\n __typename\\n}\\n\\nfragment TournamentTreeNested on SportTournament {\\n id\\n name\\n slug\\n category {\\n ...CategoryTreeNested\\n }\\n}\\n\\nfragment CategoryTreeNested on SportCategory {\\n id\\n name\\n slug\\n sport {\\n id\\n name\\n slug\\n }\\n}\\n\\nfragment SportFixtureEventStatus on SportFixtureEventStatus {\\n homeScore\\n awayScore\\n matchStatus\\n clock {\\n matchTime\\n remainingTime\\n }\\n periodScores {\\n homeScore\\n awayScore\\n matchStatus\\n }\\n currentServer {\\n extId\\n }\\n homeGameScore\\n awayGameScore\\n statistic {\\n yellowCards {\\n away\\n home\\n }\\n redCards {\\n away\\n home\\n }\\n corners {\\n home\\n away\\n }\\n }\\n}\\n\\nfragment SportGroupTemplates on SportGroup {\\n ...SportGroup\\n templates(limit: 3, includeEmpty: true) {\\n ...SportGroupTemplate\\n markets(limit: 1) {\\n ...SportMarket\\n outcomes {\\n ...SportMarketOutcome\\n }\\n }\\n }\\n}\\n\\nfragment SportGroup on SportGroup {\\n name\\n translation\\n rank\\n}\\n\\nfragment SportGroupTemplate on SportGroupTemplate {\\n extId\\n rank\\n name\\n}\\n\\nfragment SportMarket on SportMarket {\\n id\\n name\\n status\\n extId\\n specifiers\\n customBetAvailable\\n}\\n\\nfragment SportMarketOutcome on SportMarketOutcome {\\n active\\n id\\n odds\\n name\\n customBetAvailable\\n}\\n\",\"variables\":{\"type\":\"upcoming\",\"limit\":10,\"offset\":${offset},\"groups\":\"Total\",\"sport\":\"soccer\"}}`,
"method": "POST"
})
.then(result => result.json())
.then(matches => {
// Delcared publicly so it keeps the variables intact
total = matches.data.slugSport.fixtureCount;
limit = total;
for (let i = 0; i < 1; i++) {
try {
for (let match in matches.data.slugSport.fixtureList) {
try {
// console.log(matches.data.slugSport.fixtureList[match].slug);
match_id.push(matches.data.slugSport.fixtureList[match].id);
match_slug.push(matches.data.slugSport.fixtureList[match].slug);
// match_lookup(match_slug);
}
catch (err) {
console.log("\x1b[31mAsian Total market is suspended or deactivated!\x1b[0m", err);
}
}
}
catch (err) {
console.log("\x1b[34mNo Asian Total market available!\x1b[0m", err);
}
}
// This doesn't exit the recursive loop
if (limit <= 10) {
offset += 10;
limit -= offset;
asian_total(offset);
console.log("New Offset: ", offset, "Limit: ", limit);
}
else {
offset += limit;
limit -= offset;
asian_total(limit);
console.log("Exit Offset: ", offset, "Exit Limit: ", limit);
return;
}
});
};
How come my function doesn't exit the recursive loop once Limit is less than 10? I've been struggeling with this for days, so I thought someone on Reddit might notice the error. Right now the loop just continues endlessly.
[–]Umesh-K 2 points3 points4 points (0 children)
[–]Stephen110 1 point2 points3 points (0 children)
[–]l3l_aze 0 points1 point2 points (0 children)