SteemWebsocket

This class allows subscribe to push notifications from the Steem node.

from pprint import pprint
from beemapi.websocket import SteemWebsocket

ws = SteemWebsocket(
    "wss://gtg.steem.house:8090",
    accounts=["test"],
    on_block=print,
)

ws.run_forever()

Defintion

class beemapi.websocket.SteemWebsocket(urls, user='', password='', *args, only_block_id=False, on_block=None, keep_alive=25, num_retries=-1, **kwargs)

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 Steem node:

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

Notices:

  • on_block:

    '0062f19df70ecf3a478a84b4607d9ad8b3e3b607'
    
_SteemWebsocket__set_subscriptions()
__events__ = ['on_block']
__getattr__(name)

Map all methods to RPC calls and pass through the arguments

__init__(urls, user='', password='', *args, only_block_id=False, on_block=None, keep_alive=25, num_retries=-1, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'beemapi.websocket'
_ping()
cancel_subscriptions()
close()

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

get_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=[])
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