HitBTC Websocket API Client Code Reference

HitBTC WSS API V2.0 Client.

The Client Object

class hitbtc.client.HitBTC(key=None, secret=None, raw=None, stdout_only=False, silent=False, url=None, **conn_ops)[source]

HitBTC Websocket API Client class.

Programmed using the official API documentation as a reference.

Documentation can be found here:
https://api.hitbtc.com/?python#socket-api-reference
cancel_order(custom_id=None, **params)[source]

Cancel an order via Websocket.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#cancel-order
credentials_given

Assert if credentials are complete.

login(key=None, secret=None, basic=None, custom_nonce=None)[source]

Login using the WSS API.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#socket-session-authentication
place_order(custom_id=None, **params)[source]

Place a new order via Websocket.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#place-new-order
recv(block=True, timeout=None)[source]

Retrieve data from the connector queue.

replace_order(custom_id=None, **params)[source]

Replace an existing order via Websocket.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#cancel-replace-orders
request_active_orders(custom_id=None, **params)[source]

Request your account’s active orders.

This requires you to be logged-in! Call login() first!

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#get-active-orders-2
request_balance(custom_id=None, **params)[source]

Request your account’s balance.

This requires you to be logged-in! Call login() first.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#get-trading-balance
request_currencies(custom_id=None, **params)[source]

Request currencies currently listed at HitBTC.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#get-currencies
request_symbols(custom_id=None, **params)[source]

Request symbols currently traded at HitBTC.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#get-symbols
request_trades(custom_id=None, **params)[source]

Request trades executed at HitBTC.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#get-trades
start()[source]

Start the websocket connection.

stop()[source]

Stop the websocket connection.

subscribe_book(cancel=False, custom_id=None, **params)[source]

Request a stream for order book data.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#subscribe-to-orderbook
subscribe_candles(cancel=False, custom_id=None, **params)[source]

Request a stream for candle data.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#subscribe-to-candles
subscribe_reports(cancel=False, custom_id=None, **params)[source]

Request a stream of your account’s order activities.

This requires you to be logged-in! Call HitBTC.login() first!

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#subscribe-to-reports
subscribe_ticker(cancel=False, custom_id=None, **params)[source]

Request a stream for ticker data.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#subscribe-to-ticker
subscribe_trades(cancel=False, custom_id=None, **params)[source]

Request a stream for trade data.

Offical Endpoint Documentation:
https://api.hitbtc.com/?python#subscribe-to-trades

The Connector Object

class hitbtc.connector.HitBTCConnector(url=None, raw=None, stdout_only=False, silent=False, **conn_ops)[source]

Class to pre-process HitBTC data, before putting it on the internal queue.

Data on the queue is available as a 3-item-tuple by default.

Response items on the queue are formatted as:
(‘Response’, ‘Success’ or ‘Failure’, (request, response))

‘Success’ indicates a successful response and ‘Failure’ a failed one. request is the original payload sent by the client and response the related response object from the server.

Stream items on the queue are formatted as:
(method, symbol, params)

You can disable extraction and handling by passing ‘raw=True’ on instantiation. Note that this will also turn off recording of sent requests, as well all logging activity.

authenticate(key, secret, basic=False, custom_nonce=None)[source]

Login to the HitBTC Websocket API using the given public and secret API keys.

echo(msg)[source]

Print message to stdout if silent isn’t True.

put(item, block=False, timeout=None)[source]

Place the given item on the internal q.

send(method, custom_id=None, **params)[source]

Send the given Payload to the API via the websocket connection.

Parameters:
  • method – JSONRPC method to call
  • custom_id – custom ID to identify response messages relating to this request
  • kwargs – payload parameters as key=value pairs

The Websocket APP Object

class hitbtc.wss.WebSocketConnector(url, timeout=None, q_maxsize=None, reconnect_interval=None, log_level=None)[source]

Websocket Connection Thread.

Inspired heavily by ekulyk’s PythonPusherClient Connection Class https://github.com/ekulyk/PythonPusherClient/blob/master/pusherclient/connection.py

Data received is available by calling WebSocketConnection.recv()

disconnect()[source]

Disconnect from the websocket connection and joins the Thread.

pass_up(data, recv_at)[source]

Pass data up to the client via the internal Queue().

Parameters:
  • data – data to be passed up
  • recv_at – float, time of reception
Returns:

reconnect()[source]

Issue a reconnection by setting the reconnect_required event.

recv(block=True, timeout=None)[source]

Wrap for self.q.get().

Parameters:
  • block – Whether or not to make the call to this method block
  • timeout – Value in seconds which determines a timeout for get()
Returns:

run()[source]

Run the main method of thread.

send(data)[source]

Send the given Payload to the API via the websocket connection.

Furthermore adds the sent payload to self.history.

Parameters:data – data to be sent
Returns:
stop()[source]

Wrap around disconnect().

class hitbtc.wss.WebSocketConnectorThread(url, timeout=None, q_maxsize=None, reconnect_interval=None, log_level=None, **kwargs)[source]

Thread-based WebsocketConnector.

disconnect()[source]

Disconnect from the websocket and join thread.