public void SubscribeCandlesticks(string symbol, Interface.Model.CandlestickInterval candlestickInterval, int limit, Action <CandlestickEventArgs> callback, Action <Exception> exception, CancellationToken cancellationToken) { try { var interval = candlestickInterval.ToBinanceCandlestickInterval(); var canclestickCache = new CandlestickCache(binanceApi, new CandlestickWebSocketClient()); canclestickCache.Subscribe(symbol, interval, limit, e => { if (cancellationToken.IsCancellationRequested) { canclestickCache.Unsubscribe(); return; } try { var candlesticks = (from c in e.Candlesticks select NewCandlestick(c)).ToList(); callback.Invoke(new CandlestickEventArgs { Candlesticks = candlesticks }); } catch (Exception ex) { canclestickCache.Unsubscribe(); exception.Invoke(ex); } }); } catch (Exception ex) { exception.Invoke(ex); } }
public static CandlestickInterval ToBinanceCandlestickInterval(this Interface.Model.CandlestickInterval candlestickInterval) { switch (candlestickInterval) { case Interface.Model.CandlestickInterval.Minute: return(CandlestickInterval.Minute); case Interface.Model.CandlestickInterval.Minutes_3: return(CandlestickInterval.Minutes_3); case Interface.Model.CandlestickInterval.Minutes_5: return(CandlestickInterval.Minutes_5); case Interface.Model.CandlestickInterval.Minutes_15: return(CandlestickInterval.Minutes_15); case Interface.Model.CandlestickInterval.Minutes_30: return(CandlestickInterval.Minutes_30); case Interface.Model.CandlestickInterval.Hour: return(CandlestickInterval.Hour); case Interface.Model.CandlestickInterval.Hours_2: return(CandlestickInterval.Hours_2); case Interface.Model.CandlestickInterval.Hours_4: return(CandlestickInterval.Hours_4); case Interface.Model.CandlestickInterval.Hours_6: return(CandlestickInterval.Hours_6); case Interface.Model.CandlestickInterval.Hours_8: return(CandlestickInterval.Hours_8); case Interface.Model.CandlestickInterval.Hours_12: return(CandlestickInterval.Hours_12); case Interface.Model.CandlestickInterval.Day: return(CandlestickInterval.Day); case Interface.Model.CandlestickInterval.Days_3: return(CandlestickInterval.Days_3); case Interface.Model.CandlestickInterval.Week: return(CandlestickInterval.Week); case Interface.Model.CandlestickInterval.Month: return(CandlestickInterval.Month); default: throw new NotImplementedException(); } }
public static KucoinKlineInterval ToKucoinCandlestickInterval(this Interface.Model.CandlestickInterval candlestickInterval) { switch (candlestickInterval) { case Interface.Model.CandlestickInterval.Minute: return(KucoinKlineInterval.OneMinute); case Interface.Model.CandlestickInterval.Minutes_3: return(KucoinKlineInterval.ThreeMinutes); case Interface.Model.CandlestickInterval.Minutes_5: return(KucoinKlineInterval.FiveMinutes); case Interface.Model.CandlestickInterval.Minutes_15: return(KucoinKlineInterval.FifteenMinutes); case Interface.Model.CandlestickInterval.Minutes_30: return(KucoinKlineInterval.ThirtyMinutes); case Interface.Model.CandlestickInterval.Hour: return(KucoinKlineInterval.OneHour); case Interface.Model.CandlestickInterval.Hours_2: return(KucoinKlineInterval.TwoHours); case Interface.Model.CandlestickInterval.Hours_4: return(KucoinKlineInterval.FourHours); case Interface.Model.CandlestickInterval.Hours_6: return(KucoinKlineInterval.SixHours); case Interface.Model.CandlestickInterval.Hours_8: return(KucoinKlineInterval.EightHours); case Interface.Model.CandlestickInterval.Hours_12: return(KucoinKlineInterval.TwelfHours); case Interface.Model.CandlestickInterval.Day: return(KucoinKlineInterval.OneDay); case Interface.Model.CandlestickInterval.Week: return(KucoinKlineInterval.OneWeek); default: throw new NotImplementedException(); } }
public async Task <IEnumerable <Candlestick> > GetCandlesticksAsync(Exchange exchange, string symbol, Interface.Model.CandlestickInterval interval, DateTime startTime, DateTime endTime, int limit = default(int), CancellationToken token = default(CancellationToken)) { var results = await exchangeService.GetCandlesticksAsync(exchange, symbol, interval, startTime, endTime, limit, token).ConfigureAwait(false); var candlesticks = results.Select(c => c.ToViewCandlestick()).ToList(); return(candlesticks); }
public Task SubscribeCandlesticks(Exchange exchange, string symbol, Interface.Model.CandlestickInterval candlestickInterval, int limit, Action <CandlestickEventArgs> callback, Action <Exception> exception, CancellationToken cancellationToken) { return(exchangeService.SubscribeCandlesticks(exchange, symbol, candlestickInterval, limit, callback, exception, cancellationToken)); }
public async Task <IEnumerable <Interface.Model.Candlestick> > GetCandlesticksAsync(string symbol, Interface.Model.CandlestickInterval interval, DateTime startTime, DateTime endTime, int limit = 0, CancellationToken token = default(CancellationToken)) { var candlestickInterval = interval.ToBinanceCandlestickInterval(); var results = await binanceApi.GetCandlesticksAsync(symbol, candlestickInterval, startTime, endTime, limit, token).ConfigureAwait(false); var candlesticks = results.Select(cs => NewCandlestick(cs)).ToList(); return(candlesticks); }