api_key
and api_secret
with your own CDP API Key and Secret.
You must specify an on_message
function that is called when a message is received from the WebSocket API. This function takes in a single argument, which is the raw message received from the WebSocket API.
In the following example, we simply print the message to the console.
open
to your code, using the same client you just created.
heartbeats
and ticker
channels for the BTC-USD
product. The received message is printed to the console.
sleep_with_exception_check
method to run the client for a specified number of seconds. This method checks for exceptions every second, and exits if an exception is raised.
Run the following code to keep the client open for 10 seconds. It prints all of the messages it receives, then closes the connection:
run_forever_with_exception_check
method. This method runs the client forever, and exits if an exception is raised.
on_message
function. This function:
user
channel’order_filled
variable to True
if the order is filled.user
and heartbeats
channels and run the client in a while
loop to wait for the order to be filled before closing the connection.
client_order_id
. For learning purposes, we’ve pre-filled it to an arbitrary string.