Exemple #1
0
        public async void UpdateOhlc(object state)
        {
            var ohlcPair1440 = await _kraken.UpdateOhlc(1440);

            var ohlcPair60 = await _kraken.UpdateOhlc(60);

            if (ohlcPair1440 == null || ohlcPair60 == null)
            {
                _logger.LogWarning($"Ohlc update failed: {DateTime.Now}");
                return;
            }

            OhlcPair1440 = ohlcPair1440;
            OhlcPair60   = ohlcPair60;

            List <ChartData> chartData = new List <ChartData>();
            List <Asset>     a         = _asset.Assets["eurisk"];

            foreach (var ohlc in OhlcPair1440.Ohlc)
            {
                var t = Converters.UnixTimestampToDateTime(ohlc.Time);

                // Find the Asset with the closest DateTime to the ohlc object.
                var asset = a.OrderBy(m => Math.Abs((t - m.Time).TotalMilliseconds)).First();

                chartData.Add(new ChartData()
                {
                    Time  = t,
                    Value = decimal.Ceiling(asset.Ask * ohlc.Open * 1.02m + 100m)
                            //y = new decimal[4] { u.Open, u.High, u.Low, u.Close }
                });
            }

            ChartPair1440 = new ChartPair()
            {
                Pair      = OhlcPair1440.Pair,
                Last      = OhlcPair1440.Last,
                ChartData = chartData
            };

            _logger.LogInformation($"Ohlc updated: {DateTime.Now}");
        }
Exemple #2
0
        public async Task <decimal> GetDailyChange()
        {
            var ohlcPair = await _kraken.UpdateOhlc(60);

            if (ohlcPair == null)
            {
                return(Decimal.Zero);
            }

            var ohlc = ohlcPair.Ohlc.ToList().OrderBy(m =>
                                                      Math.Abs((
                                                                   DateTime.Now.AddDays(-1) -
                                                                   Converters.UnixTimestampToDateTime(m.Time)
                                                                   ).TotalMilliseconds)).First();

            var asset = _asset.Assets["eurisk"].OrderBy(m =>
                                                        Math.Abs((DateTime.Now.AddDays(-1) - m.Time).TotalMilliseconds)).First();

            return((_btceur.Ask[0] - ohlc.Open) * asset.Ask);
        }