Kana Perps Python Websocket API
Supported Markets
Asset
Market ID
Description
APT/USDC
501
Aptos-based trading market.
BTC/USDC
502
Bitcoin-based trading market.
ETH/USDC
503
Ethereum-based trading market.
WebSocket Client Documentation
Installation:
Install Dependencies: You will need the
websocket-clientlibrary. Install it using pip:
pip install websocket-client1. WebSocket Client for Subscribing to Position Updates
WebSocket URL:
wss://perpetuals-indexer-ws.kanalabs.io/ws
Example Request:
When you connect to the WebSocket server, the client will send a subscription message like this:
{
"topic": "positions",
"address": "0x4d6dc68e391e86991e58ab4d548b7e92872430d1f51bc666fe0c206bad7ff770"
}topic: The topic to subscribe to, which is
positionsin this case.address: The address to track for position updates.
Example Response:
After subscribing, you will receive position updates as a response from the server. The response might look like this:
Example Code to Connect to the WebSocket and Subscribe:
Here’s a Python script that demonstrates how to connect to the WebSocket server and subscribe to position updates for a specific address.
2. WebSocket Client for Subscribing to Order Fills Updates
WebSocket URL:
wss://perpetuals-indexer-ws.kanalabs.io/ws
Example Request:
When you connect to the WebSocket server, the client will send a subscription message like this:
topic: The topic to subscribe to, which is trade_history in this case.
address: The address to track for order fills updates.
Example Response:
After subscribing, you will receive order fills updates as a response from the server. The response might look like this:
Example Code to Connect to the WebSocket and Subscribe:
Here’s a Python script that demonstrates how to connect to the WebSocket server and subscribe to order fills updates for a specific address.
3. WebSocket Client for Subscribing to Open Orders Updates
WebSocket URL:
wss://perpetuals-indexer-ws.kanalabs.io/ws
Example Request:
When you connect to the WebSocket server, the client will send a subscription message like this:
topic: The topic to subscribe to, which is open_orders in this case.
address: The address to track for open orders updates.
Example Response:
After subscribing, you will receive open orders updates as a response from the server. The response might look like this:
Example Code to Connect to the WebSocket and Subscribe:
Here’s a Python script that demonstrates how to connect to the WebSocket server and subscribe to open orders updates for a specific address.
4. WebSocket Client for Subscribing to Order history Updates
WebSocket URL:
wss://perpetuals-indexer-ws.kanalabs.io/ws
Example Request:
When you connect to the WebSocket server, the client will send a subscription message like this:
topic: The topic to subscribe to, which is order_history in this case.
address: The address to track for order history updates.
Example Response:
After subscribing, you will receive order history updates as a response from the server. The response might look like this:
Example Code to Connect to the WebSocket and Subscribe:
Here’s a Python script that demonstrates how to connect to the WebSocket server and subscribe to order history updates for a specific address.
5. WebSocket Client for Subscribing to Order Book Updates
WebSocket URL:
wss://perpetuals-indexer-ws.kanalabs.io/ws
Example Request:
When you connect to the WebSocket server, the client will send a subscription message like this:
topic: The topic to subscribe to, which is orderbook in this case.
address: The address to track for order book updates.
Example Response:
After subscribing, you will receive order book updates as a response from the server. The response might look like this:
Example Code to Connect to the WebSocket and Subscribe:
Here’s a Python script that demonstrates how to connect to the WebSocket server and subscribe to order book updates for a specific address.
Last updated