The general manager object inherits from the
Websocket Manager object, found here. This means that all the functions described in that document will also work here **however, those inherited functions require that the channel that the function is referring to is also passed in. **.
Websocket connections should be used only if strictly necessary for the trading strategy. They require significantly higher CPU, bandwidth & memory usage when compared to making simple REST requests on a set interval.
The general manager class is designed to allow easy subscription to any channel on any exchange. This is to provide flexibility beyond price events and orderbook events, and allow more in-depth analysis.
manager = blankly.GeneralManager('coinbase_pro', 'BTC-USD')
Because these websocket objects are designed to work across currencies and exchanges, specifying a default exchange and currency for the object to behave on can make interaction significantly simpler.
|default_exchange||Fill with a default exchange for the manager to use when no overrides are given later.||str|
|default_currency||Fill with a default asset for the manager to use when no overrides are given later.||str|
create_general_connection(callback, channel, log=None, override_symbol=None, override_exchange=None)
|callback||Function with argument that accepts a single json-type message.||callable|
|channel||The websocket channel to create this connection on. Demos are given below.||str|
|log||Optionally fill this with a path to a log file to enable logging.||str|
|override_symbol||Override the default symbol and create the websocket this currency.||str|
|override_exchange||Override the default exchange and create the websocket on this exchange.||str|
Coinbase Pro Streams
A list of the Coinbase Pro websocket streams can be found below:
To use a Coinbase stream, such as
heartbeat, simply create a general connection using that channel:
# Demo callback object def callback(message): print(message) # Create the manager: manager = blankly.GeneralManager('coinbase_pro', 'BTC-USD') # Create the connection websocket = manager.create_general_connection(callback, 'heartbeat')
This will begin printing heartbeats from Coinbase on that currency.
A list of the supported binance streams can be found below:
To use a binance stream, such as
"btcusdt@aggTrade", simply create a general connection using that channel:
# Demo callback object def callback(message): print(message) # Create the manager): manager = blankly.GeneralManager('binance', 'BTC-USDT') # Create the connection websocket = manager.create_general_connection(callback, 'aggTrade')