packages feed

Finance-Quote-Yahoo 0.4.1 → 0.5.0

raw patch · 2 files changed

+38/−15 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Finance.Quote.Yahoo: Daily :: QuoteFrequency
+ Finance.Quote.Yahoo: Dividend :: QuoteFrequency
+ Finance.Quote.Yahoo: Monthly :: QuoteFrequency
+ Finance.Quote.Yahoo: Weekly :: QuoteFrequency
+ Finance.Quote.Yahoo: data QuoteFrequency
- Finance.Quote.Yahoo: getHistoricalQuote :: QuoteSymbol -> Day -> Day -> IO (Maybe [HistoricalQuote])
+ Finance.Quote.Yahoo: getHistoricalQuote :: QuoteSymbol -> Day -> Day -> QuoteFrequency -> IO (Maybe [HistoricalQuote])

Files

Finance-Quote-Yahoo.cabal view
@@ -1,5 +1,5 @@ Name:                Finance-Quote-Yahoo-Version:             0.4.1+Version:             0.5.0 Description:         Obtain quote data from finance.yahoo.com Synopsis:	     Obtain quote data from finance.yahoo.com Category:            Web@@ -14,8 +14,9 @@   Description: Choose the new smaller, split-up base package. Library    if flag(splitBase)-    Build-Depends: base >= 3,containers,network,HTTP,HTTP-Simple,time>=1.1.1,old-locale+    Build-Depends: base >= 3,containers,old-locale   else-    Build-Depends: base < 3,network,HTTP,HTTP-Simple,time>=1.1.1+    Build-Depends: base < 3+  Build-Depends: network,HTTP,HTTP-Simple,time>=1.1.1   GHC-Options:         -O   Exposed-modules:     Finance.Quote.Yahoo
Finance/Quote/Yahoo.hs view
@@ -60,7 +60,7 @@                    Just a -> print a   let startDate = Data.Time.Calendar.fromGregorian 2007 07 01   let endDate = Data.Time.Calendar.fromGregorian 2007 07 03-  h <- getHistoricalQuote (head quoteSymbolList) startDate endDate+  h <- getHistoricalQuote (head quoteSymbolList) startDate endDate Daily   case h of     Nothing -> error \"no historical\"     Just l -> sequence $ Prelude.map print l@@ -71,7 +71,8 @@ module Finance.Quote.Yahoo (getQuote,getHistoricalQuote,defaultQuoteFields,                             baseQuoteURI,baseHistoricalURI,quoteReq,                             QuoteField,QuoteSymbol,QuoteValue,Quote,-                            QuoteCurrency,HistoricalQuote(..)) where+                            QuoteCurrency,QuoteFrequency(..),+                            HistoricalQuote(..)) where import qualified Network.HTTP.Simple as H (httpGet)  import qualified Network.URI as U (parseURI,escapeURIString,                                    isUnescapedInURI) @@ -175,16 +176,22 @@       volume :: Int     } deriving Show +-- | QuoteFrequency - frequency for historical quotes. Exported.+data QuoteFrequency = Daily | Weekly | Monthly | Dividend+ -- | historicalQuoteReq will build a String representation of a  -- Yahoo Finance CSV historical quote request URI. -historicalQuoteReq :: QuoteSymbol -> T.Day -> T.Day -> String-historicalQuoteReq symbol start end = +historicalQuoteReq :: QuoteSymbol -> T.Day -> T.Day -> QuoteFrequency ->+                      String+historicalQuoteReq symbol start end freq =      let (startDay,startMonth,startYear) = dateArgs start-        (endDay,endMonth,endYear) = dateArgs end in+        (endDay,endMonth,endYear) = dateArgs end +        freqChar = freqArg freq in     U.escapeURIString U.isUnescapedInURI           $ baseHistoricalURI ++ "?s=" ++ symbol ++            "&a=" ++ startMonth ++ "&b=" ++ startDay ++ "&c=" ++ startYear ++-           "&d=" ++ endMonth ++ "&e=" ++ endDay ++ "&f=" ++ endYear+           "&d=" ++ endMonth ++ "&e=" ++ endDay ++ "&f=" ++ endYear +++           "&g=" ++ [freqChar]     where       -- Return the string args for the URI.       -- Note when parsing months - for some odd reason Yahoo has decided @@ -196,6 +203,14 @@           month = show $ (read (F.formatTime dtl "%m" t) :: Int) - 1           year = F.formatTime dtl "%Y" t +      -- Return the char Yahoo uses to denote various frequencies+      freqArg :: QuoteFrequency -> Char+      freqArg f = case f of +                    Daily -> 'd'+                    Weekly -> 'w'+                    Monthly -> 'm'+                    Dividend -> 'v'+ -- | parseHistorical takes the raw csv from Yahoo Finance and returns  -- a list of HistoricalQuote entries. parseHistorical :: QuoteSymbol -> QuoteCSV -> Maybe [HistoricalQuote]@@ -236,9 +251,15 @@                               d = read (a!!2) :: Int in                           T.fromGregorian y m d --- | getHistoricalQuote takes a stock symbol and a start and end dates--- and obtains the HistoricalQuote lines for this given range.--- Nothing is returned on any error. Check finance.yahoo.com to see how+-- | getHistoricalQuote takes a stock symbol, start and end date ranges,+-- a quote frequency setting, and obtains the HistoricalQuote lines +-- for this given date range and quote frequency. +-- Supported frequencies are "Daily", "Weekly", +-- "Monthly" or "Dividend". Hopefully these are self-explanatory.+-- Nothing is returned on any error, but note if you ask for the quotes+-- based on Dividend frequency for a stock that pays no dividends, you+-- will not see Nothing, but just an empty result.+-- Check finance.yahoo.com to see how -- far they offer quote history for a symbol you are interested in. -- Note! Yahoo takes some liberties with dates due to weekends and  -- holidays and market closures. Exported.@@ -254,17 +275,18 @@ --                   adjclose \= 26.86\,  --                   volume \= 21011000\} ---getHistoricalQuote :: QuoteSymbol -> T.Day -> T.Day -> +getHistoricalQuote :: QuoteSymbol -> T.Day -> T.Day -> QuoteFrequency ->                      IO (Maybe [HistoricalQuote])-getHistoricalQuote symbol start end = +getHistoricalQuote symbol start end freq =      case end > start of       False -> error("start date must be earlier than end date")       True -> do -        trycsv <- fetchCSV (historicalQuoteReq symbol start end)+        trycsv <- fetchCSV (historicalQuoteReq symbol start end freq)         case trycsv of           Nothing -> return Nothing           Just csv -> return $ parseHistorical symbol csv +-- split and join are copies of those from MissingH split :: Char -> String -> [String] split delim s = if null rest then [token]                              else token : split delim (tail rest)