bitmex-client-websocket icon indicating copy to clipboard operation
bitmex-client-websocket copied to clipboard

Feature/multiplexing support

Open BSanchidrian opened this issue 6 years ago • 9 comments

Hello everyone,

I'm working on a project where I needed multiplexing support from bitmex, so I wrote a quick adapter in order to support such feature on this library. Note that it's a quick implementation due my own project deadlines.

  • Moved HandleObjectMessage and HandleRawMessage to a global static class in order to reuse those handlers.
  • Added classes like BitmexWebsocketChannel which represents a multiplexing channel, MultiplexingMessageBase for the message structure or BitmexMultiplexClient used to send/receive data.

Next steps:

  • I couldn't finish the Sample project showing how the multiplexing works, only recent trades are currently working. I'll try to fix it in the upcoming days.
  • Add the required functionality to control how many users can be connected to the same multiplexing websocket and handle disconnections/errors (I've emailed bitmex and they said the limit is 1000 users) (They also recommended staying below 100 per socket/ip address if possible).
  • The class naming (BitmexMultiplexClient) might not be ideal, check class names.
  • Would be great to find a common abstraction between BitmexWebsocketClient and BitmexMultiplexClient since both represent a BitmexWebsocket but with different capabilities common interface).

BSanchidrian avatar Sep 06 '19 19:09 BSanchidrian

Hello,

thanks, seems reasonable. Is it going to be backward compatible or brings any breaking change to usage? Ping me when you will be ready, I will go through it.

I would suggest to name it like BitmexWebsocketMultiplexClient, quite long, but more expressive.

Marfusios avatar Sep 10 '19 14:09 Marfusios

Hello Marfusios,

I'm currently in holidays so I'll try to finish the tests as soon as I'm back home.

There shouldn't be any breaking change since the multiplex client is completely separated from the normal one.

Btw I like your name suggestion, I'll change it soon :)

Regards

BSanchidrian avatar Sep 12 '19 10:09 BSanchidrian

Hi Marfusios Is this feature going to be added to the master branch? Thanks in advance Regards

Paulito123 avatar Dec 24 '19 09:12 Paulito123

Hi all! As I understood, this pr implementation wouldn't work, cause we can not subscribe to observable through another parent observable as tried in example:

   client.Channels.Subscribe(channel =>
                        channel.Streams.InfoStream.Subscribe(info =>
                    {
                        Log.Information($"Channel = {channel.ChannelName} | Reconnection happened, Message: {info.Info}, Version: {info.Version:D}");
                    }));

@Marfusios, what you think about adding an optional field with info about channel and adding it to base response on handling?

ridicoulous avatar Jan 28 '20 00:01 ridicoulous

Hi @ridicoulous,

Doesn't it work? I believe that it worked when I wrote the sample project.

Not gonna lie, had to implement this feature quick for a test project I was working on and didn't put much love into it, I might need to review all the changes again.

Thanks for the feedback!

BSanchidrian avatar Jan 28 '20 09:01 BSanchidrian

Hi @BSanchidrian. It general it works fine, if we talk anout sending and receiving messages in communicator. It does not work for me if I try create a subscribtion through client.Channels observable to each channel's stream as mentioned in example:

    client.Channels.Subscribe(channel =>
                channel.Streams.SubscribeStream.Subscribe(x =>
            {
                Log.Information(x.IsSubscription
                    ? $"[{channel.ChannelName}]: Subscribed ({x.Success}) to {x.Subscribe}"
                    : $"[{channel.ChannelName}]:Unsubscribed ({x.Success}) from {x.Unsubscribe}");
            }));

            client.Channels.Subscribe(channel =>
                channel.Streams.PongStream.Subscribe(x =>
                    Log.Information($"[{channel.ChannelName}] Pong received ({x.Message})"))); 

I mean that I can see messages in verbose logs of communicator, but didn't see messages from subscribtion in example

ridicoulous avatar Jan 28 '20 10:01 ridicoulous

That's interesting, I'll definitely take a look whenever I have some free time.

Thanks @ridicoulous!

BSanchidrian avatar Jan 28 '20 10:01 BSanchidrian

Unfortunately, I have a lack of time, let me check the current code later this week.

Marfusios avatar Jan 28 '20 10:01 Marfusios

Hello @BSanchidrian , First of all thank you for your effort. A lot of time has passed. What stage is your work? Can we use this feature right now? I would be glad if you give information. :))

emin-karadag avatar May 16 '20 07:05 emin-karadag