tiagosiebler / binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & browser support, integration tests, beautification & more.
https://www.npmjs.com/package/binance
MIT License
775 stars 266 forks source link

Connecting websockets to Binance.US #120

Open hodlerhacks opened 3 years ago

hodlerhacks commented 3 years ago

I see that on the REST API, the endpoint can be set to Binance.US. What about the WebSockets API, can it be used on Binance.US as well?

tiagosiebler commented 3 years ago

This should be possible using the new client implementations in #122. The websockets API exposes a method to connect to a full websocket URL, or you could look at expanding support for the US servers in the existing implementation.

Take a look at how getWsBaseUrl is hooked up in these utility methods: https://github.com/tiagosiebler/binance/blob/v2.0.0/beta/src/websocket-client.ts#L774-L781

hodlerhacks commented 3 years ago

Sorry, late response (I was on vacation). Thanks for confirming this is now possible. So the following is the recommended way of doing this, right?

wsClient = new WebsocketClient({
        api_key: apiKey,
        api_secret: apiSecret,
        beautify: true,
        wsUrl: <Binance US ws URL goes here>,
    }, logger);
kenchambers commented 1 year ago

@hodlerhacks

Yup, i am able to get it to work using binance us:


 let client = new WebsocketClient({
      wsUrl: 'wss://stream.binance.us:9443',
      api_key: process.env.BINANCE_REAL_KEY,
      api_secret: process.env.BINANCE_REAL_SECRET,
      beautify: true
    })