예제 #1
0
        public void InitPositionWatcher(BitmexUser account, Dictionary <string, ICryptoIntrument> instruments)
        {
            _priceMultiplier = PriceMultiplier;
            _instrument      = Instrument;
            _instrumentObj   = (InstrumentBaseType)instruments[_instrument];
            _posWatcher      = new PositionWatcher(_instrument, MainWnd.Controller, MainWindow.Error);

            var ex = MainWnd.Controller.Exchange;

            ex.PositionChanged += _posWatcher.OnPositionChanged;
            ex.OrderChanged    += _posWatcher.OnOrderChanged;

            this.PositionSizeChanged += (s, e) =>
            {
                MainWindow.HandleException(() => _posWatcher.OnPositionSizeChanged(e.PositionSize));
            };
            _posWatcher.WatcherChanged += (s, e) =>
            {
                ChangeControl(() => LogWatcherEvent(e.Message));
            };
            _posWatcher.StateChanged += (s, e) => ChangeControl(() =>
            {
                lblState.Content             = e.Message;
                var state                    = e.Message == "BuyLimit" || e.Message == "SellLimit";
                btnCancelWatching.Visibility = state ? Visibility.Visible : Visibility.Hidden;
            });
            MainWnd.PriceChangedSubscription(true, _instrument);
            _posWatcher.Init(account);
        }