bhiveapi.websocket module

class bhiveapi.websocket.HiveWebsocket(urls, user='', password='', only_block_id=False, on_block=None, keep_alive=25, num_retries=-1, timeout=60, *args, **kwargs)

Bases: events.events.Events

Create a websocket connection and request push notifications

Parameters
  • urls (str) – Either a single Websocket URL, or a list of URLs

  • user (str) – Username for Authentication

  • password (str) – Password for Authentication

  • keep_alive (int) – seconds between a ping to the backend (defaults to 25seconds)

After instanciating this class, you can add event slots for:

  • on_block

which will be called accordingly with the notification message received from the Hive node:

ws = HiveWebsocket(
    "wss://gtg.steem.house:8090",
)
ws.on_block += print
ws.run_forever()
cancel_subscriptions()

cancel_all_subscriptions removed from api

close()

Closes the websocket connection and waits for the ping thread to close

get_request_id()

Generates next request id

on_close(ws)

Called when websocket connection is closed

on_error(ws, error)

Called on websocket errors

on_message(ws, reply, *args)

This method is called by the websocket connection on every message that is received. If we receive a notice, we hand over post-processing and signalling of events to process_notice.

on_open(ws)

This method will be called once the websocket connection is established. It will

  • login,

  • register to the database api, and

  • subscribe to the objects defined if there is a callback/slot available for callbacks

process_block(data)

This method is called on notices that need processing. Here, we call the on_block slot.

reset_subscriptions(accounts=[])

Reset subscriptions

rpcexec(payload)

Execute a call by sending the payload.

Parameters

payload (json) – Payload data

Raises
  • ValueError – if the server does not respond in proper JSON format

  • RPCError – if the server returns an error

run_forever()

This method is used to run the websocket app continuously. It will execute callbacks as defined and try to stay connected with the provided APIs

stop()

Stop running Websocket