Skip to content

Instantly share code, notes, and snippets.

Last active July 13, 2023 03:47
Show Gist options
  • Save saiteja09/52f15d4b4f30657af51a1336661884a8 to your computer and use it in GitHub Desktop.
Save saiteja09/52f15d4b4f30657af51a1336661884a8 to your computer and use it in GitHub Desktop.
Stock Widget for iOS using Scriptable
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-blue; icon-glyph: book; share-sheet-inputs: plain-text;
// Stock Ticker Widget
let stocksInfo = await getStockData()
let widget = await createWidget()
if (config.runsInWidget) {
// The script runs inside a widget, so we pass our instance of ListWidget to be shown inside the widget on the Home Screen.
} else {
// The script runs inside the app, so we preview the widget.
// Calling Script.complete() signals to Scriptable that the script have finished running.
// This can speed up the execution, in particular when running the script from Shortcuts or using Siri.
async function createWidget(api) {
let upticker = SFSymbol.named("chevron.up");
let downticker = SFSymbol.named("chevron.down");
let widget = new ListWidget()
// Add background gradient
let gradient = new LinearGradient()
gradient.locations = [0, 1]
gradient.colors = [
new Color("141414"),
new Color("13233F")
widget.backgroundGradient = gradient
for(j=0; j<stocksInfo.length; j++)
let currentStock = stocksInfo[j];
let row1 = widget.addStack();
// Add Stock Symbol
let stockSymbol = row1.addText(currentStock.symbol);
stockSymbol.textColor = Color.white();
stockSymbol.font = Font.boldMonospacedSystemFont(12);
//Add Current Price
let symbolPrice = row1.addText(currentStock.price);
symbolPrice.textColor = Color.white();
symbolPrice.font = Font.boldMonospacedSystemFont(12);
//Second Row
let row2= widget.addStack();
// Add Company name
let companyName= row2.addText(;
companyName.textColor = Color.white();
companyName.textOpacity = 0.7;
companyName.font = Font.boldMonospacedSystemFont(9);
//Add Today's change in price
let changeValue = row2.addText(currentStock.changevalue);
if(currentStock.changevalue < 0) {
changeValue.textColor =;
} else {
changeValue.textColor =;
changeValue.font = Font.boldMonospacedSystemFont(9);
// Add Ticker icon
let ticker = null;
if(currentStock.changevalue < 0){
ticker = row2.addImage(downticker.image);
ticker.tintColor =;
} else {
ticker = row2.addImage(upticker.image);
ticker.tintColor =;
ticker.imageSize = new Size(8,8);
return widget
async function getStockData() {
let stocks = null;
// Read from WidgetParameter if present or use hardcoded values
// Provide values in Widget Parameter as comma seperated list
if(args.widgetParameter == null) {
stocks = ["PRGS", "AAPL", "INR=X", "XRP-USD"];
} else {
stocks = args.widgetParameter.split(",");
let stocksdata = [];
for(i=0; i< stocks.length; i++)
let stkdata = await queryStockData(stocks[i].trim());
let price = stkdata.quoteSummary.result[0].price;
let priceKeys = Object.keys(price);
let data = {};
data.symbol = price.symbol;
data.changepercent = (price.regularMarketChangePercent.raw * 100).toFixed(2);
data.changevalue = price.regularMarketChange.raw.toFixed(2);
data.price = price.regularMarketPrice.raw.toFixed(2);
data.high = price.regularMarketDayHigh.raw.toFixed(2);
data.low = price.regularMarketDayLow.raw.toFixed(2);
data.prevclose = price.regularMarketPreviousClose.raw.toFixed(2); = price.shortName;
return stocksdata;
async function queryStockData(symbol) {
let url = "" + encodeURIComponent(symbol) + "?modules=price"
let req = new Request(url)
return await req.loadJSON()
Copy link

I love this, Are you able do a crypto version?

Edit: Also how to I show Australian stocks, ie A200

This supports crypto as well, all you need to do is add the symbol.

Copy link

Thanks, love this widget!

Copy link

naasi1 commented Aug 10, 2021

Really great widget, love it! Would it be possible to change the currency from Dollar to Euro?

Copy link

How Can i Use This with IE Explorer on Windows ? Thanks

Copy link

Stock Widget for iOS using Scriptable
How Can i Use this with IE Explorer in HTML on Windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment