Deutsch   English   Français   Italiano  
<20250115113407.603@kylheku.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.awk
Subject: Re: st[awk] market quotes
Date: Wed, 15 Jan 2025 19:53:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <20250115113407.603@kylheku.com>
References: <vm8kk1$30h6u$1@dont-email.me>
Injection-Date: Wed, 15 Jan 2025 20:53:40 +0100 (CET)
Injection-Info: dont-email.me; posting-host="3a20774213740ab96a51eedd1b4dd575";
	logging-data="3254928"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18YIPBxkbcp6mnwe+GzMhtj5ZBGhysYe9E="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Y01tb+1U4y8nE1xeB1bzTOYEv2s=
Bytes: 2028

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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca