stocks (empty) → 0.1.0.0
raw patch · 5 files changed
+202/−0 lines, 5 filesdep +aesondep +basedep +bytestringsetup-changed
Dependencies added: aeson, base, bytestring, http-conduit, semigroups
Files
- LICENSE +30/−0
- README.md +34/−0
- Setup.hs +2/−0
- src/Net/Stocks.hs +106/−0
- stocks.cabal +30/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright David Bouchare (c) 2018++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Author name here nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,34 @@+# stocks ++Haskell library for the IEX trading API. ++Example: ++```haskell+{-# LANGUAGE RecordWildCards #-}++import Net.Stocks++comp :: String+comp = "AAPL"++main :: IO ()+main = do+ resp <- getData comp QueryStocks+ case resp of+ Nothing -> putStrLn "No data for that company"+ Just (Stock{..}) -> do+ putStrLn $ "Stock value: " ++ show latestPrice+```++Which should show: ++```+Stock value: <the_actual_stock_value>+```++### Attribution +If you redistribute our API data:++* Cite IEX using the following text and link: “Data provided for free by [IEX](https://iextrading.com/developer).” +* Provide a link to https://iextrading.com/api-exhibit-a in your terms of service.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Net/Stocks.hs view
@@ -0,0 +1,106 @@+{-# LANGUAGE OverloadedStrings #-}++module Net.Stocks+ ( Stock(..)+ , Financials(..)+ , FinancialsList(..)+ , QueryType(..)+ , Company+ , stocksQuery+ , financialsQuery+ , peersQuery+ , priceQuery+ , getData+ , getNonJSONData+ ) where+ +import Control.Monad+import Control.Applicative+import Data.Char+import Data.Aeson+import Data.List.NonEmpty+import Data.ByteString.Lazy.Char8+import Network.HTTP.Conduit++-- | Stock data+data Stock =+ Stock { company :: String -- ^ The company's name+ , latestPrice :: Float -- ^ Latest stock price+ , latestTime :: String -- ^ Timeframe+ , changePercent :: Float -- ^ Percentage change+ } deriving (Show)++instance FromJSON Stock where+ parseJSON = withObject "Stock" $ \v -> Stock+ <$> v .: "companyName"+ <*> v .: "latestPrice"+ <*> v .: "latestTime"+ <*> v .: "changePercent"++newtype FinancialsList = FinancialsList { financialsList :: NonEmpty Financials}++instance FromJSON FinancialsList where+ parseJSON = withObject "FinancialsList" $ \v -> FinancialsList + <$> v .: "financials"++-- | Financials data+data Financials = + Financials { reportDate :: String -- ^ The report's date+ , grossProfit :: Int -- ^ Gross Profit+ , costOfRevenue :: Int -- ^ Cost of revenue+ , cashFlow :: Int -- ^ Cash flow+ } deriving (Show)++instance FromJSON Financials where+ parseJSON = withObject "Financials" $ \v -> Financials+ <$> v .: "reportDate"+ <*> v .: "grossProfit"+ <*> v .: "costOfRevenue"+ <*> v .: "cashFlow"++type Company = String++lowerString :: Company -> String+lowerString str = Prelude.map toLower str++baseURL :: String+baseURL = "https://api.iextrading.com/1.0/stock/"++data QueryType = QueryStocks+ | QueryFinancials+ | QueryPeers+ | QueryPrice++-- builds the URL: /stock/{symbol}/quote+stocksQuery :: Company -> String+stocksQuery company = baseURL ++ lowerString company ++ "/quote"++-- builds the URL: /stock/{symbol}/financials+financialsQuery :: Company -> String+financialsQuery company = baseURL ++ lowerString company ++ "/financials"++-- builds the URL: /stock/{symbol}/peers+peersQuery :: Company -> String+peersQuery company = baseURL ++ lowerString company ++ "/peers"++-- builds the URL: /stock/{symbol}/price+priceQuery :: Company -> String+priceQuery company = baseURL ++ lowerString company ++ "/price"++-- get JSON data +getData :: (FromJSON a) => String -> QueryType -> IO (Maybe a)+getData company qt = do+ obj <- simpleHttp (query qt company)+ return $ decode obj+ where+ query QueryStocks = stocksQuery+ query QueryFinancials = financialsQuery++-- Get non JSON data+getNonJSONData :: String -> QueryType -> IO ByteString+getNonJSONData company qt = do+ obj <- simpleHttp (query qt company)+ return obj+ where+ query QueryPeers = peersQuery+ query QueryPrice = priceQuery
+ stocks.cabal view
@@ -0,0 +1,30 @@+name: stocks+version: 0.1.0.0+synopsis: Library for the IEX Trading API+description: Simple library for interacting with the IEX Trading API+homepage: https://github.com/dabcoder/stocks#readme+license: BSD3+license-file: LICENSE+author: David Bouchare+maintainer: David Bouchare+copyright: 2018 David Bouchare+category: Net+build-type: Simple+cabal-version: >=1.10+extra-source-files: README.md+ +library+ exposed-modules: Net.Stocks+ -- other-modules:+ -- other-extensions:+ build-depends: base == 4.*+ , http-conduit+ , aeson >= 0.8.0+ , bytestring+ , semigroups >= 0.18+ hs-source-dirs: src+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/dabcoder/stocks.git