public Candle(int x, CandlePayload candle) { Close = (double)candle.Close; Open = (double)candle.Open; High = (double)candle.High; Low = (double)candle.Low; DateTime = candle.Time; X = x; }
public void LogCandle(CandlePayload candle) { MinuteCandles[candle.Time.ToLocalTime()] = candle; if (MinuteCandles.Count > 100) { MinuteCandles.OrderBy(p => p.Key).Take(50).ToList() .ForEach(p => MinuteCandles.Remove(p.Key, out _)); } }
public void LogCandle(CandlePayload candle) { var t = DateTime.Now; t = t.AddMilliseconds(-t.Millisecond).AddSeconds(-t.Second); MinuteCandles[t] = candle; if (MinuteCandles.Count > 100) { MinuteCandles.OrderBy(p => p.Key).Take(50).ToList() .ForEach(p => MinuteCandles.Remove(p.Key)); } }
public static YesterdayCandleData Create(MarketInstrument stock, CandlePayload candle) { return(new YesterdayCandleData( stock.Figi, stock.Name, Convert.ToInt32(candle.Volume), candle.Open, candle.Close, candle.Low, candle.High, stock.Currency, stock.MinPriceIncrement )); }
public static Infrastructure.Common.Models.Market.Candle ToOuterModel(this CandlePayload source) { var target = new Infrastructure.Common.Models.Market.Candle { Moment = source.Time, OpenPrice = source.Open, ClosePrice = source.Close, MaxPrice = source.High, MinPrice = source.Low, VolumeInBaseCurrency = source.Volume, VolumeInQuoteCurrency = source.Volume }; return(target); }
public void AddCandle(CandlePayload candle) { if (_candles == null) { _candles = new HashSet <ICandleModel>(); } _candles.Add(new CandleViewModel() { Interval = candle.Interval, Open = candle.Open, Close = candle.Close, Low = candle.Low, High = candle.High, Time = candle.Time }); }
private static string MakeNotificationMessage(NotificationRule notificationRule, MarketInstrument instrument, CandlePayload firstCandle, CandlePayload lastCandle) { var priceChange = lastCandle.Close - firstCandle.Close; var priceChangeInPercent = 100 * priceChange / firstCandle.Close; var msg = $"{(notificationRule.PriceDirection == PriceDirection.Decrased ? "📉" : "📈") } " + $"${instrument.Ticker} {lastCandle.Close} {instrument.Currency}\r\n" + $"{notificationRule.TimePeriodInHours}h / {priceChangeInPercent.ToString("F2")} % / {(priceChange >= 0 ? "+" : "")}{priceChange.ToString("F2")} {instrument.Currency}\r\n" + $"{"https://www.tinkoff.ru/invest/stocks/"}{instrument.Ticker}"; return(msg); }
public async Task SendNotification(NotificationRule notificationRule, MarketInstrument instrument, CandlePayload firstCandle, CandlePayload lastCandle) { if (_notificationTimestampToTicker == null) { await LoadLastSendTimes(); } try { if (!_notificationTimestampToTicker.ContainsKey(instrument.Ticker) || (_notificationTimestampToTicker.ContainsKey(instrument.Ticker) && DateTime.UtcNow - _notificationTimestampToTicker[instrument.Ticker] >= TimeSpan.FromHours(notificationRule.TimePeriodInHours))) { var msg = MakeNotificationMessage(notificationRule, instrument, firstCandle, lastCandle); await _telegramBot.SendNotification(msg); _notificationTimestampToTicker[instrument.Ticker] = DateTime.UtcNow; await SaveLastSendTimes(); } } catch (Exception ex) { Log.Error(ex.ToString()); await Task.Delay(TimeSpan.FromSeconds(1)); } }
public CandleMessage(string @event, CandlePayload payload) { Event = @event; Payload = payload; }
private static void LogTicker(MarketInstrument instrument, NotificationRule notificationRule, CandlePayload lastCandle, CandlePayload firstCandle) { var priceChange = lastCandle.Close - firstCandle.Close; var priceChangeInPercent = 100 * priceChange / firstCandle.Close; var msg = $"${instrument.Ticker} " + $"{notificationRule.TimePeriodInHours}h / {priceChangeInPercent.ToString("F2")} % / {(priceChange >= 0 ? "+" : "")}{priceChange.ToString("F2")} {instrument.Currency} / " + $"{firstCandle.Close} {instrument.Currency} -> {lastCandle.Close} {instrument.Currency} / " + $"{firstCandle.Time:dd.MM.yyyy HH:mm} -> {lastCandle.Time:dd.MM.yyyy HH:mm}"; Log.Write(notificationRule.IsActual(firstCandle.Close, lastCandle.Close) ? Serilog.Events.LogEventLevel.Warning : Serilog.Events.LogEventLevel.Information, msg); }