Interface KatanaPerpsLiquidationEvent

  • subscription Websocket messages always include a type property which dictates the shape of its data property.
    • type will be the name of the subscription that the message correlates to.
    • Each KatanaPerps<name>Event interface will document its provided data shape and properties.
  • subscriptions type messages will instead have a subscriptions property when dispatched.
  • Tip: Using the enum MessageEventType will make it easier to narrow the messages.
import {
WebSocketClient,
MessageEventType,
SubscriptionNamePublic,
type KatanaPerpsMessageEvent,
type KatanaPerpsTickerEventData,
type KatanaPerpsSubscribeType,
} from '@katanaperps/katana-perps-sdk';

const client = new WebSocketClient();

function handleSubscriptions(subscriptions: KatanaPerpsSubscribeType[]) {
// all subscribed subscriptions
console.log('Active Subscriptions: ', subscriptions);
}

function handleTickersUpdate(message: KatanaPerpsTickerEventData) {
// handle the updated data
console.log('Ticker: ', message);
}

client.onMessage((message: KatanaPerpsMessageEvent) => {
switch (message.type) {
case MessageEventType.error:
console.error(
`[${message.data.code}] | Error received from WebSocketServer: ${message.data.message}`,
);
break;
case MessageEventType.subscriptions:
return handleSubscriptions(message.subscriptions);
// narrows the type to the specific KatanaPerps<name>Event type
case MessageEventType.tickers:
return handleTickersUpdate(message.data);
default:
break;
}
});

async function main() {
await client.connect();

client.subscribePublic([
{
name: SubscriptionNamePublic.tickers,
markets: ['ETH-USD'],
},
]);
}

main().catch((error) => {
console.error('Error During Startup: ', error);
});
interface KatanaPerpsLiquidationEvent {
    type: "liquidations";
    data: KatanaPerpsLiquidationEventData;
}

Hierarchy (view full)

Properties

Properties

type: "liquidations"

The type property is used to determine the shape of the data property of the update event.

  • Liquidation updates on the WebSocket include all KatanaPerpsLiquidation properties as well as the market symbol that corresponds to the liquidation.