User Data Streams

List of available user data streams

User Order Update

Stream Name: order

Update Speed: real-time

Description: The order stream provides real-time updates for changes to a user's order. Each update includes information about the order, such as the order ID, the symbol, the order side (buy or sell), the order type (limit, market, etc.), the order status (open, filled, cancelled, etc.), and the price and quantity of the order.

Type:

type UpdateOrder = {
    id: string;
    userId: string;
    status: OrderStatus;
    side: OrderSide;
    type: OrderType;
    pair: string;
    price: string;
    quantity: string;
    cost: string;
    executedQuantity: string;
    cumulativeQuoteQty: string;
    stopPrice: string | null;
    closedAt: Date | null;
}; 

enum OrderStatus {
  Pending = 'Pending',
  Open = 'Open',
  Closed = 'Closed',
  Rejected = 'Rejected',
  Canceled = 'Canceled',
  Expired = 'Expired',
  WaitStop = 'WaitStop'
}

enum OrderSide {
  Ask = 'Ask',
  Bid = 'Bid'
}

enum OrderType {
  Limit = 'Limit',
  Market = 'Market',
  StopLoss = 'StopLoss',
  TakeProfit = 'TakeProfit',
  StopLossLimit = 'StopLossLimit',
  TakeProfitLimit = 'TakeProfitLimit',
  LimitMaker = 'LimitMaker'
}

Payload:

{
    "id": "158cf5f9-b818-458a-a5ae-61d04b50fef4",
    "userId": "94e61fd8-0ec5-4c85-a321-5eae86ea66c1",
    "status": "Closed",
    "pair": "ETH_UAH",
    "type": "Limit",
    "side": "Ask",
    "quantity": "0.03",
    "price": "100",
    "cost": "3",
    "stopPrice": null,
    "executedQuantity": "0.03",
    "cumulativeQuoteQty": "0",
    "closedAt": "2022-07-26T12:48:28.639Z"
}

New User Trade Stream

Stream Name: trade

Update Speed: real-time

Description: The trade stream provides real-time updates for new trades executed by a user. Each update includes information about the trade, such as the trade ID, the pair, the trade side (buy or sell), the price and quantity of the trade, the timestamp of the trade, etc..

Type:

type UserTrade = {
    id: string;
    userId: string;
    orderId: string;
    pair: string;
    matchPrice: string;
    matchQuantity: string;
    quoteQuantity: string;
    createdAt: Date;
    isTaker: boolean;
    isBuyer: boolean;
    fee: string;
    feeCurrency: string;
};

Payload:

{
    "id": "b3bce900-c2c8-4154-8829-3de1e340437b",
    "userId": "94e61fd8-0ec5-4c85-a321-5eae86ea66c1",
    "orderId": "e42a8d62-be99-431a-a427-2477fc3a6047",
    "pair": "ETH_UAH",
    "matchPrice": "100",
    "matchQuantity": "0.03",
    "quoteQuantity": "3",
    "createdAt": "2022-07-26T12:48:28.638Z",
    "isBuyer": false,
    "isTaker": false,
    "fee": "0.0075",
    "feeCurrency": "UAH"
}

Transfer

Stream Name: transfer

Update Speed: real-time

Description: The transfer stream provides real-time updates for transfers of funds between different accounts within the exchange. Each update includes information about the transfer, such as the transfer ID, the asset being transferred, the amount transferred, the merchantId ID, the fee, the timestamp of the transfer, etc..

Type:

type PublicTransfer = {
    id: string;
    userId: string;
    status: TransferStatus;
    type: TransferType;
    amount: string;
    fee?: string;
    paymentCode: string;
    asset: string;
    payload: JSON;
    address?: string;
    createdAt: Date;
    merchantId: string;
};

enum TransferStatus {
  Created = 'Created',
  Canceled = 'Canceled',
  PartiallyProcessed = 'PartiallyProcessed',
  Processing = 'Processing',
  Processed = 'Processed',
  WaitForConfirmation = 'WaitForConfirmation'
}

enum TransferType {
  Deposit = 'Deposit',
  Withdraw = 'Withdraw'
}

Payload:

{
    "id": "81850d2e-0112-4a2b-953d-ab11acf75b04",
    "userId": "93adcb31-a266-4c6e-98e8-5fc574cd230d",
    "status": "Processed",
    "type": "Deposit",
    "amount": "100",
    "fee": "0",
    "paymentCode": "TEST",
    "asset": "ETH",
    "payload": {},
    "address": null,
    "createdAt": "2022-07-04T13:05:18.783Z",
    "merchantId": "16214228-5c0c-5abc-be6a-c90259b21d4e"
}

Account/Balance Update

Stream Name: accounts

Update Speed: real-time

Description: The accounts stream provides real-time updates for changes to a user's account balances. Each update includes information about the account balance, such as the asset and the available and blocked balance on it.

Type:

type UserAccountsEvent = {
    userId: string;
    assets: WsUserAsset[];
};

type WsUserAsset = {
    code: string;
    balance?: string;
    lockBalance?: string;
}

Payload:

{
    "userId": "93adcb31-a266-4c6e-98e8-5fc574cd230d",
    "assets": [
        {
            "code": "ETH",
            "balance": "99.9999975",
            "lockBalance": "0"
        },
      ...
    ]
}

Example: How to subscribe to my user orders
This example can be used with all types of streams to receive your user data.

import socketClusterClient from 'socketcluster-client';

const WS_URL = 'ws-pro.kuna.io';
const WS_PORT = 443;

const client = socketClusterClient.create({
    hostname: WS_URL,
    port: WS_PORT,
    secure: true,
});

void (async () => {
  	// authorization by apiKey
  	const apiKey = ""; // your apiKey 
  	await Promise.all([
    	client.invoke('login', apiKey),
    	client.listener('authenticate').once(),
    ]);

  	// subscribe to 'order' channel (stream)
    const orderChanel = client.subscribe('order');
  
    // consume user order events
    for await (const data of orderChanel) {
        console.log('Order:', data);
    }
    
  	// attach listener to channel events
    await orderChanel.listener('subscribe').once();
})();