Get hands dirty
Let’s play with some API. There is no better way to understand what API is other than playing with it and seeing it in action.
Prerequisites
You need some software installed first.
CLI
Install websocat to perform WebSocket request from your terminal
Browser
- Get Postman account to use Postman Workspaces
- Install Postman Desktop Agent to perform WebSocket requests
Play with WebSocket API from Kraken
WebSocat
- Establish a connection with the API
websocat wss://ws.kraken.com
- Ping the API to see if it responds. Just type the below message and hit Enter:
{"event": "ping"}
- Now subscribe to the event
ticker
stream that sends messages with currency price. Just type the below message and hit Enter:{ "event": "subscribe", "pair": [ "XBT/USD", "XBT/EUR" ], "subscription": { "name": "ticker" }}
-
You should now see a constant stream of data sent by the server. You do not have to ask the API every second for an update, as the update is pushed to you.
- Now unsubscribe from info about one currency pair. Just type the below message and hit Enter:
{ "event": "unsubscribe", "pair": [ "XBT/USD" ], "subscription": { "name": "ticker" }}
- You should see a message that you unsubscribed and the rest of the stream is just about EUR
Postman
- Go to this Postman Workspace with WebSocket APIs.
- Right-click on the
Kraken API
collection located at the left side of the page (alternatively, you can click on the...
icon, which shows when you hover onKraken API
). - Select the
Create a fork
option from the list. - Go to your forked workspace and use the
Kraken API
collection to ping the server. - Use the
Kraken API
collection to send the subscribe and unsubscribe messages.