/// <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); }
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); }
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; }
public InitState(PositionWatcher watcher, string instrument) { }
/// <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; }
public SellLimitState(PositionWatcher watcher, string symbol, double rejectPrice, bool closeOrder = false) : base(watcher, symbol, "Sell", rejectPrice, closeOrder) { }
public BuyMarketState(PositionWatcher watcher, string symbol) : base(watcher, symbol) { }
public StopOrderState(PositionWatcher watcher, string symbol, string ordSide) : base(watcher, symbol, ordSide) { _ordSide = ordSide == "Buy" ? "Sell" : "Buy"; }
protected PositionStateBase(PositionWatcher watcher, string symbol, string ordSide) : this(watcher, symbol) { _ordSide = ordSide; }
protected PositionStateBase(PositionWatcher watcher, string symbol) { _watcher = watcher; _symbol = symbol; }