Пример #1
0
        private void ProcessNews(IEnumerable <NewsEvent> events)
        {
            newsObserver = null;
            var newNews = events.Select(evt => new NewsContainer(evt))
                          .Except(News, new LambdaComparer <NewsContainer>((l, r) => l.Event.Level == r.Event.Level && l.Event.Name == r.Event.Name && l.Event.Time == r.Event.Time));

            if (_useDb)
            {
                ForexStorage.UseForexContext(c => {
                    var dateLast = c.Event__News.Max(e => e.Time);
                    newNews.ToList().Select(evt => evt.Event)
                    //.Where(evt => evt.Time > dateLast)
                    .ForEach(evt => {
                        c.Event__News.Add(new Event__News()
                        {
                            Level   = (evt.Level + "").Substring(0, 1),
                            Country = evt.Country,
                            Name    = evt.Name,
                            Time    = evt.Time
                        });
                        c.SaveConcurrent();
                    });
                }, (c, exc) => Log = exc);
            }
            ReactiveUI.RxApp.MainThreadScheduler.Schedule(() => {
                newNews.ForEach(evt => News.Add(evt));
                NewsView.GroupDescriptions.Clear();
                NewsView.GroupDescriptions.Add(new PropertyGroupDescription("Date"));
                NewsView.Refresh();
                UpdateNewsColor();
            });
        }
Пример #2
0
 void Show(DateTime? dateStart) {
   var ticks = ForexStorage.UseForexContext(c => {
     var period = BarPeriod;
     var pair = PairCurrent;
     if (string.IsNullOrWhiteSpace(PairCurrent)) throw new Exception("Piar is empty.");
     var q = c.t_Bar.Where(b => b.Period == period && b.Pair == pair && b.StartDateLocal < DateStart.Value).OrderByDescending(b => b.StartDate).Take(DateLength / 2);
     if( !dateStart.HasValue)dateStart = q.Min(b => b.StartDateLocal);
     return c.t_Bar.Where(b => b.Period == period && b.Pair == pair && b.StartDateLocal >= dateStart)
       .Take(DateLength).OrderBy(b => b.StartDate)
       .Select(b => new DatePoint() { X = b.StartDateLocal.Value, Y = (b.AskClose + b.AskOpen) / 2 })
       .ToArray();
   }, (c, e) => LogMessage.Send(e));
   AddTicks(ticks);
   var newsStart = ticks[0].X;
   var newsEnd = ticks.Last().X;
   var news = ForexStorage.UseForexContext(
     c => c.Event__News.Where(ne => ne.Time >= newsStart && ne.Time <= newsEnd).ToArray(),
     (c, exc) => LogMessage.Send(exc));
   NewsEvents.Except(news, _newsEventComparer).ToList().ForEach(ne => NewsEvents.Remove(ne));
   NewsEvents.AddRange(news.Except(NewsEvents, _newsEventComparer));
   NewsEvents.Sort(new Comparison<Event__News>(_newsEventComparicon));
   //NewsEventCurrent = NewsEvents.FirstOrDefault(CompareNewsEvents);
   DrawVertivalLines(new DateTime[0]);
   DrawVertivalLines(news.Select(ne => ne.Time.DateTime).ToArray());
 }
Пример #3
0
 private void ReadNewsEventsHistoryFromDB(string country,string name, DateTimeOffset dateStart, DateTimeOffset dateEnd) {
   var newsHistory = ForexStorage.UseForexContext(c =>
     c.Event__News.Where(dbEv => dbEv.Name == name && dbEv.Country == country &&
       dbEv.Time >= dateStart && dbEv.Time <= dateEnd)
     .OrderByDescending(db => db.Time).ToArray()
   );
   NewsEventHistory.Clear();
   NewsEventHistory.AddRange(newsHistory);
   NewsEventHistory.Sort(new Comparison<Event__News>(_newsEventComparicon));
 }
Пример #4
0
        public void SessionInfoTest()
        {
            var re = new Regex(@":(\d\d):(\d\d)-(\d\d):(\d\d)", RegexOptions.Compiled);

            ForexStorage.UseForexContext(c => {
                c.t_Trade.ToList().ForEach(t => {
                    if (re.IsMatch(t.SessionInfo))
                    {
                        var session   = re.Replace(t.SessionInfo, ":$1|$2-$3|$4");
                        session       = session.Replace(":", "\t").Replace("|", ":");
                        t.SessionInfo = session;
                    }
                });
            }, null, c => c.SaveChanges(), 60 * 10);
            TestContext.WriteLine("Done");
        }
