Kana Perps Python Websocket API
Important Note:
For all the Websocket endpoints below, pass your profile address.
To track your transactions on-chain (e.g., via Aptos Explorer or Aptos Scan), you must use your profile address, as all on-chain trades are executed using this profile address.
To obtain your profile address, use the /getProfileAddress endpoint and provide your wallet address as the userAddress parameter.
How to Fetch the Profile Address:
Example endpoint: https://perps-tradeapi.kanalabs.io/getProfileAddress?userAddress=0xd01e3a233632a41463bd6d289e99e69e1b50815c7afff710e1c992659a8722f3 Example code: https://docs.kanalabs.io/perpetual-futures/kana-perps/api-docs/kana-perps-python-rest-api#id-20.-get-profile-address
Testnet Supported Markets
Asset
Market ID
Description
APT-USD
1338
Aptos-based trading market.
BTC-USD
1339
Bitcoin-based trading market.
ETH-USD
1340
Ethereum-based trading market.
SOL-USD
2387
Solana-based trading market.
Mainnet Supported Markets
Asset
Market ID
Description
APT-USD
14
Aptos-based trading market.
BTC-USD
15
Bitcoin-based trading market.
ETH-USD
16
Ethereum-based trading market.
SOL-USD
31
Solana-based trading market.
WebSocket URL:
✅ Testnet WebSocket URL
✅ Mainnet WebSocket URL
Important Note: Profile Address Required
🔹 You must pass your profile address for WebSocket endpoints.
🔹 To get your profile address, use the /getProfileAddress endpoint.
Profile Address API:
Endpoint:
Example Request:
Input Parameter:
userAddress(your wallet address)
Response Example:
WebSocket Client Documentation
Installation:
Install Dependencies: You will need the
websocket-clientlibrary. Install it using pip:
1. WebSocket Client for Subscribing to Position Updates
WebSocket URL:
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
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:
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:
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:
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:
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.
6. WebSocket Client for Subscribing to Recent Trades Updates
WebSocket URL:
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 recent_trades in this case.
address: The address to track for recent trades updates.
Example Response:
After subscribing, you will receive recent trades 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 recent trades updates for a specific address.
7. WebSocket Client for Subscribing to Live Funding Rate Updates
WebSocket URL:
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 live_funding_rate in this case.
Example Response:
After subscribing, you will receive live funding rate 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 live funding rate updates for a specific address.
Last updated