I have over 4000 tickers in sqlite3 and when I retrieve the tickers I want to pull the data for each tickers from polygon.io and then save the data to sqlite3. But my problem is when I am iterating the tickers to get the data I get an error, errno: 'ETIMEDOUT', if I rerun it again I get the same error but on a different tickers. So, my question is what am I doing wrong or is it from polygon.
This is my output:
FetchError: request to https://api.polygon.io/v2/aggs/ticker/ITRG/range/1/day/2021-12-27/2021-12-27?adjusted=true&sort=asc&limit=120&apiKey=APIKEY failed, reason: connect ETIMEDOUT 198.44.194.42:443
at ClientRequest.<anonymous> (c:\Users\mo654\OneDrive\Desktop\snapchat2\node_modules\node-fetch\lib\index.js:1461:11)
at ClientRequest.emit (node:events:390:28)
at TLSSocket.socketErrorListener (node:_http_client:447:9)
at TLSSocket.emit (node:events:390:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT'
}
const candle2 = require("./test2");
const AppDAO = require('./dao')
const ProjectRepository = require('./project_repository')
const TaskRepository = require('./task_repository')
async function asyncCall() {
const dao = new AppDAO('./Stocks.db')
const projectRepo = new ProjectRepository(dao)
const taskRepo = new TaskRepository(dao)
const bar = new candle2()
projectRepo.getAll()
.then(ticks =>{
ticks.forEach(element => {
bar.dailyBar(element.Tickers, '2021-12-27', '2021-12-27').then(result =>{
if (result !== undefined){
console.log(result)
for (i = 0; i < result.length; i++){
taskRepo.create(element.Id, result[i].t, result[i].o, result[i].h, result[i].l, result[i].c, result[i].v)
}
}
})
});
})
}
asyncCall()