internal Task <CallResult <UpdateSubscription> > SubscribeInternal <T>(string url, IEnumerable <string> topics, Action <DataEvent <T> > onData) { var request = new BinanceSocketRequest { Method = "SUBSCRIBE", Params = topics.ToArray(), Id = NextId() }; return(SubscribeAsync(url, request, null, false, onData)); }
/// <inheritdoc /> protected override async Task <bool> UnsubscribeAsync(SocketConnection connection, SocketSubscription subscription) { var topics = ((BinanceSocketRequest)subscription.Request !).Params; var unsub = new BinanceSocketRequest { Method = "UNSUBSCRIBE", Params = topics, Id = NextId() }; var result = false; if (!connection.Socket.IsOpen) { return(true); } await connection.SendAndWaitAsync(unsub, ResponseTimeout, data => { if (data.Type != JTokenType.Object) { return(false); } var id = data["id"]; if (id == null) { return(false); } if ((int)id != unsub.Id) { return(false); } var result = data["result"]; if (result?.Type == JTokenType.Null) { result = true; return(true); } return(true); }).ConfigureAwait(false); return(result); }