public static CandlestickInterval ToBinanceCandlestickInterval(this Core.Model.CandlestickInterval candlestickInterval)
        {
            switch (candlestickInterval)
            {
            case Core.Model.CandlestickInterval.Minute:
                return(CandlestickInterval.Minute);

            case Core.Model.CandlestickInterval.Minutes3:
                return(CandlestickInterval.Minutes_3);

            case Core.Model.CandlestickInterval.Minutes5:
                return(CandlestickInterval.Minutes_5);

            case Core.Model.CandlestickInterval.Minutes15:
                return(CandlestickInterval.Minutes_15);

            case Core.Model.CandlestickInterval.Minutes30:
                return(CandlestickInterval.Minutes_30);

            case Core.Model.CandlestickInterval.Hour:
                return(CandlestickInterval.Hour);

            case Core.Model.CandlestickInterval.Hours2:
                return(CandlestickInterval.Hours_2);

            case Core.Model.CandlestickInterval.Hours4:
                return(CandlestickInterval.Hours_4);

            case Core.Model.CandlestickInterval.Hours6:
                return(CandlestickInterval.Hours_6);

            case Core.Model.CandlestickInterval.Hours8:
                return(CandlestickInterval.Hours_8);

            case Core.Model.CandlestickInterval.Hours12:
                return(CandlestickInterval.Hours_12);

            case Core.Model.CandlestickInterval.Day:
                return(CandlestickInterval.Day);

            case Core.Model.CandlestickInterval.Days3:
                return(CandlestickInterval.Days_3);

            case Core.Model.CandlestickInterval.Week:
                return(CandlestickInterval.Week);

            case Core.Model.CandlestickInterval.Month:
                return(CandlestickInterval.Month);

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
 public static CandlestickInterval ToBinanceCandlestickInterval(this Core.Model.CandlestickInterval candlestickInterval)
 {
     return(candlestickInterval switch
     {
         Core.Model.CandlestickInterval.Minute => CandlestickInterval.Minute,
         Core.Model.CandlestickInterval.Minutes3 => CandlestickInterval.Minutes_3,
         Core.Model.CandlestickInterval.Minutes5 => CandlestickInterval.Minutes_5,
         Core.Model.CandlestickInterval.Minutes15 => CandlestickInterval.Minutes_15,
         Core.Model.CandlestickInterval.Minutes30 => CandlestickInterval.Minutes_30,
         Core.Model.CandlestickInterval.Hour => CandlestickInterval.Hour,
         Core.Model.CandlestickInterval.Hours2 => CandlestickInterval.Hours_2,
         Core.Model.CandlestickInterval.Hours4 => CandlestickInterval.Hours_4,
         Core.Model.CandlestickInterval.Hours6 => CandlestickInterval.Hours_6,
         Core.Model.CandlestickInterval.Hours8 => CandlestickInterval.Hours_8,
         Core.Model.CandlestickInterval.Hours12 => CandlestickInterval.Hours_12,
         Core.Model.CandlestickInterval.Day => CandlestickInterval.Day,
         Core.Model.CandlestickInterval.Days3 => CandlestickInterval.Days_3,
         Core.Model.CandlestickInterval.Week => CandlestickInterval.Week,
         Core.Model.CandlestickInterval.Month => CandlestickInterval.Month,
         _ => throw new NotImplementedException(),
     });
Ejemplo n.º 3
0
        public Task SubscribeCandlesticks(string symbol, Core.Model.CandlestickInterval candlestickInterval, int limit, Action <CandlestickEventArgs> callback, Action <Exception> exception, CancellationToken cancellationToken)
        {
            var tcs = new TaskCompletionSource <object>();

            var binanceApi       = new BinanceApi();
            var interval         = candlestickInterval.ToBinanceCandlestickInterval();
            var candlestickCache = new CandlestickCache(binanceApi, new CandlestickWebSocketClient());

            candlestickCache.Subscribe(symbol, interval, limit, e =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    candlestickCache.Unsubscribe();
                    return;
                }

                var candlesticks = (from c in e.Candlesticks select NewCandlestick(c)).ToList();

                try
                {
                    callback.Invoke(new CandlestickEventArgs {
                        Candlesticks = candlesticks
                    });
                }
                catch (Exception ex)
                {
                    candlestickCache.Unsubscribe();
                    exception.Invoke(ex);
                    return;
                }
            });

            tcs.SetResult(null);

            return(tcs.Task);
        }
Ejemplo n.º 4
0
        public async Task <IEnumerable <Candlestick> > GetCandlesticksAsync(Exchange exchange, string symbol, Core.Model.CandlestickInterval interval, DateTime startTime, DateTime endTime, int limit = default, CancellationToken token = default)
        {
            var results = await exchangeService.GetCandlesticksAsync(exchange, symbol, interval, startTime, endTime, limit, token).ConfigureAwait(false);

            var candlesticks = results.Select(c => c.ToViewCandlestick()).ToList();

            return(candlesticks);
        }
Ejemplo n.º 5
0
 public Task SubscribeCandlesticks(Exchange exchange, string symbol, Core.Model.CandlestickInterval candlestickInterval, int limit, Action <CandlestickEventArgs> callback, Action <Exception> exception, CancellationToken cancellationToken)
 {
     return(exchangeService.SubscribeCandlesticks(exchange, symbol, candlestickInterval, limit, callback, exception, cancellationToken));
 }
Ejemplo n.º 6
0
        public async Task <IEnumerable <Core.Model.Candlestick> > GetCandlesticksAsync(string symbol, Core.Model.CandlestickInterval interval, DateTime startTime, DateTime endTime, int limit = 0, CancellationToken token = default)
        {
            var binanceApi          = new BinanceApi();
            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);
        }