Task 2 — User Stream Tracker
The UserStreamTracker
responsibility is to fetch user account data and queues it accordingly.
UserStreamTracker
contains subsidiary classes that help maintain the real-time wallet/holdings balance and open orders of a user. Namely, the classes required are:
UserStreamTrackerDataSource
UserStreamTracker
MarketAuth
(if applicable).
NOTE: This is only required in Centralized Exchanges. |
UserStreamTrackerDataSource
The UserStreamTrackerDataSource
class is responsible for initializing a WebSocket connection to obtain user related trade and balances updates.
Integrating your own data source component would require you to extend from the UserStreamTrackerDataSource base class here.
The following details the required functions in UserStreamTrackerDataSource
:
last_recv_time
Should be updated(using python's time.time()) everytime a message is received from the websocket.
Input Parameter: None
Expected Output(s): float
listen_for_user_stream
Subscribe to user stream via web socket, and keep the connection open for incoming messages.
Input Parameter: ev_loop: asyncio.BaseEventLoop
, output: asyncio.Queue
Expected Output(s): None
UserStreamTracker
The UserStreamTracker
class is responsible for maintaining the real-time account balances and orders of the user.
This can be achieved in 2 ways(depending on the available API on the exchange):
REST API
In this scenario, we would have to periodically make API requests to the exchange to retrieve information on the user's account balances and order statuses. An example of this can be seen in Huobi's connector exchange file connector. The market file shows that Huobi uses REST API alone by periodically calling the market's
_update_balances()
and_update_order_status()
through the_status_polling_loop()
. Also, it can be seen that no user stream files exist in Huobi's connector directory.WebSocket API
When an exchange does have WebSocket API support to retrieve user account details and order statuses, it would be ideal to incorporate it into the Hummingbot client when managing account balances and updating order statuses. This is especially important since Hummingbot needs to knows the available account balances and order statuses at all times.
TIP: In most scenarios, as seen in most other Centralized Exchanges( Binance, Coinbase Pro, Bittrex), a simple WebSocket integration is used to listen on selected topics and retrieving messages to be processed in Market class. |
The following details the required functions to be implemented in UserStreamTracker
:
data_source
Initializes a user stream data source.
Input Parameter: None
Expected Output(s): UserStreamTrackerDataSource
start
Starts all listeners and tasks.
Input Parameter: None
Expected Output(s): None
user_stream
Returns the message queue containing all the messages pertaining to user account balances and order statues.
Input Parameter: None
Expected Output(s): asyncio.Queue
Debugging & Testing
As part of the QA process, for each tasks(Task 1 through 3) you are required to include the unit test cases for the code review process to begin. Refer to Option 1: Unit Test Cases to build your unit tests.