Esempio n. 1
0
        public virtual async Task <CallResult <UpdateSubscription> > SubscribeToKlinesAsync(string symbol, ThodexPeriod period, Action <ThodexSocketCandle> onData)
        {
            var internalHandler = new Action <ThodexSocketUpdateResponse>(data =>
            {
                if (data.Method == WSMethods_Kline_Update && data.Data.Count == 1)
                {
                    var json = data.Data[0].ToString();
                    if (json.StartsWith("[[") && json.EndsWith("]]"))
                    {
                        var klines = JsonConvert.DeserializeObject <IEnumerable <ThodexSocketCandle> >(json);
                        foreach (var kline in klines)
                        {
                            if (kline.Symbol.ToUpper() == symbol.ToUpper())
                            {
                                onData(kline);
                            }
                        }
                    }
                    else
                    {
                        var kline = JsonConvert.DeserializeObject <ThodexSocketCandle>(json);
                        if (kline.Symbol.ToUpper() == symbol.ToUpper())
                        {
                            onData(kline);
                        }
                    }
                }
            });

            var request = new ThodexSocketRequest(this.NextRequestId(), WSMethods_Kline_Subscribe, symbol, Convert.ToInt32(JsonConvert.SerializeObject(period, new PeriodConverter(false))));;

            return(await Subscribe(request, null, false, internalHandler).ConfigureAwait(false));
        }
Esempio n. 2
0
 public virtual CallResult <UpdateSubscription> SubscribeToKlines(string symbol, ThodexPeriod period, Action <ThodexSocketCandle> onData) => SubscribeToKlinesAsync(symbol, period, onData).Result;