[#16] Support Bittrex Public API

This commit is contained in:
Gavin.Chan
2018-01-07 04:49:42 +00:00
parent 4e1a89a3c6
commit 26463a8921
3 changed files with 104 additions and 0 deletions
+1
View File
@@ -2,6 +2,7 @@
# flake8: noqa
from libcryptomarket.api.bitfinex_api import BitfinexApi
from libcryptomarket.api.bitmex_api import BitmexApi
from libcryptomarket.api.bittrex_api import BittrexApi
from libcryptomarket.api.coinmarketcap_api import CoinMarketCapApi
from libcryptomarket.api.gdax_api import GdaxApi
from libcryptomarket.api.poloniex_api import PoloniexApi
+83
View File
@@ -0,0 +1,83 @@
#!/bin/python
from libcryptomarket.api.exchange_api import ExchangeApi
class BittrexApi(ExchangeApi):
"""Bittrex API.
"""
def __init__(self, public_key=None, private_key=None, logger=None):
"""Constructor.
:param public_key: Public key.
:param private_key: Private key.
:param logger: Logger.
"""
ExchangeApi.__init__(self, public_key, private_key, logger)
@classmethod
def get_url(cls):
"""Get API url.
"""
return "https://bittrex.com/api"
@classmethod
def get_public_calls(cls):
"""Get public API calls.
"""
return {
'getmarkets': 'GET',
'getcurrencies': 'GET',
'getticker': 'GET',
'getmarketsummaries': 'GET',
'getmarketsummary': 'GET',
'getorderbook': 'GET',
'getmarkethistory': 'GET',
'getticks': 'GET',
}
@classmethod
def get_private_calls(cls):
"""Get public API calls.
"""
return {}
@classmethod
def translate_call_name(cls, name):
"""Translate API call name.
The class method name is always underscored (aligned with Python
standard.) This method is to translate underscored name to exchange
API call name.
:param name: Method name (underscored).
"""
return name.replace("_", "")
def _request_public(self, name, http_method, **kwargs):
"""Request public API call.
:param name: Method name.
:param http_method: HTTP method (POST, GET, DELETE).
"""
self.log_info("Public request:\n" +
"name: {}\n".format(name) +
"http_method: {}\n".format(http_method) +
"kwargs: {}".format(kwargs))
if name == 'getticks':
return self._send_request(
command="/v2/public/" + name, http_method=http_method,
public_method=True, params=kwargs)
return self._send_request(
command="/v1.1/public/" + name, http_method=http_method,
public_method=True, params=kwargs)
def _request_private(self, name, http_method, **kwargs):
"""Request private API call.
:param name: Method name.
:param http_method: HTTP method (POST, GET, DELETE).
"""
raise NotImplementedError("Not support private api at this moment.")
+20
View File
@@ -12,6 +12,8 @@ def order_book(source, symbol, depth=5):
if source_name == "poloniex":
return _order_book_poloniex(source, symbol, depth)
elif source_name == "bittrex":
return _order_book_bittrex(source, symbol, depth)
else:
raise ValueError("Source (%s [%s]) does not support order book"
% (source, source_name))
@@ -38,3 +40,21 @@ def _order_book_poloniex(source, symbol, depth=5):
data = pd.concat(data, axis=1).astype('float64')
return data
def _order_book_bittrex(source, symbol, depth=5):
"""Return the order book from Poloniex
:param source: Source, an Exchange API object.
:param symbol: Symbol.
:param depth: Depth of the order book.
"""
response = source.get_order_book(market=symbol, type="both")
response.raise_for_status()
data = response.json()['result']
data = pd.concat([pd.DataFrame(data['buy']), pd.DataFrame(data['sell'])],
axis=1,
keys=['bids', 'asks'])
data.index = data.index + 1
return data