无法通过 binance Websockets 获取套接字数据

Unable to get the socket data through binance Websockets

这是我的客户端代码库。它与其中一个交换 websocket 一起工作,但不与这个 websocket 一起工作。有什么建议吗?

websocket 参考:https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md

import React, { Component, createContext } from "react";

export const Contx = createContext();

export class ConProvider extends Component {
  state = {
    coins: [],
    digCoin: [],
    sou: [],
    passSocket: undefined
  };

  componentDidMount() {
    this.socketCall();  
  }

  socketCall = () => {
    var ws = new WebSocket("wss://stream.binance.com:9443");
    var msg = {
      "method": "SUBSCRIBE",
      "params": "btcusdt@depth",
      "id": 1
    };

    ws.onopen = () => {
      ws.send(msg);
    };

    ws.onmessage = e => {
      const value = e.data;
      this.setState({
        coins: value
      });
    };

    this.setState({
      passSocket: ws
    });
  };

  socketClose = () => {
    var wss = this.state.passSocket;
    wss.close();
  };

  render() {
    console.log(this.state.coins);

    // console.log(this.state.coins)
    return (
      <Contx.Provider
        value={{
          ...this.state,
          socketCall: this.socketCall,
          socketClose: this.socketClose
        }}
      >
        {this.props.children}
      </Contx.Provider>
    );
  }
}

试试

var ws = new WebSocket("wss://stream.binance.com:9443/ws");
const ws = new WebSocket('wss://stream.binance.com:9443/ws');
const msg = {
  method: 'SUBSCRIBE',
  params: ['btcusdt@depth'],
  id: 1,
};

ws.onopen = () => {
  ws.send(JSON.stringify(msg));
};

Send 接受 JSON 格式,我将 msg 更改为 object,将数组传递给 params 并添加 /ws 如上所述。