示例#1
0
        /// <summary>
        /// Creates or removes <see cref="IIntervalWork"/> from <see cref="IThreadPool"/>.
        /// </summary>
        /// <param name="psc">IPlayerSlotController</param>
        /// <param name="starting"><c>true</c> if starting, <c>false</c> if stopping.</param>
        /// <returns><c>true</c> if work should be removed when done.</returns>
        private bool HandleTasks(IPlayerSlotController psc, bool starting)
        {
            IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>();

            lock (_syncObj)
            {
                // On stop, abort background interval work
                if (!starting && _progressUpdateWorks.ContainsKey(psc))
                {
                    threadPool.RemoveIntervalWork(_progressUpdateWorks[psc].Work);
                    return(true);
                }

                // When starting, create an asynchronous work and exit here
                if (!_progressUpdateWorks.ContainsKey(psc))
                {
                    IntervalWork work = new IntervalWork(() => HandleScrobble(psc, true), UPDATE_INTERVAL);
                    threadPool.AddIntervalWork(work, false);
                    _progressUpdateWorks[psc] = new PositionWatcher {
                        Work = work
                    };
                }
            }
            return(false);
        }
示例#2
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);
        }
示例#3
0
 protected LimitState(PositionWatcher watcher, string symbol, string ordSide, double rejectPrice, bool closeOrder)
     : base(watcher, symbol, ordSide)
 {
     _rejectPrice = rejectPrice;
     _closeOrder  = closeOrder;
     _orders      = new List <string>();
     _sw          = new Stopwatch();
 }
        public PositionWatchingState(PositionWatcher watcher, string symbol, bool isLongPosition, double startWatchPrice, long qty, double stopPrice)
            : this(watcher, symbol)
        {
            _startWatchPrice = startWatchPrice;
            _isLongPosition  = isLongPosition;
            _stopPrice       = stopPrice;
            _qty             = qty;

            _watcher.SendWatcherEvent(() => GetFormatedPrices());
        }
        public PositionWatchingState(PositionWatcher watcher, string symbol)
        {
            _watcher = watcher;
            Action <LimitState, double> initWatching = (state, price) =>
            {
                state.CreateOrder(_qty, price);
                watcher.PositionState = state;
                watcher.StartTimer();
            };

            createBuyState = price =>
            {
                var state = (LimitState) new BuyLimitState(watcher, symbol, _stopPrice, true);
                initWatching(state, price);
            };
            createSellState = price =>
            {
                var state = (LimitState) new SellLimitState(watcher, symbol, _stopPrice, true);
                initWatching(state, price);
            };
            _controller = watcher.Controller;
        }
示例#6
0
 public InitState(PositionWatcher watcher, string instrument)
 {
 }
示例#7
0
    /// <summary>
    /// Creates or removes <see cref="IIntervalWork"/> from <see cref="IThreadPool"/>.
    /// </summary>
    /// <param name="psc">IPlayerSlotController</param>
    /// <param name="starting"><c>true</c> if starting, <c>false</c> if stopping.</param>
    /// <returns><c>true</c> if work should be removed when done.</returns>
    private bool HandleTasks(IPlayerSlotController psc, bool starting)
    {
      IThreadPool threadPool = ServiceRegistration.Get<IThreadPool>();
      lock (_syncObj)
      {
        // On stop, abort background interval work
        if (!starting && _progressUpdateWorks.ContainsKey(psc))
        {
          threadPool.RemoveIntervalWork(_progressUpdateWorks[psc].Work);
          return true;
        }

        // When starting, create an asynchronous work and exit here
        if (!_progressUpdateWorks.ContainsKey(psc))
        {
          IntervalWork work = new IntervalWork(() => HandleScrobble(psc, true), UPDATE_INTERVAL);
          threadPool.AddIntervalWork(work, false);
          _progressUpdateWorks[psc] = new PositionWatcher { Work = work };
        }
      }
      return false;
    }
示例#8
0
 public SellLimitState(PositionWatcher watcher, string symbol, double rejectPrice, bool closeOrder = false)
     : base(watcher, symbol, "Sell", rejectPrice, closeOrder)
 {
 }
示例#9
0
 public BuyMarketState(PositionWatcher watcher, string symbol)
     : base(watcher, symbol)
 {
 }
示例#10
0
 public StopOrderState(PositionWatcher watcher, string symbol, string ordSide)
     : base(watcher, symbol, ordSide)
 {
     _ordSide = ordSide == "Buy" ? "Sell" : "Buy";
 }
示例#11
0
 protected PositionStateBase(PositionWatcher watcher, string symbol, string ordSide)
     : this(watcher, symbol)
 {
     _ordSide = ordSide;
 }
示例#12
0
 protected PositionStateBase(PositionWatcher watcher, string symbol)
 {
     _watcher = watcher;
     _symbol  = symbol;
 }