[REBOL] Re: Stock Exchange info Via TCP
From: m:s:licholai:ieee at: 12-Nov-2001 22:03
Hello Tim,
I was just working on something similar, and would be happy to share my solution. Below
is a function which gets stock data from yahoo. Although this function gets historic
data via http, it might be of some use to you. Writing the result of this function will
give you a .csv file with the historic data, which can then be imported into a spreadsheet
or directly manipulated.
Good Luck,
Matt Licholai
--------------------------------------------------------------------------------
REBOL [
Title: "Download stock data as csv"
Date: 10-Nov-2001
Author: "Matt Licholai"
Email: [M--S--Licholai--ieee--org]
File: %get-csv.r
Rights: "(C) Matt Licholai 2001 "
Version: 0.1
History: [0.1 ["Initial version"]]
Purpose: {Get stock data in csv format from Yahoo}
Comment: {Downloads historic data for a stock between two date from Yahoo.
Gets date, open, high, low, close and volume in a comma separated format
for each date within the range. Newest data is at the top of the string.}
Usage: {Example:
get-stock-csv "IBM" 01-Oct-2001 now/date
}
Language: 'English
]
get-stock-csv: func [
{Download historic data for the specified stock from Yahoo}
ticker [string!] "Stock ticker"
start [date!] "data start date"
end [date!] "data end date"
/local
yahoo-url data-path refiner codes id val
][
yahoo-url: http://chart.yahoo.com
data-path: copy "table.csv?"
refiner: func [
str [string!]
const
var
][
append append append append str "&" :const "=" :var
]
codes: compose [
s (ticker)
a start/month
b start/day
c start/year
d end/month
e end/day
f end/year
g d
q q
y 0
z (:ticker)
x .csv
]
foreach [id val] codes [
refiner data-path id val
]
read yahoo-url/:data-path
]