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);
        }
Exemple #2
0
        public async Task <IEnumerable <decimal> > GetClosingPrices(string orderBase, string orderSymbol, Period period)
        {
            var symbol = $"{orderSymbol}/{orderBase}";

            var candleStickInterval = ConvertPeriodToCandlestickInterval(period);

            var candlesticks = await _binanceClient.GetCandlesticksAsync(symbol, candleStickInterval);

            var closingPrices = ConvertCandlestickToClosingPrices(candlesticks);

            return(closingPrices);
        }
Exemple #3
0
        public static async Task <decimal> GetPriceByDate(string symbol, DateTime date)
        {
            var api          = new BinanceApi();
            var candleSticks = await api.GetCandlesticksAsync(symbol, CandlestickInterval.Minute, date, date.AddMinutes(1));

            if (candleSticks != null && candleSticks.Any())
            {
                return(((candleSticks.First().High + candleSticks.First().Low) / 2m).RoundTo(8));
            }
            else
            {
                return(0m);
            }
        }
        public async Task <DataTable> GetVolumes()
        {
            BinanceApi api = new BinanceApi();

            await SetupCoinData();

            while (true)
            {
                foreach (DataRow pricer in CoinData.Rows)
                {
                    IEnumerable <Candlestick> eighthourcandles = await api.GetCandlesticksAsync(pricer[0].ToString(),
                                                                                                CandlestickInterval.Minutes_5, 0, 0L, 0L, CancellationToken.None);

                    IOrderedEnumerable <Candlestick> candlearray = eighthourcandles.OrderByDescending(e => e.CloseTime);
                    decimal averagevolumeeighthours = candlearray.Average(candlestick => candlestick.Volume);
                    decimal fifteenminavg           = (candlearray.ElementAt(1).Volume + candlearray.ElementAt(2).Volume +
                                                       candlearray.ElementAt(0).Volume) / 3;
                    DataRow row = CoinData.Rows.Cast <DataRow>().First(o => o[0].ToString() == pricer[0].ToString());
                    row[1] = DateTime.UtcNow;
                    row[2] = Decimal.Round(averagevolumeeighthours, MidpointRounding.AwayFromZero);
                    row[3] = PercentGive(candlearray.First().Volume, averagevolumeeighthours);
                    row[4] = PercentGive(fifteenminavg, averagevolumeeighthours);
                    int greencandles = 0;
                    int i            = 0;
                    while (i != 20)
                    {
                        if (candlearray.ElementAt(i).Close > candlearray.ElementAt(i + 1).Close)
                        {
                            greencandles++;
                        }
                        else
                        {
                            break;
                        }
                        i++;
                    }
                    row[5] = greencandles;
                    CoinData.DefaultView.RowFilter = "NowPercent > 0";
                    //var filtered = CoinData.Select().Where(o => Convert.ToDecimal(o[3].ToString()) > Convert.ToDecimal(o[4].ToString()));
                    DataViewColours();
                    coindatagridview.DataSource = CoinData;
                    coindatagridview.Sort(coindatagridview.Columns[3], ListSortDirection.Descending);
                }
            }

            return(CoinData);
        }