0

I am trying to create a macOS shortcut (with the Shortcuts app) that fetches some stock quotes.

According to this web page, here is how to use the JSON structure:

  1. Open the Shortcuts app
  2. Click on the + sign to create a new shortcut
  3. Add action Get contents of URL
  4. Insert desired URL
  5. Add action Get dictionary from input (which automatically gets the dictionary from the URL)
  6. Add action Get dictionary value
  7. In field key insert fact
  8. Add Show result which will automatically set the variable name to Dictionary Value
  9. Add action Show result
  10. Then click on the play button
  11. Authorise access
  12. A pop-up message appears.

I looked up how Yahoo! Finance the API looks like thanks to this other web page which reveals the following API structure:

{
  "quoteSummary": {
    "result": [
      {
        "financialData": {
          "maxAge": 86400,
          "currentPrice": {
            "raw": 144.49,
            "fmt": "144.49"
          },
          "targetHighPrice": {
            "raw": 214,
            "fmt": "214.00"
          },
          "targetLowPrice": {
            "raw": 122,
            "fmt": "122.00"
          },
          "targetMeanPrice": {
            "raw": 176.69,
            "fmt": "176.69"
          },
          "targetMedianPrice": {
            "raw": 176,
            "fmt": "176.00"
          },
          "recommendationMean": {
            "raw": 1.9,
            "fmt": "1.90"
          },
          "recommendationKey": "buy",
          "numberOfAnalystOpinions": {
            "raw": 41,
            "fmt": "41",
            "longFmt": "41"
          },
          "totalCash": {
            "raw": 48304001024,
            "fmt": "48.3B",
            "longFmt": "48,304,001,024"
          },
          "totalCashPerShare": {
            "raw": 3.036,
            "fmt": "3.04"
          },
          "ebitda": {
            "raw": 130541002752,
            "fmt": "130.54B",
            "longFmt": "130,541,002,752"
          },
          "totalDebt": {
            "raw": 132480000000,
            "fmt": "132.48B",
            "longFmt": "132,480,000,000"
          },
          "quickRatio": {
            "raw": 0.709,
            "fmt": "0.71"
          },
          "currentRatio": {
            "raw": 0.879,
            "fmt": "0.88"
          },
          "totalRevenue": {
            "raw": 394328014848,
            "fmt": "394.33B",
            "longFmt": "394,328,014,848"
          },
          "debtToEquity": {
            "raw": 261.446,
            "fmt": "261.45"
          },
          "revenuePerShare": {
            "raw": 24.317,
            "fmt": "24.32"
          },
          "returnOnAssets": {
            "raw": 0.21214001,
            "fmt": "21.21%"
          },
          "returnOnEquity": {
            "raw": 1.75459,
            "fmt": "175.46%"
          },
          "grossProfits": {
            "raw": 170782000000,
            "fmt": "170.78B",
            "longFmt": "170,782,000,000"
          },
          "freeCashflow": {
            "raw": 90215251968,
            "fmt": "90.22B",
            "longFmt": "90,215,251,968"
          },
          "operatingCashflow": {
            "raw": 122151002112,
            "fmt": "122.15B",
            "longFmt": "122,151,002,112"
          },
          "earningsGrowth": {
            "raw": 0.048,
            "fmt": "4.80%"
          },
          "revenueGrowth": {
            "raw": 0.081,
            "fmt": "8.10%"
          },
          "grossMargins": {
            "raw": 0.43310001,
            "fmt": "43.31%"
          },
          "ebitdaMargins": {
            "raw": 0.33105,
            "fmt": "33.11%"
          },
          "operatingMargins": {
            "raw": 0.30289,
            "fmt": "30.29%"
          },
          "profitMargins": {
            "raw": 0.2531,
            "fmt": "25.31%"
          },
          "financialCurrency": "USD"
        }
      }
    ],
    "error": null
  }
}

