import type { MarketDataStreaming } from "@/api/types";
import { client } from "@/api";

export class TradeWebSocket {
  public socket: MarketDataStreaming | null = null;
  constructor() {
    if (!this.socket) {
      this.socket = client.api.market_data.streaming.subscribe();
    }
  }

  public getSocket(): MarketDataStreaming {
    return this.socket!;
  }

  public closeSocket() {
    if (this.socket) {
      this.socket.close();
      this.socket = null;
    }
  }
}

export const tradeWebSocket = new TradeWebSocket();
