private static void Display(CandlestickEventArgs args) { lock (_sync) { _candlesticks[args.Candlestick.Symbol] = args.Candlestick; if (_displayTask.IsCompleted) { // Delay to allow multiple data updates between display updates. _displayTask = Task.Delay(250) .ContinueWith(_ => { Candlestick[] latestCandlesticks; lock (_sync) { latestCandlesticks = _candlesticks.Values.ToArray(); } Console.SetCursorPosition(0, 0); foreach (var c in latestCandlesticks) { Console.WriteLine($" {c.Symbol} - O: {c.Open:0.00000000} | H: {c.High:0.00000000} | L: {c.Low:0.00000000} | C: {c.Close:0.00000000} | V: {c.Volume:0.00} - [{c.OpenTime.ToTimestamp()}]".PadRight(119)); Console.WriteLine(); } Console.WriteLine(_message.PadRight(119)); }); } } }
public void Properties() { var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); const long firstTradeId = 1234567890; const long lastTradeId = 1234567899; const bool isFinal = true; var symbol = Symbol.BTC_USDT; const CandlestickInterval interval = CandlestickInterval.Hour; const long openTime = 1234567890; const decimal open = 4950; const decimal high = 5100; const decimal low = 4900; const decimal close = 5050; const decimal volume = 1000; const long closeTime = 2345678901; const long quoteAssetVolume = 5000000; const int numberOfTrades = 555555; const decimal takerBuyBaseAssetVolume = 4444; const decimal takerBuyQuoteAssetVolume = 333; var candlestick = new Candlestick(symbol, interval, openTime, open, high, low, close, volume, closeTime, quoteAssetVolume, numberOfTrades, takerBuyBaseAssetVolume, takerBuyQuoteAssetVolume); using (var cts = new CancellationTokenSource()) { var args = new CandlestickEventArgs(timestamp, cts.Token, candlestick, firstTradeId, lastTradeId, isFinal); Assert.Equal(timestamp, args.Timestamp); Assert.Equal(candlestick, args.Candlestick); Assert.Equal(firstTradeId, args.FirstTradeId); Assert.Equal(lastTradeId, args.LastTradeId); Assert.Equal(isFinal, args.IsFinal); } }
private static void OnCandlestickEvent(object sender, CandlestickEventArgs e) { lock (Program.ConsoleSync) { Console.WriteLine($" Candlestick [{e.Candlestick.OpenTime}] - Is Final: {(e.IsFinal ? "YES" : "NO")}"); } }
public virtual void SubscribeCandlesticks(CandlestickEventArgs candlestickEventArgs) { var message = JsonConvert.SerializeObject(candlestickEventArgs.Candlesticks); var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = message, NotificationLevel = NotificationLevel.Candlesticks }; StrategyCandlesticksNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); }
private void OnCandletickUpdate(CandlestickEventArgs args) { var immutableCandleticks = _cache.GetCandlesticks(args.Candlestick.Symbol, args.Candlestick.Interval); if (immutableCandleticks != null && immutableCandleticks.Any()) { var mutableCandletickes = immutableCandleticks.ToBuilder(); var previousCandletick = mutableCandletickes.FirstOrDefault(p => p.OpenTime == args.Candlestick.OpenTime); mutableCandletickes.Remove(previousCandletick ?? mutableCandletickes.FirstOrDefault()); mutableCandletickes.Add(args.Candlestick); _cache.SetCandlestick(args.Candlestick.Symbol, args.Candlestick.Interval, mutableCandletickes.ToImmutable()); } }
public virtual void SubscribeCandlesticks(CandlestickEventArgs candlestickEventArgs) { if (candlestickEventArgs == null) { throw new ArgumentNullException(nameof(candlestickEventArgs)); } var message = JsonConvert.SerializeObject(candlestickEventArgs.Candlesticks); var strategyNotification = new StrategyNotification { Name = Strategy.Name, Message = message, NotificationLevel = NotificationLevel.Candlesticks }; StrategyCandlesticksNotification(new StrategyNotificationEventArgs { StrategyNotification = strategyNotification }); }
private void Display(CandlestickEventArgs args) => Program.Display(args.Candlestick);