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

Cannot connect/subscribe to SpotUserDataStream on Testnet #414

Open ozum opened 7 months ago

ozum commented 7 months ago

Hi,

When I try to connect/subscribe to SpotUserDataStream, I get an error message stating Invalid API key, IP, or permissions for action. (code: 2015).

const wsClient = new WebsocketClient({
  beautify: true,
  wsUrl: "wss://testnet.binance.vision",
  api_key: API_KEY,
  api_secret: API_SECRET,
});

await wsClient.subscribeSpotUserDataStream();

Workaround

I tracked the error,

In the websocket-client.js file the subscribeSpotUserDataStream() method calls the getSpotRestClient() method, which tries to connect to real network instead of testnet.

When I added the baseUrl option for the spot client to use testnet, the problem was solved. However:

  1. baseUrl is not a defined option in the WSClientConfigurableOptions
  2. This is undocumented.
const wsClient = new WebsocketClient({
  beautify: true,
  baseUrl: "https://testnet.binance.vision",
  wsUrl: "wss://testnet.binance.vision",
  api_key: API_KEY,
  api_secret: API_SECRET,
});

await wsClient.subscribeSpotUserDataStream();
ozum commented 4 months ago

@tiagosiebler, in #422, we pushed an undo commit for the baseUrl attribute in the Web Socket client.

Did you reimplement baseUrl, or is this issue closed automatically by accident?

tiagosiebler commented 4 months ago

Not yet, closed automatically by accident so I've reopened it, thanks