Copyright | (c) 2014 Peter van den Brand |
---|---|
License | BSD3 |
Maintainer | Peter van den Brand <peter@vdbrand.nl> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
This library provides an easy way to download data from Quandl.com. See http://www.quandl.com/help/api for detailed information on the Quandl API.
For basic usage, see the getTable
function. This function is all you need to download tables.
For more advanced usage, see the getTableWith
function. This function allows you
to use query a subset of the data, query multiple tables (multisets),
apply frequency conversions, and apply transformations supported by Quandl.
- getTable :: String -> String -> Maybe String -> IO (Maybe Dataset)
- defaultOptions :: Options
- getTableWith :: Options -> [(String, String, Maybe Int)] -> IO (Maybe Dataset)
- search :: [String] -> Maybe String -> Maybe Int -> Maybe Int -> IO (Maybe SearchPage)
- data Options = Options {}
- data Frequency
- data Transformation
- data Dataset = Dataset {
- daTable :: Maybe Metadata
- daColumnNames :: [Text]
- daData :: [[Text]]
- daFromDate :: Day
- daToDate :: Day
- daFrequency :: Text
- data Metadata = Metadata {
- meId :: Int
- meSourceCode :: String
- meTableCode :: String
- meSourceName :: Text
- meTableName :: Text
- meUrlName :: Text
- meDescription :: Text
- meSourceUrl :: Text
- meUpdatedAt :: UTCTime
- mePrivate :: Bool
- data SearchSource = SearchSource {}
- data SearchDoc = SearchDoc {
- sdSourceCode :: Text
- sdDisplayUrl :: Maybe Text
- sdPrivate :: Bool
- sdUrlizeName :: Text
- sdName :: Text
- sdFromDate :: Day
- sdDescription :: Text
- sdColumnNames :: [Text]
- sdFrequency :: Text
- sdSourceName :: Text
- sdUpdatedAt :: UTCTime
- sdToDate :: Day
- sdCode :: Text
- data SearchPage = SearchPage {
- spTotalCount :: Int
- spCurrentPage :: Int
- spPerPage :: Int
- spSources :: [SearchSource]
- spDocs :: [SearchDoc]
- downloadJSON :: Options -> [(String, String, Maybe Int)] -> IO ByteString
- createUrl :: Options -> [(String, String, Maybe Int)] -> String
Download a whole table at once
:: String | Quandl code for the source |
-> String | Quandl code for the table |
-> Maybe String | Auth code |
-> IO (Maybe Dataset) | Dataset returned by Quandl, or |
Download all rows and columns from a single table. To get all data points for the dataset FRED/GDP:
getTable "FRED" "GDP" Nothing
Registered users should include their auth_token, like this:
getTable "FRED" "GDP" (Just "dsahFHUiewjjd")
Download using API parameters
defaultOptions :: Options Source
Default options to use for Quandl API calls. The default options do not use an auth token and will return all rows in descending order.
:: Options | API parameters |
-> [(String, String, Maybe Int)] | List of (source, table, column) items to retrieve. |
-> IO (Maybe Dataset) | Dataset returned by Quandl, or |
Download data from Quandl using the full API. This function supports all data manipulation options, plus downloading from multiple datasets (multisets).
For example, here is the annual percentage return for AAPL stock over the previous decade, in ascending date order:
import Data.Quandl import Data.Time (fromGregorian) getTableWith (defaultOptions {opSortAscending = True, opStartDate = Just (fromGregorian 2000 1 1), opEndDate = Just (fromGregorian 2010 1 1), opFrequency = Just Annual, opTransformation = Just RDiff}) [("WIKI", "AAPL", Just 4)] -- Just 4 means we only want the 4'th column (Close price)
You can pull data from multiple datasets (or from multiple columns in a single dataset) using this function as well. In the example below, we combine US GDP from FRED/GDP, crude oil spot prices from DOE/RWTC, and Apple closing prices from WIKI/AAPL. We are going to convert all of them to annual percentage changes, and look only at data for the last 10 years.
import Data.Quandl getTableWith (defaultOptions {opNumRows = Just 10, opFrequency = Just Annual, opTransformation = Just RDiff}) [("FRED", "GDP", Just 1), ("DOE", "RWTC", Just 1), ("WIKI", "AAPL", Just 4)]
Please note that Quandl does not return the table metadata when pulling data from multiple datasets.
In that case the daTable
field of the returned Dataset
will be Nothing
.
Search for a table
:: [String] | List of search terms |
-> Maybe String | Auth Token |
-> Maybe Int | Number to display per page or Nothing |
-> Maybe Int | Page number to display or Nothing |
-> IO (Maybe SearchPage) | Search results from Quandl, or Nothing if parsing failed. |
Search for terms, returning given page
Datatypes
API parameters supported by Quandl, for use with the getTableWith
function.
See http://www.quandl.com/help/api for detailed information.
Options | |
|
Desired frequency of returned results. See http://www.quandl.com/help/api for detailed information.
data Transformation Source
Desired transformation of returned results. See http://www.quandl.com/help/api for detailed information.
Results from a Quandl API call.
Dataset | |
|
Metadata of a table. Only returned by Quandl when downloading from a single table.
Metadata | |
|
SearchDoc | |
|
data SearchPage Source
SearchPage | |
|
Low-level functions
downloadJSON :: Options -> [(String, String, Maybe Int)] -> IO ByteString Source
Returns unparsed JSON from a Quandl API call.