And here are the steps I made to get today's AAPL stock valuation:

  1. Open the Shortcuts app
  2. Click on the + sign to create a new shortcut
  3. Add action Get contents of URL
  4. Insert URL https://query1.finance.yahoo.com/v11/finance/quoteSummary/AAPL
  5. Add action Get dictionary from input (which automatically gets the dictionary from the URL)
  6. Add action Get dictionary value
  7. In field key insert financialData
  8. Add action Set variable
  9. Set field Variable Name to financialDataVar
  10. Add action Get dictionary value
  11. In field key insert currentPrice
  12. Add action Set variable
  13. Set field Variable Name to currentPriceVar
  14. Add action Get dictionary value
  15. In field key insert raw
  16. Add action Set variable
  17. Set field Variable Name to rawVar
  18. Add action Text
  19. In the text field, add on under the other: financialDataVar, currentPriceVar, and rawVar
  20. Add action Show alert
  21. Instead of Do you want to continue? insert Text

Clicking on the play button shows a pop-up window, but, unfortunately, without any content.

My questions:

  1. What steps do I have to do in order to get AAPL current stock price when I click on the play button?
  2. Is there a way to ask the user to input their own ticker (say MSFT, or TSLA, etc.)?

1 Answer 1

0

Procedure 1

Steps to get AAPL current stock price when clicking on the play button (one of the ways, at least):

  1. Open the Shortcuts app
  2. Click on the + sign to create a new shortcut
  3. Add action Get contents of URL
  4. Insert URL https://query1.finance.yahoo.com/v1/finance/lookup?query=AAPL*&type=equity
  5. Add action Get dictionary from input (which should automatically gets the dictionary from the URL)
  6. Add action Get Dictionary Value
  7. Insert the following Key: finance
  8. Add action Get Dictionary Value
  9. Insert the following Key: result
  10. Add action Get Dictionary Value
  11. Insert the following Key: documents
  12. Add action Get Dictionary Value
  13. Insert the following Key: regularMarketPrice
  14. Add action Get Dictionary Value
  15. Insert the following Key: raw
  16. Add action Set Variable
  17. Insert a Variable Name, e.g.,: rawShareVar
  18. Add action Show Result
  19. Shortcut should automatically fill the Result with the last variable name (i.e., rawShareVar)
  20. When you click for the first time on play (or Cmd-R), Shortcuts will ask something like: Allow [name of the shortcut] to connect to "query1.finance.yahoo.com"?, click on Allow
  21. A pop-up window appears with the current price of the chosen stock (in this case AAPL)
  22. Click on Done to close the pop-up.

Here below a screen grab of algorithm: Screenshot of the first algorithm.


Procedure 2

Steps to get any stock price by prompting the user when clicking on the play button (one of the ways, at least):

  1. Open the Shortcuts app
  2. Click on the + sign to create a new shortcut
  3. Add action Ask for Input
  4. Check that the action asks for Text
  5. Replace Prompt with Enter a ticker symbol
  6. Add action Set Variable
  7. In the Variable Name field type something like tickerVar
  8. Erase tickerVar that was automatically inserted by the app
  9. Insert URL https://query1.finance.yahoo.com/v1/finance/lookup?query=AAPL*&type=equity
  10. Within the URL erase AAPL
  11. Start typing tickerVar and select it
  12. It should look like this: https://query1.finance.yahoo.com/v1/finance/lookup?query=tickerVar*&type=equity
  13. Add action Get dictionary from input (which should automatically gets the dictionary from the URL)
  14. Add action Get Dictionary Value
  15. Insert the following Key: finance
  16. Add action Get Dictionary Value
  17. Insert the following Key: result
  18. Add action Get Dictionary Value
  19. Insert the following Key: documents
  20. Add action Get Dictionary Value
  21. Insert the following Key: regularMarketPrice
  22. Add action Get Dictionary Value
  23. Insert the following Key: raw
  24. Add action Set Variable
  25. Insert a Variable Name, e.g.,: rawTickerVar
  26. Add action Show Result
  27. The Shortcut app should automatically fill the Result with the last variable name (i.e., rawTickerVar)
  28. When you click for the first time on play (or Cmd-R), Shortcuts will first ask to type the ticker name (e.g., MSFT)
  29. Then it will ask something like: Allow [name of the shortcut] to connect to "query1.finance.yahoo.com"?, click on Allow
  30. A pop-up window appears with the current price of the chosen stock (in this case AAPL)
  31. Click on Done to close the pop-up.

Here below a screen grab of algorithm: Screenshot of the second algorithm.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .