tiagosiebler / binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & browser support, integration tests, beautification & more.
MIT License
757 stars 266 forks source link

run example ws-public-spot-orderbook.ts failed #392

Closed guotie closed 8 months ago

guotie commented 8 months ago

errors:

ws automatically reconnecting....  spot_depth_bnbusdt_
2024-02-01T15:32:15.777Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/btcusdt@depth20",
  } ]
2024-02-01T15:32:15.828Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/ethusdt@depth20",
  } ]
2024-02-01T15:32:15.853Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/bnbusdt@depth20",
  } ]
2024-02-01T15:32:16.209Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 4,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
guotie commented 8 months ago

why?

tiagosiebler commented 8 months ago

Strange, maybe your IP is in a restricted location? E.g. binance doesn't allow any connections from IPs in the US.

I've made a small update to the example so it logs error events: https://github.com/tiagosiebler/binance/blob/master/examples/ws-public-spot-orderbook.ts#L60-L62

Can you pull (or copy paste) the latest update and try the example again, does it print more info?

guotie commented 8 months ago

maybe ip address problem.

any solution?

tiagosiebler commented 8 months ago

Did you run the latest change I pushed yesterday? It should show more logs.

guotie commented 8 months ago

seems no more logs.

subscribing to trades for:  BTCUSDT
subscribing to trades for:  ETHUSDT
subscribing to trades for:  BNBUSDT
2024-02-03T04:52:58.930Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 0,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
2024-02-03T04:52:58.932Z [ "Reconnecting to websocket with delay...", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    connectionDelayMs: 500,
  } ]
ws automatically reconnecting....  spot_depth_btcusdt_
2024-02-03T04:52:58.946Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 0,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
2024-02-03T04:52:58.947Z [ "Reconnecting to websocket with delay...", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    connectionDelayMs: 500,
  } ]
ws automatically reconnecting....  spot_depth_ethusdt_
2024-02-03T04:52:58.952Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 0,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
2024-02-03T04:52:58.952Z [ "Reconnecting to websocket with delay...", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    connectionDelayMs: 500,
  } ]
ws automatically reconnecting....  spot_depth_bnbusdt_
2024-02-03T04:52:59.434Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/btcusdt@depth20",
  } ]
2024-02-03T04:52:59.455Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/ethusdt@depth20",
  } ]
2024-02-03T04:52:59.482Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/bnbusdt@depth20",
  } ]
2024-02-03T04:52:59.885Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 4,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
2024-02-03T04:52:59.886Z [ "Reconnecting to websocket with delay...", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    connectionDelayMs: 500,
  } ]
ws automatically reconnecting....  spot_depth_ethusdt_
2024-02-03T04:52:59.887Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 4,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
2024-02-03T04:52:59.887Z [ "Reconnecting to websocket with delay...", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    connectionDelayMs: 500,
  } ]
ws automatically reconnecting....  spot_depth_btcusdt_
2024-02-03T04:52:59.935Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 4,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
2024-02-03T04:52:59.935Z [ "Reconnecting to websocket with delay...", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    connectionDelayMs: 500,
  } ]
ws automatically reconnecting....  spot_depth_bnbusdt_
2024-02-03T04:53:00.387Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/ethusdt@depth20",
  } ]
2024-02-03T04:53:00.417Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/btcusdt@depth20",
  } ]
2024-02-03T04:53:00.436Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/bnbusdt@depth20",
  } ]
2024-02-03T04:53:00.817Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 4,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
2024-02-03T04:53:00.818Z [ "Reconnecting to websocket with delay...", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    connectionDelayMs: 500,
  } ]
ws automatically reconnecting....  spot_depth_ethusdt_
2024-02-03T04:53:00.825Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 4,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
2024-02-03T04:53:00.825Z [ "Reconnecting to websocket with delay...", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    connectionDelayMs: 500,
  } ]
ws automatically reconnecting....  spot_depth_btcusdt_
2024-02-03T04:53:00.866Z [ "Websocket connection closed", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    eventCloseCode: undefined,
    wsConnectionState: 4,
    isUserData: false,
    listenKey: "",
    market: "spot",
  } ]
2024-02-03T04:53:00.866Z [ "Reconnecting to websocket with delay...", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    connectionDelayMs: 500,
  } ]
ws automatically reconnecting....  spot_depth_bnbusdt_
2024-02-03T04:53:01.318Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_ethusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/ethusdt@depth20",
  } ]
2024-02-03T04:53:01.326Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_btcusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/btcusdt@depth20",
  } ]
2024-02-03T04:53:01.367Z [ "Reconnecting to public websocket", {
    category: "binance-ws",
    wsKey: "spot_depth_bnbusdt_",
    wsUrl: "wss://stream.binance.com:9443/ws/bnbusdt@depth20",
  } ]
tiagosiebler commented 8 months ago

Strange, seems like a network issue for you but it's weird there's no error. Do these URLs work on the same machine?

You can test them with CURL or just in the browser, if you're doing this testing locally - just make sure it's the same machine / network connection.

guotie commented 8 months ago

"msg": "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please contact customer service if you believe you received this message in error."

tiagosiebler commented 8 months ago

"msg": "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please contact customer service if you believe you received this message in error."

Yup, this is your network. You're making requests from a country that binance has banned. This is very common for example if you're accidentally using a server in the US. Binance will block any requests from any IP in those countries, with that error.

If you think this is a mistake, you should contact binance with your IP or country.

guotie commented 8 months ago

thank you very much