Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequent disconnects #121

Open
vburwitz3 opened this issue Oct 27, 2018 · 5 comments
Open

Frequent disconnects #121

vburwitz3 opened this issue Oct 27, 2018 · 5 comments

Comments

@vburwitz3
Copy link

vburwitz3 commented Oct 27, 2018

Issue Overview

Sadly there is a problem that connections get constantly lost if you run a program 24h. I do not see how to get that solved.
If there are no price updates for some time I can rerequest.
But UserDataWebSocketMessages connection handlers die and I cant check them (at least I do not see how) (and price updates may still be coming and are not broken!).
Sadly everything is wrapped up in a DLL so I can not go into the problem. Telegram API discussion group or Binance ticket was of no use.
The real problem is there is no working function to check if connection is ok. At the beginning each order creation/deletion on binance comes over the connection, at a certain point it stops until a connection is newly recreated (new UserDataWebSocketMessages()).
The problem is there is also no exception or so that would be thrown to get the information that connection is broken.

Package Version: ?.?.?

BinanceDotNet 4.6.2

Repro Steps

To check the issue simply do a connection with new UserDataWebSocketMessage(OrderUpdateMessageHandler, TradeUpdateMessageHandler, AccountUpdateMessageHandler) and try after some hours to get a order update, by example cancelling an existing order over the Binance website "Open Orders" page.
Mostly after some hours the connection will have died and there will be no Update/Cancellation/Whatever message received by the client anymore.

Other Information

It is a very severe API issue! Since it basically prevents implementing a stable automated trading application!

@vburwitz3
Copy link
Author

vburwitz3 commented Nov 14, 2018

My request code it the following

private async void startBinanceConnection (bool requestUnderlyings) {
	// Binance init
	binanceClient	=new BinanceClient(new ClientConfiguration() {
		ApiKey		=binanceApiKey,
		SecretKey	=binanceSecretKey,
		Logger		=logger,
		DefaultReceiveWindow	=50000,
	});

	// init callbacks and start
	UserDataWebSocketMessages userDataWebSocketMessages	=new UserDataWebSocketMessages {
		OrderUpdateMessageHandler	=new BinanceWebSocketMessageHandler<BinanceTradeOrderData>(x => {
			// OrderStatusUpdate() als EventHandler callen um Orderänderungen zu verarbeiten
			MethodInvoker orderStatusUpdateCall	=delegate {
				OrderStatusUpdate(x);
			};
			Form1.gui.Invoke(orderStatusUpdateCall);
		}),
		TradeUpdateMessageHandler	=new BinanceWebSocketMessageHandler<BinanceTradeOrderData>(x => {
			// OrderStatusUpdate() als EventHandler callen um Trade Executions zu verarbeiten
			MethodInvoker orderStatusUpdateCall	=delegate {
				OrderStatusUpdate(x);
			};
			Form1.gui.Invoke(orderStatusUpdateCall);
		}),
		AccountUpdateMessageHandler	=new BinanceWebSocketMessageHandler<BinanceAccountUpdateData>(x => {
			Console.WriteLine("AccountUpdateMessageHandler: eventType " +x.EventType+" balances "+x.Balances.ToString());
		})
	};

	logger.Info("binanceWebSocketClient Callbacks starting...");
	binanceWebSocketClient		=new DisposableBinanceWebSocketClient(binanceClient, logger);
	try {
		binanceWebSocketClientGuid	=await binanceWebSocketClient.ConnectToUserDataWebSocket(userDataWebSocketMessages);
	}
	catch (Exception ex) {
		printMsgStatic("startBinanceConnection: ConnectToUserDataWebSocket failed (Exception: "+ex.Message+").");
	}
	logger.Info("binanceWebSocketClient Callbacks done.");

	if (requestUnderlyings) {
		printMsgStatic("Underlyings Requests start.");
		// alle Underlyings neu requesten
		for (int undID=0; undID<indexEntries.GetLength(0); undID++) {
			Underlying und		=(Underlying)symbols[undID];
			// Realtime Tickdaten für das Index Spot Underlying requesten
			printMsgStatic("Start Binance realtime Request: "+und.underlying);
			// Manual WebSocket usage
			var socketId	=binanceWebSocketClient.ConnectToTradesWebSocket(indexEntries[undID,indexSpot], b => {
				Form1.updateLastBinance(b);
			});
		} // for (underlying)
		printMsgStatic("Underlyings Requests done.");
	}
} // startBinanceConnection()

@xfiodembo
Copy link
Contributor

Fortunately its not an issue, all websocket connections die at the 24h mark. at least per binance api docs "A single connection to stream.binance.com is only valid for 24 hours; expect to be disconnected at the 24 hour mark"

@vburwitz3
Copy link
Author

It is a issue. i found out that the connections die after about 3 minutes. And the documentation says that you need to send a Pong after eacjh Ping that was send (or simply frequently).
The problem is that the "Listen Key" is not available over the API!
When the connection is established just a Guid is returned and the Listen Key that would be available in the connection function is simply forgotten (just in a local object that is not stored or returned) and is for the API user unavailable.

@glitch100
Copy link
Owner

@vburwitz3 Can you provide a link to documentation around the Listen Key?

@vburwitz3
Copy link
Author

vburwitz3 commented Jan 21, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants