Sujet : Re: st[awk] market quotes
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.awkDate : 15. Jan 2025, 20:53:40
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250115113407.603@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
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®ion=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/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca