Allows you to subscribe to public topics.
subscribe( topic: string | { [key:string]:any }, callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">, once?: boolean, id?: string ): unsubscribe | undefined
Subscribing to the trade topic:
trade
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(); }; }, []);
Subscribing to the executionreport topic:
executionreport
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(); }; }, []);