|
Post by meerkat on Jan 10, 2023 10:28:56 GMT -5
Anyone have a routine to get CSV stock prices.
I'm able to get them, but it's messy.
a$ = httpget$("https://finance.yahoo.com/quote/TSLA/history/") open "c:\data\temp\stock.txt" for output as #f print #f,a$ close #f
Then open the file and find the data:
open "c:\data\temp\stock.txt" for input as #f a$ = input$(#f, lof(#f)) close #f
begTime = time$("ms") a = instr(a$,"<span>Volume</span>") + 1
while a > 0 a = instr(a$,"<span>",a) if a = 0 then exit while a1 = instr(a$,"</span>",a) if a1 = 0 then exit while k = a1 - a - 6 'print a1;"|";a;"|";a1 - a;"|";k a1$ = mid$(a$,a+6,k) if left$(a1$,6) = "*Close" then exit while print a1$ a = a1 + 7 WEND endTime = time$("ms")
print "Time:";endTime - begTime end
LB Time:9745 RB Time:270
Ya.. I could have skipped writing to a file and used the data directly from the URL. But I wanted the file to look for other stuff.
Output has Date, Open, High, Low, Close, Ajd Close, and Volume
Aug 23, 2022 291.45 298.83 287.92 296.45 296.45 63,984,900 Aug 22, 2022 291.91 292.40 286.30 289.91 289.91 55,843,200 Aug 19, 2022 299.00 300.36 292.50 296.67 296.67 61,395,300
Thanks for the help...
|
|
|
Post by metro on Jan 10, 2023 11:25:15 GMT -5
G'Day Dan I used to scrape our exchange's site a few years back, then they decided to make it impossible and forced ya to seek 3rd party providers. Now days it's either pay for it eodhistoricaldata.com/ or for me at least my broker provides historical data via CSV downloads. These are a pita coz no api just click one file at a time. I do get an EOD feed of all data for companies in my watch lists from my broker though. Not sure how accurate Yahoo data is. It costs me $440 a year for data In my charting software. Happy hunting... libertybasiccom.proboards.com/post/7353/threadYou may recognise the code in that post, your RB code 7+ years ago
|
|
|
Post by meerkat on Jan 10, 2023 11:48:00 GMT -5
Thanks Laurie... I'll check it out.. My memory is leaving me!!
Dam
|
|
|
Post by pierre on Jan 10, 2023 12:58:01 GMT -5
Strange behaviour.....
the program runs very fast in LB 4.5.1 I get a stock.txt of 1053 kB and a long list of results
in LB5 alpha build 353, the first part stops unexpectedly on the line : print #f, a$ without a documented error and creates a file of 32 kB
in RB I get a runtime error on the first line : a$ = httpget$("https://finance.yahoo.com/quote/TSLA/history/") "handshake_failure"
|
|
|
Post by metro on Jan 10, 2023 18:45:37 GMT -5
Strange behaviour..... in RB I get a runtime error on the first line : a$ = httpget$("https://finance.yahoo.com/quote/TSLA/history/") "handshake_failure" Same here, why!, is beyond my comprehension. Interesting that it also fails retrieving this forum too in RB
'a$="https://libertybasiccom.proboards.com/" 'a$ = "https://finance.yahoo.com/quote/TSLA/history/" a$="http://www.rebol.com/index.html" print httpget$(a$)
|
|
|
Post by metro on Jan 10, 2023 23:59:07 GMT -5
Thanks Laurie... I'll check it out.. My memory is leaving me!! Dam Seems mine has gone
It would appear I have raised the RB issue before (2017) neal hit the nail on the head with
I do miss tinkering with RB
Also your LB code (for me) only downloads half (approx) of the historical data
I only get back to " 22 Aug 2022 Dividend"
I
|
|