Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for crypto currencies #5

Merged
merged 29 commits into from
Sep 10, 2017
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6708ed0
adding framework for tracking cryptocoins apis
lockefox Aug 29, 2017
fbcfa9f
adding test framework for coins endpoints
lockefox Aug 29, 2017
d01b56f
adding basic functions for finding/listing valid tickers
lockefox Aug 29, 2017
0ca576e
adding tests for coins.info functions
lockefox Aug 29, 2017
5c3ba27
adding autodocs for coins update
lockefox Aug 29, 2017
fbf344e
adding docs framework for new coins endpoints
lockefox Aug 29, 2017
123a561
updating _version.py to match new template
lockefox Aug 29, 2017
1356df1
adding ticker info fetch function
lockefox Aug 29, 2017
7f8cb9c
updating notes on coins_help
lockefox Aug 30, 2017
8aa0a13
adding links to docs
lockefox Aug 30, 2017
1964ff6
updating README to match new endpoints
lockefox Aug 30, 2017
5257230
adding header to coins.prices
lockefox Aug 30, 2017
8cf875c
adding basic tests for ticker data
lockefox Aug 30, 2017
0e972a9
adding functionality to grab one or all tickers for price data
lockefox Aug 30, 2017
0084ae8
adding test for _listify
lockefox Aug 30, 2017
d2c4088
adding schema for hitbtc orderbook
lockefox Sep 6, 2017
7ea66a9
reorganizing functions and tests for better access to utilities
lockefox Sep 6, 2017
0301540
fixing bug with 3.5 vs OrderedDict
lockefox Sep 6, 2017
db2e962
touching up rh_news tests
lockefox Sep 7, 2017
7d21571
adding coin_list_to_ticker_List function
lockefox Sep 7, 2017
513f1b5
adding code/tests for get_quote_hitbtc()
lockefox Sep 7, 2017
31f3fdb
adding orderbook utility and tests
lockefox Sep 7, 2017
2a0b8e9
removing caching TODO from coins.info
lockefox Sep 7, 2017
eb856fa
updating docs for release
lockefox Sep 7, 2017
c556897
removing cache layer TODO
lockefox Sep 7, 2017
a66bb2e
fixing schema for rh_news - UUID now has data in it
lockefox Sep 10, 2017
5faf346
fixing version.txt include for bdist_wheel
lockefox Sep 10, 2017
eb7c6ff
updating for release as per PR notes
lockefox Sep 10, 2017
3c5953e
updating deploy script to avoid --stash
lockefox Sep 10, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ python:
- "3.5"
- "3.6"
- "3.6-dev" # 3.6 development branch
- "3.7-dev" # 3.7 development branch
# - "3.7-dev" # 3.7 development branch
install:
- "pip install semantic_version"
- "pip install ."
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include prosper/datareader/version.txt
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ Supported Feeds
- Market News Feed: Google
- Price Quote: Robinhood

**Coins**: helper libraries for fetching info on crypto currencies (via `hitBTC`_)

- Ticker Info: get info about coin<->currency conversion metadata
- Price Quote: get latest OHLC data for given coin
- Price History: get history of coin price
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Price history not supported, don't put it in the README

- Order Book: view current orders

.. _pandas-datareader: https://pandas-datareader.readthedocs.io/en/latest/index.html
.. _vader_sentiment: http://www.nltk.org/api/nltk.sentiment.html#module-nltk.sentiment.vader
.. _hitBTC: https://hitbtc.com

.. |Show Logo| image:: http://dl.eveprosper.com/podcast/logo-colour-17_sm2.png
:target: http://eveprosper.com
Expand Down
72 changes: 72 additions & 0 deletions docs/coins_help.rst
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
8 changes: 5 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Supported Feeds

* `Utils`_: General utilities for additional insights
* `Stocks`_: Parse IRL stock quote data

* `Coins`_: Data utilities for cryptocoin price quotes

Index
=====
Expand All @@ -33,9 +33,10 @@ Index
:caption: Contents:

getting_started.rst
utils_help.rst
stocks_help.rst

coins_help.rst
utils_help.rst

Indices and tables
==================

Expand All @@ -47,6 +48,7 @@ Indices and tables
.. _pandas-datareader: https://pandas-datareader.readthedocs.io/en/latest/index.html
.. _Stocks: stocks_help.html
.. _Utils: utils_help.html
.. _Coins: coins_help.html

.. |Build Status| image:: https://travis-ci.org/EVEprosper/ProsperDatareader.svg?branch=master
:target: https://travis-ci.org/EVEprosper/ProsperDatareader
Expand Down
30 changes: 30 additions & 0 deletions docs/source/datareader.coins.rst
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:
1 change: 1 addition & 0 deletions docs/source/datareader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Subpackages

.. toctree::

datareader.coins
datareader.stocks

Submodules
Expand Down
14 changes: 9 additions & 5 deletions prosper/datareader/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ def get_version():

"""
if not INSTALLED:
warnings.warn(
'Unable to resolve package version until installed',
UserWarning
)
return '0.0.0' #can't parse version without stuff installed
try:
with open('version.txt', 'r') as v_fh:
return v_fh.read()
except Exception:
warnings.warn(
'Unable to resolve package version until installed',
UserWarning
)
return '0.0.0' #can't parse version without stuff installed

return p_version.get_version(HERE)

Expand Down
Empty file.
115 changes: 115 additions & 0 deletions prosper/datareader/coins/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
"""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())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure there's a test for unsupported key_name


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()
Loading