Last active
July 14, 2022 01:21
-
-
Save slebetman/a2fc20624b921b29cf98643b37b16bb2 to your computer and use it in GitHub Desktop.
Code refactor
This file contains 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 portfolio = await prisma.portfolio.findUnique({ where: { id: req.user.id } }) | |
const stocks = await prisma.portfolioStocks.findMany({ | |
where: { | |
owner: { | |
id: 1 | |
} | |
} | |
}) | |
let listOfStocks = stocks.map(x=>x.name) | |
let list=[...new Set(listOfStocks)] //generating list of unique stock names to retrieve price from api | |
let dataPromises = list.map((stock)=>{ | |
return axios.get('https://data.messari.io/api/v1/assets/' + stock + '/metrics/market-data') | |
}) | |
let data = await Promise.all(dataPromises) | |
for (let j=0;j<data.length; j++) { | |
for(let i=0;i<stocks.length;i++){ | |
if(stocks[i].name == data[j].data.data.Asset.name){ | |
stocks[i].currentPrice = data[j].data.data.market_data.price_usd | |
} | |
} | |
} | |
res.send(stocks) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment