Skip to main content

HitBTC API Client library

Project description

hitbtcapi 1.0

REST API Client for HitBTC

logo

Features

  • Convenient methods for making API calls using keyword arguments

    • Automatic classification into form-data or query parameters

    • Automatic packing into JSON

  • Near 100% test coverage.

  • Tab-completable methods and attributes when using IPython.

Dependencies

Install the required dependencies with

$ pip install -r requirements.txt # for api
$ pip install -r requirements_test.txt # for tests

Installation

hitbtcapi is available on PYPI. Install with pip:

$ pip install hitbtcapi

or with easy_install:

$ easy_install hitbtcapi

The library is currently tested against Python versions 2.7 and 3.4+.

API Reference

The official documentation can be found on the HitBTC API reference page. You can also explore the API using Swagger UI.

Prerequisites

The first thing you need to do is to Sign Up with HitBTC.

Next, you need to obtain an API Key and an API Secret. If you’re writing code for your own HitBTC account, you can create API keys on HitBTC API Settings page. You can create multiple API keys with different permissions for your applications.

NOTE: Make sure to enable appropriate permissions for the API key (some require email confirmation).

Getting started

Create a Client object for interacting with the API:

from hitbtcapi.client import Client

api_key = 'your api key'
api_secret = 'your api secret'

client = Client(api_key,api_secret)

Error handling

All errors occurring during interaction with the API will be raised as exceptions. These exceptions will be subclasses of hitbtcapi.errors.HitBTCError. When the error involves an API request and/or response, the error will be a subclass of hitbtcapi.errors.APIError, and include more information about the failed interaction. For full details of error responses, please refer to the relevant API documentation.

Error

HTTP Status code

InvalidRequestError

400

AuthenticationError

401

TwoFactorRequiredError

402

InvalidScopeError

403

NotFoundError

404

ValidationError

422

RateLimitExceededError

429

InternalServerError

500

ServiceUnavailableError

503

GatewayTimeoutError

504

Usage

I’ve done my best to make the code clean, commented, and understandable; however it may not be exhaustive. For more details, please refer to the official documentation or the API Explorer.

IN SHORT

  • Use args for URI paths

  • Use kwargs for form data or query parameters

Thats it!

Public API (Market Data)

Get available currencies, tokens, ICO etc.

client.get_currencies()
client.get_currency('BTC')

Get currency symbols (currency pairs) traded on HitBTC exchange.

client.get_symbols()
client.get_symbol('ETHBTC')

Get ticker information

client.get_tickers()
client.get_ticker('ETHBTC')

Get trades for a specific symbol

client.get_trades('ETHBTC')
client.get_trades('ETHBTC',sort='ASC',limit=10)

# Caution: from is a python keyword,
# so cannot be used as a keyword argument to a function,
# need to use dict instead
import datetime
today = datetime.datetime.now()
yesterday = today - datetime.timedelta(days=1)
params = {
    'from': today.isoformat(),
    'to': yesterday.isoformat()
}
client.get_trades('ETHBTC',sort='ASC',limit=10,**params)

Get orderbook (electronic list of buy and sell orders) for a specific symbol, organized by price level

client.get_orderbook('ETHBTC')
client.get_orderbook('ETHBTC',limit=10)

Get candles for a specific symbol (used for OHLC)

client.get_candles('ETHBTC')
client.get_candles('ETHBTC', limit=10, period='H1')

Trading

Get trading balance for your account

client.get_trading_balance()

Get a list of active orders or a specific active order

client.get_active_orders()
client.get_active_orders(symbol='ETHBTC')

client.get_active_order('840450210')
client.get_active_order('840450210', wait=30000)

Create a new order

client.create_order(symbol='ETHBTC',side='buy',quantity='0.063',price='0.046016') # required parameters
client.create_order(symbol='ETHBTC',side='buy',quantity='0.063',price='0.046016', type='stopLimit', stopPrice='0.073')

Update an existing order

client.update_order('840450210',symbol='ETHBTC',side='buy',quantity='0.063',price='0.046016',timeInForce='GDC')

Cancel all open orders or a specific open order

client.cancel_open_orders()
client.cancel_open_orders(symbol='ETHBTC')

client.cancel_order('840450210')

Get personal trading commission rate

client.get_trading_fee('ETHBTC')

Trading History

Get order history

client.get_order_history()
client.get_order_history(symbol='ETHBTC',limit=10)

# Caution: from is a python keyword,
# so cannot be used as a keyword argument to a function,
# need to use dict instead
import datetime
today = datetime.datetime.now()
yesterday = today - datetime.timedelta(days=1)
params = {
    'from': today.isoformat(),
    'to': yesterday.isoformat()
}
client.get_order_history(symbol='ETHBTC',limit=10,**params)

Get trade history

client.get_trade_history()
client.get_trade_history(symbol='ETHBTC',limit=10)

# Caution: from is a python keyword,
# so cannot be used as a keyword argument to a function,
# need to use dict instead
import datetime
today = datetime.datetime.now()
yesterday = today - datetime.timedelta(days=1)
params = {
    'from': today.isoformat(),
    'to': yesterday.isoformat()
}
client.get_trade_history(symbol='ETHBTC',limit=10,**params)

Get trades by order

client.get_trades_by_orderid('840450210')

Account Information

Get account balance

client.get_account_balance()

Get deposit address for the cryptocurrency

client.get_deposit_address('BTC')

Add deposit address for the cryptocurrency

client.add_deposit_address('BTC')

Withdraw cryptocurrency

client.withdraw('BTC', amount='0.01', address='sOmE-cuRR-encY-addR-essH') # required parameters
client.withdraw('BTC', amount='0.01', address='sOmE-cuRR-encY-addR-essH', networkFee='0.0003', includeFee=True, autoCommit=False)

Commit cryptocurrency withdrawal

client.commit_withdrawal('d2ce578f-647d-4fa0-b1aa-4a27e5ee597b')

Rollback cryptocurrency withdrawal

client.rollback_withdrawal('d2ce578f-647d-4fa0-b1aa-4a27e5ee597b')

Transfer money between trading and account

client.transfer_to_trading(currency='BTC',amount='0.023',type='bankToExchange')

Get all transactions or by id

client.get_account_transactions()
client.get_account_transactions(currency='BTC',sort='ASC',limit=10)

# Caution: from is a python keyword,
# so cannot be used as a keyword argument to a function,
# need to use dict instead
import datetime
today = datetime.datetime.now()
yesterday = today - datetime.timedelta(days=1)
params = {
    'from': today.isoformat(),
    'to': yesterday.isoformat()
}
client.get_trade_history(currency='BTC',sort='ASC',limit=10,**params)

client.get_account_transaction('d2ce578f-647d-4fa0-b1aa-4a27e5ee597b')

Running tests

$ python -m unittest2 tests/test_client.py
$ python -m unittest2 tests/test_utils.py

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgements

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

hitbtcapi-1.0.1.tar.gz (8.2 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page