Working iterative api query applied over a list of stock symbols. Read from file in scheme, not yet so for perl.

apitesting
Mike Holloway 3 years ago
parent 80461d7e9c
commit bb21d54da6
  1. 3
      .gitignore
  2. 1
      stocklist.conf
  3. 40
      stockminder.pl
  4. 56
      stockminder.scm

3
.gitignore vendored

@ -1 +1,4 @@
.*.sw*
backup_*
test.out
test.scm

@ -0,0 +1 @@
VIU.TO VCN.TO VUN.TO

@ -0,0 +1,40 @@
#!/bin/env perl
# Raw uri https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=VBU.TO&apikey=EC4C0NRKZAK1Q2UG
use strict;
use warnings;
use HTTP::Request;
my $api_uri = "https://www.alphavantage.co/";
my $api_key = "EC4C0NRKZAK1Q2UG";
my @symbols =
(
"VIU.TO",
"VCN.TO",
"VUN.TO"
);
my %functions =
(
"timeseries_intraday", "TIME_SERIES_INTRADAY",
"timeseries_daily", "TIME_SERIES_DAILY",
"timeseries_daily_adj", "TIME_SERIES_DAILY_ADJUSTED",
"timeseries_weekly", "TIME_SERIES_WEEKLY",
"timeseries_weekly_adj", "TIME_SERIES_WEEKLY_ADJUSTED",
"timeseries_monthly", "TIME_SERIES_MONTHLY",
"timeseries_monthly_adj", "TIME_SERIES_MONTHLY_ADJUSTED"
);
foreach my $stock_symbol (@symbols)
{
print $api_uri,
"query?".
"function=",
$functions{'timeseries_daily'},
"&symbol=",
$stock_symbol,
"&apikey=",
$api_key,
"\n";
}

@ -1,24 +1,44 @@
#!/bin/env gxi
(import :std/net/request)
#|(print (request-text
(http-get "https://apidojo-yahoo-finance-v1.p.rapidapi.com/market/v2/get-quotes?symbols=AMD%252CIBM%252CAAPL&region=US"
headers: '( ("x-rapidapi-host" . "apidojo-yahoo-finance-v1.p.rapidapi.com")
("x-rapidapi-key" . "98c32048f8mshe6f4d8a686ddce9p18cc5ajsn8b8888e7e256") )
)
) )
(http-get "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=VBU.TO&apikey=EC4C0NRKZAK1Q2UG")
(print "Hello, Asshole!")
|#
(import :std/net/request
:std/format
:std/xml
:std/text/json)
#| Yahoo Finance Headers
headers: '( ("x-rapidapi-host" . "apidojo-yahoo-finance-v1.p.rapidapi.com")
("x-rapidapi-key" . "98c32048f8mshe6f4d8a686ddce9p18cc5ajsn8b8888e7e256") )
|#
; Declare the file from which we'll load our stockminder configuration
; Things like stock symbols, favourite functions, timing preferences, etc.
(define-values
(stockminder-config stocklist output-file)
(values
(open-input-file "stocklist.conf")
; Initialize our stocklist so we can throw stuff in there after we parse
; the config file.
`()
(open-output-file "test.out") ) )
; The procedure we'll use to iterate through config values and add symbols
; to our stocklist
(define read-config (lambda (config-file)
(let read-loop ((config-chomp (read config-file)))
(if (eof-object? config-chomp)
(close-input-port config-file)
(and (set! stocklist (append stocklist `(,config-chomp)))
(read-loop (read config-file)) ) ) ) ))
; Now the business end; parse the config file
(read-config stockminder-config)
(define-values
(api-function api-url api-key)
(values
"TIME_SERIES_DAILY"
"https://www.alphavantage.co/"
"EC4C0NRKZAK1Q2UG" ) )
(let
((stock-symbol "VCN.TO")
(api-function "TIME_SERIES_DAILY")
(api-key "EC4C0NRKZAK1Q2UG")
(api-url "https://www.alphavantage.co/") )
(print (request-text (http-get
(string-join (list api-url "query?function=" api-function
"&symbol=" stock-symbol "&apikey=" api-key) "" ) ))) )
((stock-symbols stocklist))
(map (lambda (x) (display (string-append
api-url "query?function=" api-function "&symbol=" (symbol->string x) "&apikey=" api-key "\n")))
stock-symbols ) )

Loading…
Cancel
Save