private void HandlePossibleSingleData <T>(DataEvent <JToken> data, Action <DataEvent <IEnumerable <T> > > onMessage) { var internalData = data.Data["data"]; if (internalData == null) { return; } if (internalData.Type == JTokenType.Array) { var firstItemTopic = internalData.First()["i"]?.ToString() ?? internalData.First()["s"]?.ToString(); var deserialized = BaseClient .DeserializeInternal <BinanceCombinedStream <IEnumerable <T> > >(data.Data); if (!deserialized) { return; } onMessage(data.As(deserialized.Data.Data, firstItemTopic)); } else { var symbol = internalData["i"]?.ToString() ?? internalData["s"]?.ToString(); var deserialized = BaseClient .DeserializeInternal <BinanceCombinedStream <T> >( data.Data); if (!deserialized) { return; } onMessage(data.As <IEnumerable <T> >(new[] { deserialized.Data.Data }, symbol)); } }
private void HandleData <T>(string name, JArray dataArray, string?symbol, DataEvent <JToken> dataEvent, Action <DataEvent <T> > handler, JsonSerializer?serializer = null) { var desResult = _baseClient.DeserializeInternal <T>(dataArray, serializer: serializer); if (!desResult) { _log.Write(LogLevel.Warning, $"Failed to _baseClient.DeserializeInternal {name} object: " + desResult.Error); return; } handler(dataEvent.As(desResult.Data, symbol)); }
private void HandleAuthUpdate <T>(DataEvent <JToken> token, Action <DataEvent <BitfinexSocketEvent <IEnumerable <T> > > > action, string category) { var evntStr = token.Data[1]?.ToString(); if (evntStr == null) { return; } var evntType = BitfinexEvents.EventMapping[evntStr]; var evnt = BitfinexEvents.Events.Single(e => e.EventType == evntType); if (evnt.Category != category) { return; } if (action == null) { _log.Write(LogLevel.Debug, $"Ignoring {evnt.EventType} event because not subscribed"); return; } IEnumerable <T> data; if (evnt.Single) { var result = _baseClient.DeserializeInternal <T>(token.Data[2] !); if (!result) { _log.Write(LogLevel.Warning, "Failed to _baseClient.DeserializeInternal data: " + result.Error); return; } data = new[] { result.Data }; } else { var result = _baseClient.DeserializeInternal <IEnumerable <T> >(token.Data[2] !); if (!result) { _log.Write(LogLevel.Warning, "Failed to _baseClient.DeserializeInternal data: " + result.Error); return; } data = result.Data; } action(token.As(new BitfinexSocketEvent <IEnumerable <T> >(evntType, data))); }