-
Notifications
You must be signed in to change notification settings - Fork 1
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
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 fbcfa9f
adding test framework for coins endpoints
lockefox d01b56f
adding basic functions for finding/listing valid tickers
lockefox 0ca576e
adding tests for coins.info functions
lockefox 5c3ba27
adding autodocs for coins update
lockefox fbf344e
adding docs framework for new coins endpoints
lockefox 123a561
updating _version.py to match new template
lockefox 1356df1
adding ticker info fetch function
lockefox 7f8cb9c
updating notes on coins_help
lockefox 8aa0a13
adding links to docs
lockefox 1964ff6
updating README to match new endpoints
lockefox 5257230
adding header to coins.prices
lockefox 8cf875c
adding basic tests for ticker data
lockefox 0e972a9
adding functionality to grab one or all tickers for price data
lockefox 0084ae8
adding test for _listify
lockefox d2c4088
adding schema for hitbtc orderbook
lockefox 7ea66a9
reorganizing functions and tests for better access to utilities
lockefox 0301540
fixing bug with 3.5 vs OrderedDict
lockefox db2e962
touching up rh_news tests
lockefox 7d21571
adding coin_list_to_ticker_List function
lockefox 513f1b5
adding code/tests for get_quote_hitbtc()
lockefox 31f3fdb
adding orderbook utility and tests
lockefox 2a0b8e9
removing caching TODO from coins.info
lockefox eb856fa
updating docs for release
lockefox c556897
removing cache layer TODO
lockefox a66bb2e
fixing schema for rh_news - UUID now has data in it
lockefox 5faf346
fixing version.txt include for bdist_wheel
lockefox eb7c6ff
updating for release as per PR notes
lockefox 3c5953e
updating deploy script to avoid --stash
lockefox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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