Example #1
0
 public void Update(TeleSubscription subscription)
 {
     foreach (var kp in LastSignificantPrice)
     {
         subscription.LastSignificantPrice[kp.Key].HighestBid = kp.Value.HighestBid;
         subscription.LastSignificantPrice[kp.Key].LowestAsk  = kp.Value.LowestAsk;
         subscription.LastSignificantPrice[kp.Key].Time       = kp.Value.Time;
     }
 }
        private void StartSubscription(CryptoExchangeBase exchange, TeleSubscription sub)
        {
            var subscription = new TelegramSubscription(exchange, sub);

            subscription.Changed += SendSubscriptionReply;
            subscription.Changed += async(s, o, n) => await UpdateSubscriptionInDb(s, n).ConfigureAwait(false);

            exchange.Subscribe(subscription);
            lock (subscriptionLock)
                Subscriptions.Add(subscription);
        }
Example #3
0
 public TelegramSubscription(
     CryptoExchangeBase exchange,
     TeleSubscription subscription)
     : base(exchange)
 {
     Id                   = subscription.Id;
     ChatId               = subscription.ChatId;
     UserName             = subscription.UserName;
     ExchangeId           = exchange.Id;
     Threshold            = subscription.Threshold;
     LastSignificantPrice = subscription.LastSignificantPrice.ToDictionary(
         x => x.Key,
         x => new CryptoCoin(x.Value)
         );
     Coins = subscription.Coins.Select(c => c.Id).ToImmutableHashSet( );
 }
 private TimeSpan _updateInterval = new TimeSpan(0, 0, 0, 0, 50); //500 ms
 private void TestCalibration_Loaded(object sender, RoutedEventArgs e)
 {
     _ts = Telemetry.Subscribe(KFlyCommandType.GetEstimationAttitude, (GetEstimationAttitude cmd) =>
     {
         view1.Dispatcher.BeginInvoke(new Action(()=>
             {
                 QuaternionRotation3D rot = new QuaternionRotation3D(
                     new System.Windows.Media.Media3D.Quaternion(
                         -cmd.Data.X, -cmd.Data.Y, -cmd.Data.Z, cmd.Data.W));
                 KFlyRotation.Rotation = rot;
             }));
     });
     _timer = new DispatcherTimer();
     _timer.Tick += new EventHandler(DispatcherTimer_Tick);
     _timer.Interval = _updateInterval;
     _timer.Start();
     Load3DModel();
 }
        private void TestCalibration_Loaded(object sender, RoutedEventArgs e)
        {
            _ts = Telemetry.Subscribe(KFlyCommandType.GetSensorData, (GetSensorData cmd) =>
            {
                  double now = DateTimeAxis.ToDouble(DateTime.Now);
                  Gyro.Dispatcher.BeginInvoke(new Action(()=>
                    {
                        (Gyro.Model.Series[0] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Gyro.X));
                        (Gyro.Model.Series[1] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Gyro.Y));
                        (Gyro.Model.Series[2] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Gyro.Z));
                        (Accelerometer.Model.Series[0] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Accelerometer.X));
                        (Accelerometer.Model.Series[1] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Accelerometer.Y));
                        (Accelerometer.Model.Series[2] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Accelerometer.Z));
                        (Magnometer.Model.Series[0] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Magnometer.X));
                        (Magnometer.Model.Series[1] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Magnometer.Y));
                        (Magnometer.Model.Series[2] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Magnometer.Z));

                        _updateGraphCounter++;
                        if (_updateGraphCounter >= _updateIntervalGraph)
                        {
                            _updateGraphCounter = 0;
                            Gyro.RefreshPlot(true);
                            Accelerometer.RefreshPlot(true);
                            Magnometer.RefreshPlot(true);
                        }
                    }));
            });
            _ts2 = Telemetry.Subscribe(KFlyCommandType.GetRawSensorData, (GetRawSensorData cmd) =>
            {
                double now = DateTimeAxis.ToDouble(DateTime.Now);
                Gyro.Dispatcher.BeginInvoke(new Action(() =>
                {
                    (Gyro.Model.Series[0] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Gyro.X));
                    (Gyro.Model.Series[1] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Gyro.Y));
                    (Gyro.Model.Series[2] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Gyro.Z));
                    (Accelerometer.Model.Series[0] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Accelerometer.X));
                    (Accelerometer.Model.Series[1] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Accelerometer.Y));
                    (Accelerometer.Model.Series[2] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Accelerometer.Z));
                    (Magnometer.Model.Series[0] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Magnometer.X));
                    (Magnometer.Model.Series[1] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Magnometer.Y));
                    (Magnometer.Model.Series[2] as LineSeries).Points.Add(new DataPoint(now, cmd.Data.Magnometer.Z));

                    _updateGraphCounter++;
                    if (_updateGraphCounter >= _updateIntervalGraph)
                    {
                        _updateGraphCounter = 0;
                        Gyro.RefreshPlot(true);
                        Accelerometer.RefreshPlot(true);
                        Magnometer.RefreshPlot(true);
                    }
                }));
            });
               _timer = new DispatcherTimer();
            _timer.Tick += new EventHandler(DispatcherTimer_Tick);
            _timer.Interval = _updateInterval;
            _timer.Start();
        }
 private void TestCalibration_Closed(object sender, EventArgs e)
 {
     if (_timer != null)
     {
         _timer.Stop();
         _timer = null;
     }
     if (_ts != null)
     {
         Telemetry.Unsubscribe(_ts);
         _ts = null;
     }
     if (_ts2 != null)
     {
         Telemetry.Unsubscribe(_ts2);
         _ts2 = null;
     }
 }