binance icon indicating copy to clipboard operation
binance copied to clipboard

Connecting websockets to Binance.US

Open hodlerhacks opened this issue 3 years ago • 3 comments

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?

hodlerhacks avatar Jul 10 '21 07:07 hodlerhacks

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

tiagosiebler avatar Aug 08 '21 00:08 tiagosiebler

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);

hodlerhacks avatar Aug 27 '21 08:08 hodlerhacks

@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
    })

kenchambers avatar Mar 23 '23 22:03 kenchambers