Last active
July 5, 2018 15:52
-
-
Save amchercashin/9e1f1c03c920024ff32e08358c04b625 to your computer and use it in GitHub Desktop.
asyncAPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
async function getLastRecord(indexID) { | |
const response = await axios.get("http://iss.moex.com/iss/history/engines/stock/markets/index/securities/" + indexID + ".json?limit=1"); | |
const lastRecord = response.data["history.cursor"]["data"][0][1]; | |
return lastRecord; | |
} | |
async function getDataAsync(indexID) { | |
const lastRecord = await getLastRecord(indexID); | |
let promises = []; | |
let data = []; | |
for (let i = 0; i < lastRecord; i += 100) { | |
promises.push(axios.get("http://iss.moex.com/iss/history/engines/stock/markets/index/securities/" + indexID + ".json?start=" + i)); | |
} | |
const results = await Promise.all(promises); | |
data = results.reduce((acc, val) => acc.concat(val.data.history.data), []); | |
return(data); | |
} | |
async function printData(indexID) { | |
let data = await getDataAsync(indexID); | |
console.log(data.length) | |
} | |
printData("MICEX10INDEX"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment