OTCBTC SDK for Python
A client for OTCBTC, which supports the OTCBTC public API and Auth API based on the official API documentation, for more information, please read the documentation.
Whether you’re building a custom app or integrating other service into OTCBTC, OTCBTC SDK for Python allows you to leverage the flexibility of Python to get your project up and running as quickly as possible.
PyPI are recommended to install OTCBTC SDK for Python, use pip or pipenv.
pip install otcbtc-client
You need to instantiate an client from OTCBTCClient class first, with your own API_KEY and API_SECRET.
from otcbtc_client.client import OTCBTCClient
auth_client = OTCBTCClient(API_KEY, API_SECRET) # Need to access auth APIs
For public APIs, API_KEY and API_SECRET are not necessary.
client = OTCBTCClient() # Use public APIs only.
In [1]: client.market.all()
Out[1]:
[{'id': 'btceth', 'name': 'BTC/ETH', 'ticker_id': 'btc_eth'},
{'id': 'eoseth', 'name': 'EOS/ETH', 'ticker_id': 'eos_eth'},
{'id': 'bcheth', 'name': 'BCH/ETH', 'ticker_id': 'bch_eth'},
{'id': 'gxseth', 'name': 'GXS/ETH', 'ticker_id': 'gxs_eth'},
{'id': 'zeceth', 'name': 'ZEC/ETH', 'ticker_id': 'zec_eth'},...]
In [1]: client.ticker.all()
Out[1]:
{'ada_btc': {'at': 1526921081,
'ticker': {'buy': '0.0000301',
'high': '0.0000309',
'last': '0.00003027',
'low': '0.0000293',
'open': 2.943e-05,
'sell': '0.0000306',
'vol': '60930.97947734'}},
'ada_eth': {'at': 1526921081,
'ticker': {'buy': '0.00034758',
'high': '0.000372',
'last': '0.00035391',
'low': '0.00034335',
'open': 0.0003498,
'sell': '0.00036176',
'vol': '70583.0778626'}},...}
In [1]: client.ticker.fetch('otbeth')
Out[1]:
{'at': 1526921191,
'ticker': {'buy': '0.00062634',
'high': '0.000655',
'last': '0.00063229',
'low': '0.00061501',
'open': 0.0006402,
'sell': '0.00064',
'vol': '900260.78491758'}}
In [1]: client.order_book.fetch(market='otbeth', asks_limit=1, bids_limit=1)
Out[1]:
{'asks': [{'avg_price': '0.0',
'created_at': '2018-05-22T00:43:18+08:00',
'executed_volume': '0.0',
'id': 37519992,
'market': 'otbeth',
'ord_type': 'limit',
'price': '0.00064',
'remaining_volume': '1107.93650478',
'side': 'sell',
'state': 'wait',
'trades_count': 0,
'volume': '1107.93650478'}],
'bids': [{'avg_price': '0.0',
'created_at': '2018-05-22T00:48:31+08:00',
'executed_volume': '0.0',
'id': 37521683,
'market': 'otbeth',
'ord_type': 'limit',
'price': '0.00062636',
'remaining_volume': '159.65259595',
'side': 'buy',
'state': 'wait',
'trades_count': 0,
'volume': '159.65259595'}]}
Each trade is included only once. Trades are sorted in reverse creation order
In [1]: client.trade.fetch(market='otbeth', limit=1)
Out[1]:
[{'at': 1526921408,
'created_at': '2018-05-22T00:50:08+08:00',
'funds': '0.5631751916118198',
'id': 1813244,
'market': 'otbeth',
'price': '0.00063297',
'side': 'up',
'volume': '889.73441334'}]
Other parameters:
In [1]: client.timestamp.fetch() # or just call client.timestamp()
Out[1]: 1526921749
In [1]: client.kline.fetch(market='otbeth', limit=1)
Out[1]: [[1526921880, 0.00063846, 0.00063846, 0.00063846, 0.00063846, 823.5836]]
Other parameters:
Which are the trades not included in K data yet, because there’s delay between trade generated and processed by K data generator.
In [1]: client.kline.with_pending_trades(market='otbeth', trade_id=1, limit=1)
Out[1]:
{'k': [[1526922180, 0.00063787, 0.00063787, 0.00063787, 0.00063787, 998.8065]],
'trades': []}
In [1]: auth_client.user.fetch()
Out[1]:
{'accounts': [{'balance': '0.0',
'currency': 'eos',
'locked': '0.0',
'saving': '0.0'},
{'balance': '0.0',
'currency': 'btc',
'locked': '0.0',
'saving': '0.0'},...],
'email': '***',
'user_name': '***'}
auth_client.order.list_orders(market=None, state=None, limit=None, page=None, order_by=None)
Paramters:
auth_client.order.list_order(id) # Unique order id
auth_client.order.create_order(market, side, volume, price, ord_type=None)
Parameters:
auth_client.order.cancel_order(id)
auth_client.order.cancel_orders(side=None) # If present, only sell orders (asks) or buy orders (bids) will be canncelled. Vaules: 'sell', 'buy'
Trades are sorted in reverse creation order.
auth_client.trade.my_trades(market, limit=None, timestamp=None, from_=None, to=None, order_by=None)
Parameters: