• st[awk] market quotes

    From Mike Sanders@21:1/5 to All on Wed Jan 15 15:35:29 2025
    #!/bin/sh

    <<NOTES

    st[awk] market quotes: Michael Sanders - 2025

    Admittedly marginally awk releated,
    nevertheless a handy little script.

    Have fun!

    NOTES

    UAS="Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0"

    V1="US Treasury 10 Year Yield|INDEXCBOE:TNX"
    V2="Volatility Index|INDEXCBOE:VIX"
    V3="S&P 500|INDEXSP:INX"
    V4="Nasdaq Composite|INDEXNASDAQ:IXIC"
    V5="Dow Jones Industrial Average|INDEXCBOE:DJX"
    V6="Walmart Inc.|NYSE:WMT"
    V7="Palantir Technologies Inc.|NASDAQ:PLTR"

    clear

    for FOO in "$V1" "$V2" "$V3" "$V4" "$V5" "$V6" "$V7"; do
    NFO=$(echo "$FOO" | cut -d'|' -f1)
    URL=$(echo "$FOO" | cut -d'|' -f2)
    TIK=$(echo "$FOO" | cut -d':' -f2)
    OUT=$(lynx -dump "https://www.google.com/search?q=$URL" | \
    grep -A1 '/ Stock Price' | tail -n1)
    echo "$TIK: $OUT - $NFO" | awk '{$1=$1; print $0 "\n"}'
    done

    # eof

    --
    :wq
    Mike Sanders

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Mike Sanders on Wed Jan 15 19:53:40 2025
    On 2025-01-15, Mike Sanders <porkchop@invalid.foo> wrote:
    #!/bin/sh

    <<NOTES

    st[awk] market quotes: Michael Sanders - 2025

    Get price from ticker, TXR Lisp:

    (defun url (ticker)
    `https://query1.finance.yahoo.com/v7/finance/spark? \
    includePrePost=false&includeTimestamps=false&indicators=close& \
    interval=5m&range=1d&symbols=@ticker&lang=en-US&region=US`)

    (defun path (obj . keys)
    (whilet ((key (pop keys)))
    (set obj [obj key]))
    obj)

    (defun get-stock-json (ticker)
    (command-get-json `curl -s -o - @(sh-esc (url ticker))`))

    (defun get-price (json)
    (path json "spark" "result" 0 "response" 0 "meta" "regularMarketPrice"))

    (match (@ticker) *args*
    (flow ticker get-stock-json get-price prinl))


    Run:


    $ txr stock.tl AAPL
    237.87
    $ txr stock.tl GOOG
    197.7


    Let's adjust the floating point output:


    (match (@ticker) *args*
    (flow ticker get-stock-json get-price (pic `####.####`) put-line))


    $ txr stock.tl AAPL
    238.0270
    $ txr stock.tl GOOG
    197.6650

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)