aloysius-pgast / bittrex-signalr-client

Node.js implementation of SignalR protocol tailored for Bittrex exchange
39 stars 14 forks source link

Order Subscription ends silently at random points #6

Closed dakovi closed 6 years ago

dakovi commented 6 years ago

Hello,

first of all I am really enjoying your script and the new beta API. Thank you for your work.

Recently I stumbled upon a problem with my subscription to orders (client.subscribeToOrders). They seem to get disconnected on random points when there is no activity for a while (a few hours). Short description of my setup:

The watchdog you implemented for a similar problem can't help out since it is possible that there is no other active subscription to a market and therefore the dog can't catch a drop. Do you see any possibility to get a similar functionality for an order subscription?

My ideas like an interval of renewing the subscription or always resubscribe when a signal occurs aren't very elegant and could fail easily.

Reagrds

aloysius-pgast commented 6 years ago

Hi Thanks for your feedback.

I'll try to check if it's possible to implement a watchdog but my first guess is it won't be possible because traffic related to orders is not expected so frequently as for tickers or order books. I'll run some tests anyway to see how I can improve stability.

Did you notice by if it always start failing after the same amount of time ?

dakovi commented 6 years ago

Yeah a watch dog based on incoming traffic (orders) wouldn't help that much since an absence of order data doesn't necessarily mean a broken stream. It would result in a simple "guess it is down?" statement...like the interval idea I mentioned above.

Unfortunately I can't give you any specific details about time amounts since I am only able to see a termination by not catching a fulfilled buy order...which happens randomly and can take days to occur due to higher market activities where I am restarting the stream anyway.

My best guess is a connection loss after a few hours of no incoming market data (in my case I am just using streams when a position is opened and don't check the market if I don't hold that coin) and trade activity.

If you have an idea about a temp fix on my side I am of course all ears. Right now I am thinking about a 30 minute restart interval....

Maybe I could also open an unsued dummy market stream as a point of activity and let the existing watch dog do the rest but that isn't elegant at all and results in constant bandwith traffic and resource usage...

aloysius-pgast commented 6 years ago

I pushed some code to develop branch. I added parameter resubscribe to client method subscribeToOrders. This way you'll be able to force the resubscription to exchange without having to re-open the whole SignalR connection.

client.subscribeToOrders(true);

Let me know if it gets better. I'll keep investigating to find a better solution in the meantime

dakovi commented 6 years ago

Great, I'll take a look at the weekend?

By the way: The beta is officially over - see: https://github.com/Bittrex/beta/commit/c4c4a5d0d6f1bdd1045b97f67e595d41af4c62ab

They changed the documentation accordingly: bittrex.github.io

I guess you can now skip the legacy stuff since this endpoint is using the new techniques anyway?

dakovi commented 6 years ago

Just for clarification: Should I see any kind of message in DEBUG mode when using

client.subscribeToOrders(true);

while having an already established subscription to orders? Right now I am not sure if my forced resubscribing interval is really doing anything.

aloysius-pgast commented 6 years ago

Hi. When running with DEBUG=BittrexSignalRClient* node, you should see following line everytime you re-subscribe to orders

BittrexSignalRClient:Client Method 'subscribeToOrders' will trigger following changes : {"subscribe":[{"entity":"orders"}]}

Also, if you enable logging of WS frame, you should have debug lines containing all WS content received on socket :

client.logAllWsMessages(true);

You should see

BittrexSignalRClient:Client Method 'subscribeToOrders' will trigger following changes : {"subscribe":[{"entity":"orders"}]} +29s                                                                                                           
  BittrexSignalRClient:Client Watchdog for 'tickers' will be disabled since we don't have any remaining subscription +0ms                                                                                                                    
  BittrexSignalRClient:Client Watchdog for 'markets' will be disabled since we don't have any remaining subscription +0ms                                                                                                                    
  BittrexSignalRClient:Connection {"R":"e630071b229c49feb3502971be8cd5fc7ec39fea95c44d86983a641b6afb5df3","I":"2"} +2s                                                                                                                       
  BittrexSignalRClient:Connection {"C":"d-8AA6106D-B,0|Dll,0|Dlm,3|Dlk,0","M":[]} +189ms                                                                                                                                                     
  BittrexSignalRClient:Connection {"R":true,"I":"3"} +30ms 
aloysius-pgast commented 6 years ago

Did you experienced the data timeout while resubscribing periodically ?

aloysius-pgast commented 6 years ago

Maybe it would be easier to make the lib automatically resubscribing to order at a given interval (defined in constructor opts). Re-subscribing manually would still be possible of course.

aloysius-pgast commented 6 years ago

I added an option to constructor to automatically handle re-subscription periodically :

let client = new SignalRClient({
    watchdog:{
        // automatically re-subscribe for orders every 30min (this is enabled by default)
        orders:{
            enabled:true,
            period:1800
        }
    }
});

Option is enabled by default with a period of 30min. Everytime an automatic re-subscription occurs, a watchdog event such as below will be emitted


{ 
    connectionId: '45311561-2009-47ee-b8b8-0139b6a0392e',
    dataType: 'orders',
    lastTimestamp: 1525694192160 
}
aloysius-pgast commented 6 years ago

Hi. Do you have feedback regarding the last changes ?

dakovi commented 6 years ago

Hi,

first of all I am very sorry for my late reply. I really appreciate the time you're investing in this little project. Unfortunately I am no longer an active trader on Bittrex which has nothing to do with your work. Therefore I am no longer using my script and your work and can't really comment on the recent changes.

Anyway I wish you good luck with your further projects!

aloysius-pgast commented 6 years ago

Thanks !