libcryptomarket: Powerful cryptocurrency market analysis toolkit
Objective
-
Support API calls of top cryptocurrency exchanges
-
Support trading and analysis tools for cryptocurrency market
The project aims to answer the following two questions:
-
How to get historical data, especially a long period, in a single query?
-
How to send exchange API query in an elegent fashion?
Prerequisite
Python 3.5+
Installation
You can install it via pip for static version
pip install libcryptomarket
or development version
pip install git+https://github.com/libcryptomarket/libcryptomarket.git
Exchanges supported
| Exchange | Public API | Private API |
|---|---|---|
| Bitfinex | v | x |
| BitMEX | v | x |
| Bittrex | v | x |
| CoinMarketCap | v | x |
| GDAX | v | x |
| Poloniex | v | v |
Basic Usage
Generic API
You can just make a simple call to query the same function from different exchanges. For example, if you want to get the historical data from GDAX and Bitfinex in a 5 minute timeframe, just call
In [1]: from libcryptomarket.api import GdaxApi, BitfinexApi
In [2]: from libcryptomarket.core import historical_ticker
In [3]: from datetime import datetime
In [4]: ticker1 = historical_ticker(source=GdaxApi(), symbol="BTC-USD", period=300, start_time=datetime(2017, 12, 30, 12, 0, 0), end_time=datetime(2017, 12, 31, 12, 0, 0))
In [5]: ticker2 = historical_ticker(source=BitfinexApi(), symbol="tBTCUSD", period="5m", start_time=datetime(2017, 12, 30, 12, 0, 0), end_time=datetime(2017, 12, 31, 12, 0, 0))
The historical data query automatically rolls over if the exchange response chunk a long period data. It can guarantee that you do not need to write your own logic to get a long period of data.
Exchange API
You can easily initialize an exchange API client and call any method stated
in the exchange API official documentation. The return value is always
the native response from library requests.
For example, to get GDAX order book information,
In [1]: from libcryptomarket.api import GdaxApi
In [2]: exchange = GdaxApi()
In [3]: exchange.products_book(product_id="BTC-USD").json()
Out[3]:
{'asks': [['14903.01', '22.60310282', 18]],
'bids': [['14903', '3.4933731', 2]],
'sequence': 4757644393}
Also, to buy order in Poloniex,
In [1]: from libcryptomarket.api import PoloniexApi
In [2]: exchange = PoloniexApi(public_key="<your public key>", private_key="<your private key>")
In [3]: exchange.buy(currencyPair="BTC_LTC", rate=0.001, amount=0.1, postOnly=1)
The exchange API methods are always delimited by underscore.
| Exchange | Method | libcryptomarket | URL |
|---|---|---|---|
| Bitfinex | candles | BitfinexApi().candles(timeframe="1m", symbol="tBTCUSD", session="hist") |
https://api.bitfinex.com/v2/candles/trade:1m:tBTCUSD/hist |
| BitMEX | trades/bucketed | BitmexApi().trade_bucketed(binSize="1m", symbol="XBTUSD") |
https://www.bitmex.com/api/v1/trade/bucketed?binSize=1m&symbol=XBTUSD |
| Bittrex | /public/getorderbook | BittrexApi().get_order_book(market="BTC-LTC", type="both") |
https://bittrex.com/api/v1.1/public/getorderbook?market=BTC-LTC&type=both |
| CoinMarketCap | ticket// | CoinMarketCapApi().ticker(id="bitcoin", convert="EUR") |
https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR |
| GDAX | /products//candles | GdaxApi().products_candles(product_id="BTC-USD") |
https://api.gdax.com/products/BTC-USD/candles |
| Poloniex | returnOrderBook | PoloniexApi().return_order_book(currencyPair="BTC_NXT", depth=10) |
https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_NXT&depth=10 |
Contribution
The project is targeting as a core but generic toolkit to query cryptocurrency market, so we are happy if you join to contribute and make it better. Please do not hesitate to contact us (gavincyi at gmail dot com).