tiagosiebler / binance

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

Support for COIN-M user data stream #242

Closed skliarovartem closed 1 year ago

skliarovartem commented 1 year ago

Trying to connect to futures websockets:

const ws = new WebsocketClient({
                        api_key: wallet.apiKey,
                        api_secret: wallet.apiSecret,
                        beautify: true,
                        baseUrl: 'https://fapi.binance.com',
                        wsUrl: 'wss://fstream.binance.com',
                    });

And getting error: { wsKey: 'spot_userData', error: "Unexpected '<'" }

tiagosiebler commented 1 year ago

You shouldn't need to override the urls. The WS client handles this for you. Here's an example for USD Futures: https://github.com/tiagosiebler/awesome-crypto-examples/blob/master/src/exchanges/binance/account-events/futures-balance-update.ts#L20-L68

tiagosiebler commented 1 year ago

Another example here: https://github.com/tiagosiebler/binance/blob/master/examples/ws-userdata.ts#L116

skliarovartem commented 1 year ago

Awesome!

skliarovartem commented 1 year ago

As I understand subscribeUsdFuturesUserDataStream works for USDT-M. Is it possible also to subscribe to COIN-M? Many thanks!

tiagosiebler commented 1 year ago

Hmm unfortunately I haven't implemented COIN-M yet... https://github.com/tiagosiebler/binance/blob/master/src/websocket-client.ts#L1845-L1869

It should be relatively straight forward by adapting what subscribeUsdFuturesUserDataStream() does into what the docs say for COIN-M

skliarovartem commented 1 year ago

Ok, I have created a fork and implemented there subscribeCoinFuturesUserDataStream of course rest client is empty right now, I use direct requests...

tiagosiebler commented 1 year ago

Ok, I have created a fork and implemented there subscribeCoinFuturesUserDataStream of course rest client is empty right now, I use direct requests...

Cool, will you be making a pull request or would you prefer me to do it? Yes, the rest client for coinm is still a bit empty, it was only recently started by another user, but we can start adding methods to it for any needed endpoints.

skliarovartem commented 1 year ago

ok, I will make pr, but next week

tiagosiebler commented 1 year ago

Supported since a few releases ago