public void Clear() { _securityData.Clear(); _allOrdersById.Clear(); _allOrdersByStringId.Clear(); _allOrdersByTransactionId.Clear(); _orders.Clear(); _newsById.Clear(); _newsWithoutId.Clear(); _myTrades.Clear(); _trades.Clear(); _tradeStat.Clear(true); _orderStatusTransactions.Clear(); _massCancelationTransactions.Clear(); _exchangeBoards.Clear(); _securities.Clear(); _orderCancelFails.Clear(); _orderRegisterFails.Clear(); _positions.Clear(); }
private void RecycleOrders() { if (OrdersKeepCount == 0) { Orders.Clear(); AllOrdersByTransactionId.Clear(); AllOrdersById.Clear(); AllOrdersByStringId.Clear(); _securityData.SyncDo(d => d.Values.ForEach(v => { v.Orders.Clear(); v.OrdersById.Clear(); v.OrdersByStringId.Clear(); })); return; } var totalCount = Orders.Count; if (OrdersKeepCount == -1 || totalCount < (1.5 * OrdersKeepCount)) { return; } var countToRemove = totalCount - OrdersKeepCount; lock (_securityData.SyncRoot) { var toRemove = Orders.SyncGet(d => { var tmp = d.Where(o => o.State == OrderStates.Done || o.State == OrderStates.Failed).Take(countToRemove).ToHashSet(); d.RemoveRange(tmp); return(tmp); }); MyTrades.SyncDo(d => d.RemoveWhere(t => toRemove.Contains(t.Order))); AllOrdersByTransactionId.SyncDo(d => d.RemoveWhere(t => toRemove.Contains(t.Value))); AllOrdersById.SyncDo(d => d.RemoveWhere(t => toRemove.Contains(t.Value))); AllOrdersByStringId.SyncDo(d => d.RemoveWhere(t => toRemove.Contains(t.Value))); foreach (var pair in _securityData) { pair.Value.Orders.SyncDo(d => d.RemoveWhere(t => toRemove.Contains(t.Value.Order))); pair.Value.MyTrades.SyncDo(d => d.RemoveWhere(t => toRemove.Contains(t.Value.Order))); pair.Value.OrdersById.SyncDo(d => d.RemoveWhere(t => toRemove.Contains(t.Value))); pair.Value.OrdersByStringId.SyncDo(d => d.RemoveWhere(t => toRemove.Contains(t.Value))); } } }
/// <inheritdoc /> protected override bool OnSendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: _infos.Clear(); break; case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (!mdMsg.IsSubscribe) { // NOTE candles can be received during unsubscription process //_infos.Remove(mdMsg.OriginalTransactionId); break; } if (mdMsg.DataType.IsCandleDataType()) { var info = _infos.SafeAdd(mdMsg.TransactionId, k => mdMsg.DataType.ToCandleMessage().CreateInstance <CandleMessage>()); info.SecurityId = mdMsg.SecurityId; info.Arg = mdMsg.Arg; } break; } } return(base.OnSendInMessage(message)); }
private void ChartUpdateTimerOnTick(object sender, EventArgs eventArgs) { if (IsRealtime.IsChecked == true && _lastPrice != 0m) { var step = PriceStep.Value ?? 10; var price = Round(_lastPrice + (decimal)((RandomGen.GetDouble() - 0.5) * 5 * step), (decimal)step); AppendTick(_security, new ExecutionMessage { ServerTime = _lastTime, TradePrice = price, Volume = RandomGen.GetInt(50) + 1 }); _lastTime += TimeSpan.FromSeconds(10); } TimeFrameCandle[] candlesToUpdate; lock (_updatedCandles.SyncRoot) { candlesToUpdate = _updatedCandles.OrderBy(p => p.Key).Select(p => p.Value).ToArray(); _updatedCandles.Clear(); } _allCandles.AddRange(candlesToUpdate); candlesToUpdate.ForEach(c => { Chart.Draw(c.OpenTime, new Dictionary <IChartElement, object> { { _candleElement1, c }, }); }); }
/// <inheritdoc /> protected override void OnSendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: _states.Clear(); break; case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (mdMsg.DataType == MarketDataTypes.MarketDepth) { if (mdMsg.IsSubscribe) { if (IsSupportOrderBookIncrements) { _states.Add(mdMsg.TransactionId, RefTuple.Create(new QuotesDict(new BackwardComparer <decimal>()), new QuotesDict(), _none)); } } else { _states.Remove(mdMsg.OriginalTransactionId); } } break; } } base.OnSendInMessage(message); }
public void Dispose() { if (!_isDisposed) { if (!_shutdown) { Shutdown(true, 0); } if (null != _shuttingDownEvent) { _shuttingDownEvent.Close(); _shuttingDownEvent = null; } _workerThreads.Clear(); if (null != _isIdleWaitHandle) { _isIdleWaitHandle.Close(); _isIdleWaitHandle = null; } _isDisposed = true; } }
private void ChartUpdateTimerOnTick(object sender, EventArgs eventArgs) { if (IsRealtime.IsChecked == true && _lastPrice != 0m) { var nextTick = (ExecutionMessage)_tradeGenerator.Process(new TimeMessage { ServerTime = _lastTime }); if (nextTick != null) { AppendTick(_security, nextTick); } _lastTime += TimeSpan.FromSeconds(10); } Tuple <TimeFrameCandle, bool>[] candlesToUpdate; lock (_updatedCandles.SyncRoot) { candlesToUpdate = _updatedCandles.OrderBy(p => p.Key).Select(p => p.Value).ToArray(); _updatedCandles.Clear(); } var lastCandle = _allCandles.LastOrDefault(); _allCandles.AddRange(candlesToUpdate.Where(c => lastCandle == null || c.Item1.OpenTime != lastCandle.OpenTime).Select(t => t.Item1)); ChartDrawData chartData = null; foreach (var tuple in candlesToUpdate) { var candle = tuple.Item1; var needToFinish = tuple.Item2; if (chartData == null) { chartData = new ChartDrawData(); } if (needToFinish) { candle.State = CandleStates.Finished; } var chartGroup = chartData.Group(candle.OpenTime); lock (candle.PriceLevels) chartGroup.Add(_candleElement, candle); foreach (var pair in _indicators.CachedPairs) { chartGroup.Add(pair.Key, pair.Value.Process(candle)); } } if (chartData != null) { Chart.Draw(chartData); } }
/// <summary> /// Process <see cref="MessageAdapterWrapper.InnerAdapter"/> output message. /// </summary> /// <param name="message">The message.</param> protected override void OnInnerAdapterNewOutMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: _level1DepthBuilders.Clear(); break; case MessageTypes.Level1Change: { var level1Msg = (Level1ChangeMessage)message; // генерация стакана из Level1 var quoteMsg = GetBuilder(level1Msg.SecurityId).Process(level1Msg); if (quoteMsg != null) { RaiseNewOutMessage(quoteMsg); } break; } case MessageTypes.QuoteChange: { var quoteMsg = (QuoteChangeMessage)message; GetBuilder(quoteMsg.SecurityId).HasDepth = true; break; } } base.OnInnerAdapterNewOutMessage(message); }
/// <inheritdoc /> public override void SendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: _depths.Clear(); break; case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (mdMsg.DataType == MarketDataTypes.MarketDepth) { if (mdMsg.IsSubscribe) { if (mdMsg.MaxDepth != null) { _depths[mdMsg.SecurityId] = mdMsg.MaxDepth.Value; } } else { _depths.Remove(mdMsg.SecurityId); } } break; } } base.SendInMessage(message); }
/// <summary> /// To reset the state. /// </summary> private void Reset() { _cancellationTransactions.Clear(); _orderIds.Clear(); _orderStringIds.Clear(); _orderStatusIds.Clear(); }
/// <summary> /// To reset the state. /// </summary> private void Reset() { _orderStatusIds.Clear(); _cancellationTransactions.Clear(); _replaceTransactions.Clear(); _replaceTransactionsByTransId.Clear(); }
public void ClearCache() { _subscribers.Clear(); //_continuousSecurities.Clear(); _registeredFilteredMarketDepths.Clear(); _registeredPortfolios.Clear(); }
/// <inheritdoc /> protected override bool OnSendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: { lock (_sync) { _pending.Clear(); } break; } case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (mdMsg.IsSubscribe) { if (mdMsg.SecurityId == default || mdMsg.DoNotBuildOrderBookInrement || mdMsg.To != null) { break; } if (mdMsg.DataType2 != DataType.MarketDepth && mdMsg.DataType2 != DataType.Level1) { break; } lock (_sync) _pending[mdMsg.TransactionId] = mdMsg.TypedClone(); } else { lock (_sync) _pending.Remove(mdMsg.OriginalTransactionId); } break; } case MessageTypes.OrderStatus: case MessageTypes.PortfolioLookup: { var subscrMsg = (ISubscriptionMessage)message; if (subscrMsg.IsSubscribe && subscrMsg.To == null) { lock (_sync) _pending[subscrMsg.TransactionId] = subscrMsg.TypedClone(); } break; } } return(base.OnSendInMessage(message)); }
protected override bool OnClearing() { GuiDispatcher.GlobalDispatcher.AddAction(() => _parent.InputBindings.Clear()); _keyBindings.Clear(); _mouseActions.Clear(); return(base.OnClearing()); }
/// <inheritdoc /> public override void SendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: { _subscriptions.Clear(); break; } case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (mdMsg.IsSubscribe) { if (!mdMsg.IsBasket()) { break; } if (_securityProvider.LookupById(mdMsg.SecurityId) is BasketSecurity basket) { var processor = _processorProvider.CreateProcessor(basket); var tuple = Tuple.Create(processor, mdMsg.TransactionId); var info = _subscriptions.SafeAdd(mdMsg.DataType); var ids = new long[processor.BasketLegs.Length]; for (var i = 0; i < ids.Length; i++) { ids[i] = TransactionIdGenerator.GetNextId(); info.ByTransactionIds.Add(ids[i], tuple); } foreach (var id in ids) { var clone = (MarketDataMessage)mdMsg.Clone(); clone.TransactionId = id; SendInMessage(clone); } return; } } else { } break; } } base.SendInMessage(message); }
public void ClearAll() { lock (_snapshots.SyncRoot) { _snapshots.Clear(); _dirtyKeys.Clear(); _resetFile = true; } }
/// <summary> /// Создать <see cref="LuaFixServer"/>. /// </summary> public LuaFixServer() { _sessionHolder = new LuaSession(new MillisecondIncrementalIdGenerator()) { Path = SystemProcess.GetCurrentProcess().MainModule.FileName }; var inProcessor = new MessageProcessorPool(new MessageProcessor("Processor 'LuaServer' (In)", err => _logManager.Application.AddErrorLog(err))); var outProcessor = new MessageProcessorPool(new MessageProcessor("Processor 'LuaServer' (Out)", err => _logManager.Application.AddErrorLog(err))); _marketDataAdapter = new LuaMarketDataAdapter(_sessionHolder) { InMessageProcessor = inProcessor, OutMessageProcessor = outProcessor }; _transactionAdapter = new LuaTransactionAdapter(_sessionHolder) { InMessageProcessor = inProcessor, OutMessageProcessor = outProcessor }; _fixServer = new FixServerEx((l, p) => { if (Login.IsEmpty() || (l.CompareIgnoreCase(Login) && p == Password)) { _prevLevel1.Clear(); return(Tuple.Create(TimeSpan.FromMilliseconds(100), FixClientRoles.Admin)); } return(null); }, _transactionAdapter, _marketDataAdapter); _logManager.Application = new QuikNativeApp(); _logManager.Sources.Add(_sessionHolder); _logManager.Sources.Add(_fixServer); LogFile = "StockSharp.QuikLua.log"; var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var logFileName = Path.Combine(path, LogFile); _logManager.Listeners.Add(new FileLogListener(logFileName)); }
/// <summary> /// Clear cache. /// </summary> public override void ClearCache() { base.ClearCache(); _series.Clear(); _historySourceSubscriptions.Clear(); _subscribedCandles.Clear(); IsFinished = false; }
public void Reset(DateTimeOffset from) { lock (_candleValues.SyncRoot) { _firstValueTime = from.UtcTicks; _candleValues.Values.ForEach(_valuesStat.Remove); _candleValues.Clear(); } }
/// <inheritdoc /> protected override bool OnSendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: _depths.Clear(); break; case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (mdMsg.SecurityId == default) { break; } if (mdMsg.DataType2 == DataType.MarketDepth) { if (mdMsg.IsSubscribe) { if (mdMsg.PassThroughOrderBookInrement) { break; } if (mdMsg.MaxDepth != null) { var actualDepth = mdMsg.MaxDepth.Value; var supportedDepth = InnerAdapter.NearestSupportedDepth(actualDepth); if (supportedDepth != actualDepth) { mdMsg = mdMsg.TypedClone(); mdMsg.MaxDepth = supportedDepth; _depths.Add(mdMsg.TransactionId, actualDepth); this.AddInfoLog("MD truncate {0}/{1} ({2}->{3}).", mdMsg.SecurityId, mdMsg.TransactionId, actualDepth, supportedDepth); } } } else { RemoveSubscription(mdMsg.OriginalTransactionId); } } break; } } return(base.OnSendInMessage(message)); }
/// <inheritdoc /> public override void SendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: _states.Clear(); break; } base.SendInMessage(message); }
public void Reset(DateTimeOffset from) { _firstCandleTime = from.UtcTicks; _byTime.Clear(); lock (_allCandles.SyncRoot) { _candleStat.Remove(_allCandles); _allCandles.Clear(); } }
public void CompareTest() { const int size = 1000000; int reps = 3; Stopwatch timer; IDictionary <Guid, TestValue> dict = new SynchronizedDictionary <Guid, TestValue>(new Dictionary <Guid, TestValue>(size)); IDictionary <Guid, TestValue> test = new LurchTable <Guid, TestValue>(size); for (int rep = 0; rep < reps; rep++) { var sample = CreateSample(Guid.NewGuid(), size, 1); timer = Stopwatch.StartNew(); Parallel(1, sample, item => dict.Add(item, new TestValue { Id = item, Count = rep })); Trace.TraceInformation("Dict Add: {0}", timer.Elapsed); timer = Stopwatch.StartNew(); Parallel(1, sample, item => test.Add(item, new TestValue { Id = item, Count = rep })); Trace.TraceInformation("Test Add: {0}", timer.Elapsed); timer = Stopwatch.StartNew(); Parallel(1, sample, item => dict[item] = new TestValue { Id = item, Count = rep }); Trace.TraceInformation("Dict Update: {0}", timer.Elapsed); timer = Stopwatch.StartNew(); Parallel(1, sample, item => test[item] = new TestValue { Id = item, Count = rep }); Trace.TraceInformation("Test Update: {0}", timer.Elapsed); timer = Stopwatch.StartNew(); Parallel(1, sample, item => dict.Remove(item)); Trace.TraceInformation("Dict Rem: {0}", timer.Elapsed); Assert.AreEqual(0, dict.Count); timer = Stopwatch.StartNew(); Parallel(1, sample, item => test.Remove(item)); Trace.TraceInformation("Test Rem: {0}", timer.Elapsed); test.Clear(); dict.Clear(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
/// <summary> /// Clears the caches for Responses and Redirects if they were enabled. /// </summary> public virtual void FlushCache() { if (Responses) { Responses.Clear(); } if (Redirects) { Redirects.Clear(); } }
private void ProcessReset(Message message) { _hearbeatAdapters.Values.ForEach(a => { a.SendInMessage(message); a.Dispose(); }); _connectedAdapters.Clear(); _hearbeatAdapters.Clear(); _subscriptionQueue.Clear(); _subscriptions.Clear(); }
private void Reset() { _transactionLogSubscriptions.Clear(); _orders.Clear(); _secIds.Clear(); _nonAssociatedByIdMyTrades.Clear(); _nonAssociatedByStringIdMyTrades.Clear(); _nonAssociatedByTransactionIdMyTrades.Clear(); _nonAssociatedOrderIds.Clear(); _nonAssociatedStringOrderIds.Clear(); }
/// <inheritdoc /> protected override void OnSendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: _subscriptionIds.Clear(); break; case MessageTypes.MarketData: message = ProcessMarketDataRequest((MarketDataMessage)message); break; } base.OnSendInMessage(message); }
/// <summary> /// Send message. /// </summary> /// <param name="message">Message.</param> public override void SendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: _filteredMarketDepths.Clear(); break; case MessageTypes.MarketData: { var mdMsg = (MarketDataMessage)message; if (mdMsg.DataType != FilteredMarketDepth) { break; } if (mdMsg.IsSubscribe) { var clone = (MarketDataMessage)mdMsg.Clone(); clone.DataType = MarketDataTypes.MarketDepth; clone.Arg = null; base.SendInMessage(clone); var data = (Tuple <QuoteChangeMessage, ExecutionMessage[]>)mdMsg.Arg; var info = _filteredMarketDepths.SafeAdd(mdMsg.SecurityId, s => new FilteredMarketDepthInfo(data.Item2)); var quoteMsg = info.Process(data.Item1); RaiseNewOutMessage(quoteMsg); } else { var clone = (MarketDataMessage)mdMsg.Clone(); clone.DataType = MarketDataTypes.MarketDepth; base.SendInMessage(clone); _filteredMarketDepths.Remove(mdMsg.SecurityId); } return; } } base.SendInMessage(message); }
public void Clear() { _securityData.Clear(); AllOrdersById.Clear(); AllOrdersByStringId.Clear(); AllOrdersByTransactionId.Clear(); Orders.Clear(); NewsById.Clear(); NewsWithoutId.Clear(); MyTrades.Clear(); _trades.Clear(); _tradeStat.Clear(); }
private void Reset() { _transactionLogSubscriptions.Clear(); _orderStatusIds.Clear(); _orders.Clear(); _secIds.Clear(); _orderIds.Clear(); _orderStringIds.Clear(); lock (_nonAssociatedLock) { _nonAssociatedOrderIds.Clear(); _nonAssociatedStringOrderIds.Clear(); } }
public void SynchronizedDictionaryUnitTest() { SynchronizedDictionary<int, string> dictionary = new SynchronizedDictionary<int, string>(); dictionary.Add(1, "one"); dictionary.Add(2, "two"); Assert.IsTrue(dictionary.Count == 2); foreach (KeyValuePair<int, string> keyValuePair in dictionary) { Assert.IsTrue(dictionary.ContainsKey(keyValuePair.Key)); Assert.IsTrue(dictionary.ContainsValue(keyValuePair.Value)); } dictionary.Remove(1); Assert.IsTrue(dictionary.Count == 1); dictionary.Clear(); Assert.IsTrue(dictionary.Count == 0); }