packages feed

yahoo-finance-conduit (empty) → 0.1.0.0

raw patch · 4 files changed

+129/−0 lines, 4 filesdep +attoparsecdep +basedep +cassavasetup-changed

Dependencies added: attoparsec, base, cassava, conduit, lens, mtl, text, vector, wreq

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2014 Alexander Thiemann <mail@agrafix.net>++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Data/Conduit/Finance/Yahoo.hs view
@@ -0,0 +1,80 @@+{-# LANGUAGE OverloadedStrings #-}+module Data.Conduit.Finance.Yahoo+    ( Symbol (..), StockTime (..), StockQuote (..)+    , stockQuoteSource+    )+where++import Control.Applicative+import Control.Concurrent hiding (yield)+import Control.Lens+import Control.Monad.Trans+import Data.Conduit+import Data.Csv+import Data.Monoid+import Network.Wreq+import qualified Data.Attoparsec.ByteString.Char8 as P+import qualified Data.Text as T+import qualified Data.Vector as V++newtype Symbol =+    Symbol { unSymbol :: T.Text }+    deriving (Show, Ord, Eq)++data StockTime+   = StockTime+   { st_hour :: Int+   , st_min :: Int+   } deriving (Show, Ord, Eq)++data StockQuote+   = StockQuote+   { sq_symbol :: Symbol+   , sq_name :: T.Text+   , sq_time :: StockTime+   , sq_ask :: Double+   , sq_bid :: Double+   } deriving (Show, Ord, Eq)++instance FromRecord StockQuote where+    parseRecord v+        | V.length v == 5 =+            StockQuote <$>+            (Symbol <$> v .! 0) <*>+            v .! 1 <*>+            v .! 4 <*>+            v .! 2 <*>+            v .! 3+        | otherwise = fail "Can't parse as StockQuote"++instance FromField StockTime where+    parseField bs =+        case P.parseOnly (dateP <* P.endOfInput) bs of+          Left er -> fail er+          Right val -> return val++dateP :: P.Parser StockTime+dateP =+    do hour <- P.decimal+       _ <- P.string ":"+       minute <-  P.decimal+       amOrPm <- (P.string "am" <|>  P.string "pm")+       let hour' = if amOrPm == "pm" then hour + 12 else hour+       return (StockTime hour' minute)++stockQuoteSource :: MonadIO m => [Symbol] -> Source m StockQuote+stockQuoteSource symbols =+    loop+    where+      loop =+          do r <- liftIO $ get endPoint+             let mVals = decode NoHeader (r ^. responseBody)+             case mVals of+               Left err ->+                   liftIO $ putStrLn ("Error: Failed to parse finance api response: " ++ err)+               Right vals ->+                   mapM_ yield (V.toList vals)+             liftIO $ threadDelay (9 * 100000000) -- 15 minutes+      stockQ = T.intercalate "+" (map unSymbol symbols)+      endPoint =+          T.unpack $ "http://finance.yahoo.com/d/quotes.csv?s=" <> stockQ <> "&f=snabt1"
+ yahoo-finance-conduit.cabal view
@@ -0,0 +1,27 @@+name:                yahoo-finance-conduit+version:             0.1.0.0+synopsis:            Streaming aproach to the yahoo finance api+description:         Small library streaming stock market data from the yahoo finance api+license:             MIT+license-file:        LICENSE+author:              Alexander Thiemann <mail@agrafix.net>+maintainer:          mail@agrafix.net+copyright:           (c) 2014 Alexander Thiemann <mail@agrafix.net>+category:            Data+build-type:          Simple+cabal-version:       >=1.10++library+  exposed-modules:     Data.Conduit.Finance.Yahoo+  build-depends:       base >=4.7 && <4.8,+                       conduit >=1.1 && <1.3,+                       wreq >=0.2 && <0.3,+                       text >=1.1 && <1.2,+                       mtl >=2.2 && <2.3,+                       lens >=4.4 && <4.5,+                       cassava >=0.4 && <0.5,+                       vector >=0.10 && <0.11,+                       attoparsec >=0.12 && <0.13+  hs-source-dirs:      src+  default-language:    Haskell2010+  ghc-options: -Wall -fno-warn-orphans