subscribe(
topic: string | { [key:string]:any },
callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">,
once?: boolean,
id?: string
): unsubscribe | undefined
trade
topic:
const ws = useWS();
useEffect(() => {
const unsubscribe = ws.subscribe(
{
id: `${symbol}@trade`,
event: "subscribe",
topic: `${symbol}@trade`,
ts: Date.now()
},
{
onMessage: (data: any) => {
//
}
}
);
() => {
// Unsubscribes when the component unloads
unsubscribe();
};
}, []);
executionreport
topic:
const ws = useWS();
useEffect(() => {
const unsubscript = ws.privateSubscribe(
{
id: "executionreport",
event: "subscribe",
topic: "executionreport",
ts: Date.now()
},
{
onMessage: (data) => {
// do something
}
}
);
() => {
// Unsubscribes when the component unloads
unsubscribe();
};
}, []);