https://github.com/hexresearch/crypto-history
Fetches historical data for cryptocurrencies
https://github.com/hexresearch/crypto-history
Last synced: about 2 months ago
JSON representation
Fetches historical data for cryptocurrencies
- Host: GitHub
- URL: https://github.com/hexresearch/crypto-history
- Owner: hexresearch
- License: bsd-3-clause
- Created: 2018-07-17T09:37:11.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-02-01T02:39:26.000Z (over 7 years ago)
- Last Synced: 2025-01-09T03:56:58.464Z (over 1 year ago)
- Language: Haskell
- Size: 13.7 KB
- Stars: 2
- Watchers: 14
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# crypto-history
Fetches historical data for cryptocurrencies from [coinmarketcap.com](https://coinmarketcap.com/).
With this library we can load and save historical data for various crypto-currencies.
It uses API to [coinmarketcap.com](https://coinmarketcap.com/) to fetch the data.
In the coinmarketcap the currencies are referenced by special ids.
we can query the specific id with the function `getCoinId`:
```haskell
> import Crypto.History
> Right coinId <- getCoinId (CoinCode "ETH")
> print coinId
> CoinId "ethereum"
```
Once we know the id we can query the historical data:
```haskell
> Right hist <- getHistory (dateStr "01-01-2015") (dateStr "01-01-2018") coinId
```
The `dateStr` is a helper function to quickly construct `UTCTime` from string in the format `dd-mm-yyyy`.
Also we can query all time history data:
```haskell
> Right hist <- getAllTimeHistory coinId
```
All prices are relative to USD. But if we want to relate to another currency we can
use a special variant that uses cross-prices to calculate the given relation:
```haskell
> Right hist <- getHistory2 (dateStr "01-01-2015") (dateStr "01-01-2018") (coinIdA, coinIdB)
```
It uses the function `cross :: History -> History -> History` under the hood
to create cross-prices relative to specific coins.
We can save and load the data to/from CSV files:
```haskell
> writeHistory "file.csv" hist
> Just hist <- readHistory "file.csv"
```
The function `readHistory` - reads data strictly. For lazy reading we can use `readHistoryLazy`.