Working iterative api query applied over a list of stock symbols. Read from file in scheme, not yet so for perl.
This commit is contained in:
		
							parent
							
								
									80461d7e9c
								
							
						
					
					
						commit
						bb21d54da6
					
				
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1 +1,4 @@
 | 
				
			|||||||
.*.sw*
 | 
					.*.sw*
 | 
				
			||||||
 | 
					backup_*
 | 
				
			||||||
 | 
					test.out
 | 
				
			||||||
 | 
					test.scm
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								stocklist.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								stocklist.conf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					VIU.TO VCN.TO VUN.TO
 | 
				
			||||||
							
								
								
									
										40
									
								
								stockminder.pl
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										40
									
								
								stockminder.pl
									
									
									
									
									
										Executable file
									
								
							@ -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
 | 
					#!/bin/env gxi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(import :std/net/request)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#|(print (request-text
 | 
					(import :std/net/request
 | 
				
			||||||
   (http-get "https://apidojo-yahoo-finance-v1.p.rapidapi.com/market/v2/get-quotes?symbols=AMD%252CIBM%252CAAPL®ion=US"
 | 
						:std/format
 | 
				
			||||||
 | 
						:std/xml
 | 
				
			||||||
 | 
						:std/text/json)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#| Yahoo Finance Headers
 | 
				
			||||||
headers: '( ("x-rapidapi-host" . "apidojo-yahoo-finance-v1.p.rapidapi.com")
 | 
					headers: '( ("x-rapidapi-host" . "apidojo-yahoo-finance-v1.p.rapidapi.com")
 | 
				
			||||||
            ("x-rapidapi-key" . "98c32048f8mshe6f4d8a686ddce9p18cc5ajsn8b8888e7e256") )
 | 
					            ("x-rapidapi-key" . "98c32048f8mshe6f4d8a686ddce9p18cc5ajsn8b8888e7e256") )
 | 
				
			||||||
   )
 | 
					 | 
				
			||||||
) )
 | 
					 | 
				
			||||||
(http-get "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=VBU.TO&apikey=EC4C0NRKZAK1Q2UG")
 | 
					 | 
				
			||||||
(print "Hello, Asshole!")
 | 
					 | 
				
			||||||
|#
 | 
					|#
 | 
				
			||||||
 | 
					; 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
 | 
					(let
 | 
				
			||||||
   ((stock-symbol "VCN.TO")
 | 
					   ((stock-symbols stocklist))
 | 
				
			||||||
   (api-function "TIME_SERIES_DAILY")
 | 
					   (map (lambda (x) (display (string-append
 | 
				
			||||||
   (api-key "EC4C0NRKZAK1Q2UG")
 | 
					         api-url "query?function=" api-function "&symbol=" (symbol->string x) "&apikey=" api-key "\n")))
 | 
				
			||||||
   (api-url "https://www.alphavantage.co/") )
 | 
					      stock-symbols ) )
 | 
				
			||||||
 | 
					 | 
				
			||||||
   (print (request-text (http-get 
 | 
					 | 
				
			||||||
       (string-join (list api-url "query?function=" api-function 
 | 
					 | 
				
			||||||
       "&symbol=" stock-symbol "&apikey=" api-key) "" ) ))) )
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user