Пример #5
0
 static NewsCasterModel()
 {
     if (_useDb)
     {
         SavedNews = ForexStorage.UseForexContext(c => c.Event__News.ToArray()
                                                  .Select(ne => new NewsEvent()
         {
             Country = ne.Country,
             Level   = (NewsEventLevel)Enum.Parse(typeof(NewsEventLevel), ne.Level),
             Name    = ne.Name,
             Time    = ne.Time
         }).ToArray(),
                                                  (c, e) => {
             Default.Log = e;
             SavedNews   = new NewsEvent[0];
         });
     }
 }
Пример #6
0
    public CharterSnapshotControl() {
      InitializeComponent();

      this.SizeChanged += (s, e) => FitToView();

      MessageBus.Current.Listen<HedgeHog.NewsCaster.NewsEvent>("Snapshot")
        .Throttle(1.FromSeconds(),DispatcherScheduler.Current)
        .Where(ne => VisualParent != null)
        .Subscribe(ne => {
          try {
            var monthOffset = 3;
            var dateStart = ne.Time.AddMonths(-monthOffset*2);
            var dateEnd = ne.Time.AddDays(-1);
            ReadNewsEventsHistoryFromDB(ne.Country, ne.Name, dateStart, dateEnd);
            NewsHistoryCurrent = NewsEventHistory.First();
            NewsEventCurrent = NewsEvents.FirstOrDefault(n => n.Country == ne.Country && n.Name == ne.Name);
            DateStart = NewsEventHistory.First().Time.DateTime;
            Show();
          } catch (Exception exc) { LogMessage.Send(exc); }
        });

      Pairs.AddRange(ForexStorage.UseForexContext(c => c.v_Pair.ToArray(), (c, ex) => LogMessage.Send(ex)));
      otherVLines.Changing.ObserveOnDispatcher()
        .Subscribe(ev => {
          switch (ev.Action) {
            case NotifyCollectionChangedAction.Reset:
            case NotifyCollectionChangedAction.Remove:
              try {
                ev.OldItems.Cast<IPlotterElement>().ToList().ForEach(vl => plotter.Children.Remove(vl));
              } catch (Exception exc) {
                LogMessage.Send(exc);
              }
              return;
            case NotifyCollectionChangedAction.Add:
              ev.NewItems.Cast<VerticalLine>().ForEach(vl => plotter.Children.Add(vl));
              return;
          }
        });
      DispatcherScheduler.Current.Schedule(1.FromSeconds(), () => {
        Event__News newsEventPrev = null;
        this.ObservableForProperty(me => me.NewsEventCurrent, ne => ne).Subscribe(ne => {
          try {
            if (ne == null || CompareNewsEvents(ne, newsEventPrev)) return;
            newsEventPrev = ne;
            DateStart = ne.Time.DateTime;
            Show();
            var monthOffset = 3;
            var dateStart = ne.Time.AddMonths(-monthOffset);
            var dateEnd = ne.Time.AddMonths(monthOffset);
            ReadNewsEventsHistoryFromDB(ne.Country, ne.Name, dateStart, dateEnd);
            NewsHistoryCurrent = NewsEventHistory.FirstOrDefault(n =>
              n.Country == NewsEventCurrent.Country && n.Name == NewsHistoryCurrent.Name && n.Time == NewsEventCurrent.Time);
          } catch (Exception ex) { LogMessage.Send(ex); }
        }, ex => LogMessage.Send(ex), () => LogMessage.Send("Done with NewsEventCurrent."));

        this.ObservableForProperty(me => me.NewsHistoryCurrent, nh => nh).Subscribe(nh => {
          try {
            if (nh == null || CompareNewsEvents(NewsEventCurrent, nh)) return;
            DateStart = nh.Time.DateTime;
            Show();
            var newsEvent = NewsEvents.SingleOrDefault(ne => ne.Country == nh.Country && ne.Name == nh.Name);
            if (newsEvent != null)
              NewsEventCurrent = newsEventPrev = newsEvent;
          } catch (Exception ex) { LogMessage.Send(ex); }
        });

        this.ObservableForProperty(me => me.PairCurrent).Subscribe(oc => Show());
      });
    }