Sunil Taneja

Sunil Taneja

import "@johnlindquist/kit";
// Menu: Stock Quotes
// Description: Get realtime stock or etf quotes
// Author: Sunil Taneja
// Twitter: @suniltaneja
let stocks_array = ['AAPL', 'GOOG', 'MSFT', 'TSM', 'NVDA']
let stocks_data = []
const transformSymbol = (response) => {
let stock = {}
stock.latestPrice = response.data.latestPrice
stock.change = response.data.change
stock.symbol = response.data.symbol
stock.high = response.data.high ? response.data.high : `NA`
stock.peRatio = response.data.peRatio ? response.data.peRatio : `NA`
return stock
}
for await (let stock of stocks_array){
// free api provided by finaza.io
let query_url = `https://www.finaza.io/api/v1/quote?symbol=${stock.toUpperCase()}&key=scriptkit`
let response = await get(
query_url
);
stocks_data.push(transformSymbol(response))
}
let url = await arg(
`Select Stock:`,
stocks_data.map((e) => {
return {
name: `${e.symbol} ($${e.latestPrice})`,
description: `Change: ${e.change} High: ${e.high} PE Ratio: ${e.peRatio}`,
value: `${e.symbol}`
}
}
)
)
await $`open https://www.finaza.io/stocks/${url}`;