-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from EVEprosper/btc
Add support for crypto currencies
- Loading branch information
Showing
24 changed files
with
870 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include prosper/datareader/version.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
======================== | ||
prosper.datareader.coins | ||
======================== | ||
|
||
Meant as an extension of `pandas-datareader`_, ``prosper.datareader.coins`` provides the ability to fetch and parse data pertaining to crypto currencies. | ||
|
||
``prosper.datareader.coins`` relies on services from `hitBTC`_. | ||
|
||
Info | ||
==== | ||
|
||
General metadata and feed testing tools. | ||
|
||
**NOTE**: will implement caching layer for info, since this data should only refresh daily | ||
|
||
get_symbol() | ||
------------ | ||
|
||
``symbol_name = coins.info.get_symbol('COIN_TIKER', 'CONVERT_TICKER')`` | ||
|
||
Price of a crypto currency is measured in relation to other currencies a la FOREX. `hitBTC`_ requires a smash-cut version of coin + currency. | ||
|
||
Examples: | ||
|
||
+------+----------+--------+ | ||
| Coin | Currency | Ticker | | ||
+======+==========+========+ | ||
| BTC | USD | BTCUSD | | ||
+------+----------+--------+ | ||
| ETH | EUR | ETHEUR | | ||
+------+----------+--------+ | ||
| ETH | BTC | ETHBTC | | ||
+------+----------+--------+ | ||
|
||
Expected supported currencies: | ||
|
||
- ``USD`` | ||
- ``EUR`` | ||
- ``ETH`` | ||
- ``BTC`` | ||
|
||
For more info, try ``info.supported_currencies()`` for a current list | ||
|
||
get_ticker_info() | ||
----------------- | ||
|
||
``ticker_info = coins.info.get_ticker_info('TICKER')`` | ||
|
||
If working backwards from a ticker, this function returns the original `hitBTC symbols`_ data. | ||
|
||
Prices | ||
====== | ||
|
||
get_quote_hitbtc() | ||
------------------ | ||
|
||
``quote_df = coins.prices.get_quote_hitbtc(['BTC', 'ETH'])`` | ||
|
||
Get a peek at the current price and trend of your favorite crypto currency. This feed helps get OHLC data as well as mimic `pandas-datareader`_ quote behavior with keys like ``pct_change``. | ||
|
||
get_orderbook_hitbtc() | ||
---------------------- | ||
|
||
``orderbook = coins.prices.get_orderbook_hitbtc('BTC', 'asks')`` | ||
|
||
When you absolutely, positively, need all the data... go to the orderbook. This supports ``asks`` and ``bids`` for lookup. | ||
|
||
## TODO: add ``both`` behavior | ||
|
||
.. _pandas-datareader: https://pandas-datareader.readthedocs.io/en/latest/index.html | ||
.. _hitBTC: https://hitbtc.com/ | ||
.. _hitBTC symbols: https://hitbtc.com/api#symbols |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
datareader\.coins package | ||
========================= | ||
|
||
Submodules | ||
---------- | ||
|
||
datareader\.coins\.info module | ||
------------------------------ | ||
|
||
.. automodule:: datareader.coins.info | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
datareader\.coins\.prices module | ||
-------------------------------- | ||
|
||
.. automodule:: datareader.coins.prices | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
|
||
Module contents | ||
--------------- | ||
|
||
.. automodule:: datareader.coins | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ Subpackages | |
|
||
.. toctree:: | ||
|
||
datareader.coins | ||
datareader.stocks | ||
|
||
Submodules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
"""datareader.coins.info.py: tools for fetching cryptocoin metadata""" | ||
from datetime import datetime | ||
import itertools | ||
from os import path | ||
|
||
import requests | ||
import pandas as pd | ||
|
||
from prosper.datareader.config import LOGGER as G_LOGGER | ||
import prosper.datareader.exceptions as exceptions | ||
|
||
LOGGER = G_LOGGER | ||
HERE = path.abspath(path.dirname(__file__)) | ||
|
||
__all__ = ( | ||
'get_symbol', 'get_ticker_info', 'supported_symbol_info' | ||
) | ||
|
||
SYMBOLS_URI = 'http://api.hitbtc.com/api/1/public/symbols' | ||
def get_supported_symbols_hitbtc( | ||
uri=SYMBOLS_URI, | ||
data_key='symbols' | ||
): | ||
"""fetch supported symbols from API | ||
Note: | ||
Supported by hitbtc | ||
https://hitbtc.com/api#symbols | ||
Args: | ||
uri (str, optional): address for API | ||
data_key (str, optional): data key name in JSON data | ||
Returns: | ||
(:obj:`list`): list of supported feeds | ||
""" | ||
req = requests.get(uri) | ||
req.raise_for_status() | ||
data = req.json() | ||
|
||
return data[data_key] | ||
|
||
################################################################################ | ||
|
||
def supported_symbol_info( | ||
key_name | ||
): | ||
"""find unique values for key_name in symbol feed | ||
Args: | ||
key_name (str): name of key to search | ||
Returns: | ||
(:obj:`list`): list of unique values | ||
""" | ||
symbols_df = pd.DataFrame(get_supported_symbols_hitbtc()) | ||
|
||
unique_list = list(symbols_df[key_name].unique()) | ||
|
||
return unique_list | ||
|
||
def get_symbol( | ||
commodity_ticker, | ||
currency_ticker, | ||
logger=LOGGER | ||
): | ||
"""get valid ticker to look up | ||
Args: | ||
commodity_ticker (str): short-name for crypto coin | ||
currency_ticker (str): short-name for currency | ||
logger (:obj:`logging.logger`, optional): logging handle | ||
Returns: | ||
(str): valid ticker for HITBTC | ||
""" | ||
logger.info('--Fetching symbol list from API') | ||
symbols_df = pd.DataFrame(get_supported_symbols_hitbtc()) | ||
|
||
symbol = symbols_df.query( | ||
'commodity==\'{commodity}\' & currency==\'{currency}\''.format( | ||
commodity=commodity_ticker.upper(), | ||
currency=currency_ticker.upper() | ||
)) | ||
|
||
if symbol.empty: | ||
raise exceptions.SymbolNotSupported() | ||
|
||
return symbol['symbol'].iloc[0] | ||
|
||
def get_ticker_info( | ||
ticker, | ||
logger=LOGGER | ||
): | ||
"""reverse lookup, get more info about a requested ticker | ||
Args: | ||
ticker (str): info ticker for coin (ex: BTCUSD) | ||
force_refresh (bool, optional): ignore local cacne and fetch directly from API | ||
logger (:obj:`logging.logger`, optional): logging handle | ||
Returns: | ||
(:obj:`dict`): hitBTC info about requested ticker | ||
""" | ||
logger.info('--Fetching symbol list from API') | ||
data = get_supported_symbols_hitbtc() | ||
|
||
## Skip pandas, vanilla list search ok here | ||
for ticker_info in data: | ||
if ticker_info['symbol'] == ticker.upper(): | ||
return ticker_info | ||
|
||
raise exceptions.TickerNotFound() |
Oops, something went wrong.