Skip to main content

OTCBTC SDK for Python

Project description

otcbtc-client

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.

PyPI PyPI - License PyPI - Python Version Build Status codecov

Overview

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.

Installation

PyPI are recommended to install OTCBTC SDK for Python, use pip or pipenv.

pip install otcbtc-client

Usage

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.

Market

Get all available markets(Public API)

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'},...]

Ticker

Get ticker of all markets(Public API)

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'}},...}

Get ticker of specific market(Public API)

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'}}

Order Book

Get the order book of specified market(Public API)

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'}]}

Trade

Get recent trades on market(Public Api)

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:

  • timestamp: An integer represents the seconds elapsed since Unix epoch. If set, only trades executed before the time will be returned.
  • from_: Trade id. If set, only trades created after the trade will be returned.
  • to: Trade id. If set, only trades created before the trade will be returned.
  • order_by: If set, returned trades will be sorted in specific order, default to 'desc’.

Timestammp

Get server current time, in seconds since Unix epoch(Public API)

In [1]: client.timestamp.fetch() # or just call client.timestamp()
Out[1]: 1526921749

Kline

Get OHLC(k line) of specific market(Public API)

In [1]: client.kline.fetch(market='otbeth', limit=1)
Out[1]: [[1526921880, 0.00063846, 0.00063846, 0.00063846, 0.00063846, 823.5836]]

Other parameters:

  • period: Time period of K line, default to 1. You can choose between 1, 5, 15, 30, 60, 120, 240, 360, 720, 1440, 4320, 10080. Default value : 1
  • timestamp: An integer represents the seconds elapsed since Unix epoch. If set, only k-line data after that time will be returned.

Klines with pending trades

Get K data with pending trades(Public API)

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': []}

User

Get your profile and accounts info(Auth API)

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': '***'}

List Orders

Get your orders, results is paginated(Auth API)

auth_client.order.list_orders(market=None, state=None, limit=None, page=None, order_by=None)

Paramters:

  • market: Unique market id. It’s always in the form of xxxyyy, where xxx is the base currency code, yyy is the quote currency code, e.g. 'otbeth'. All available markets can be found at /api/v2/markets. If left blank, the api will return your orders of all markets.
  • state: Filter order by state, default to 'wait' (active orders). Other options:'cancel', 'done'
  • limit: Limit the number of returned price levels. Default to 100.
  • page: Specify the page of paginated results. Default value: 1
  • order_by: If set, returned trades will be sorted in specific order, default to 'asc'.

List Order

Get information of specified order(Auth API)

auth_client.order.list_order(id) # Unique order id

Create Order

Create a Sell/Buy order(Auth API)

auth_client.order.create_order(market, side, volume, price, ord_type=None)

Parameters:

  • market(required): Unique market id. It’s always in the form of xxxyyy, where xxx is the base currency code, yyy is the quote currency code, e.g. 'otbeth'. All available markets can be found at /api/v2/markets.
  • side(required): Either 'sell' or 'buy'.
  • volume(required): The amount user want to sell/buy. An order could be partially executed, e.g. an order sell 100 otb can be matched with a buy 60 otb order, left 40 otb to be sold; in this case the order’s volume would be '100.0', its remaining_volume would be '40.0', its executed volume is '60.0'.
  • price: Price for each unit. e.g. If you want to sell/buy 1 otb at 0.002 ETH, the price is ‘0.002’.
  • ord_type: Type of order, now only 'limit'.

Cancel Order

Cancel an order(Auth API)

auth_client.order.cancel_order(id)

Cancel Orders

Cancel all your orders(Auth API)

auth_client.order.cancel_orders(side=None) # If present, only sell orders (asks) or buy orders (bids) will be canncelled. Vaules: 'sell', 'buy'

My Trades

Get your executed trades(Auth API)

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:

  • market(required): Unique market id. It’s always in the form of xxxyyy, where xxx is the base currency code, yyy is the quote currency code, e.g. 'otbeth'. All available markets can be found at /api/v2/markets.
  • limit: Limit the number of returned trades. Default to 50. Range 1..1000
  • timestamp: An integer represents the seconds elapsed since Unix epoch. If set, only trades executed before the time will be returned.
  • from: Trade id. If set, only trades created after the trade will be returned.
  • to: Trade id. If set, only trades created before the trade will be returned.
  • order_by:If set, returned trades will be sorted in specific order, default to 'desc'. Values: 'asc', 'desc'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

otcbtc_client-0.2.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

otcbtc_client-0.2.1-py2.py3-none-any.whl (10.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file otcbtc_client-0.2.1.tar.gz.

File metadata

  • Download URL: otcbtc_client-0.2.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for otcbtc_client-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0baadb6ce018e39ec7426b72a5d91fd4bd274b349b8d3149fb126b6e99f3171e
MD5 04265e194541ca2ccec9babb8153d3f5
BLAKE2b-256 be8c3ddc090f542b02c835c2439f6f190287f6e741034004a778437a0a839d71

See more details on using hashes here.

File details

Details for the file otcbtc_client-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: otcbtc_client-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

File hashes

Hashes for otcbtc_client-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8332816dfd9d4ed2807e1256b64372daa12c86275c232af86e225e968e8e5b25
MD5 e1aa0776342dcc184370b9009c16c2ee
BLAKE2b-256 948d126500d4039c4069475f33b7c2d934a76846ea60a4565877745f9a8e439f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page