/// <summary> /// To remove the strategy from the store. /// </summary> /// <param name="strategy">The strategy data.</param> public void DeleteStrategy(StrategyData strategy) { if (strategy == null) { throw new ArgumentNullException(nameof(strategy)); } ValidateError(Invoke(f => f.DeleteStrategy(SessionId, strategy.Id)), strategy.Id); _strategies.Remove(strategy.Id); StrategyDeleted?.Invoke(strategy); }
/// <inheritdoc /> public void UnSubscribe(StrategySubscription subscription) { if (subscription == null) { throw new ArgumentNullException(nameof(subscription)); } ValidateError(Invoke(f => f.UnSubscribe(SessionId, subscription.Id))); StrategyUnSubscribed?.Invoke(subscription); _subscriptions.Remove(subscription.Id); }
/// <summary> /// Remove security. /// </summary> /// <param name="portfolio">Portfolio.</param> /// <returns>Check result.</returns> public bool Remove(Portfolio portfolio) { if (portfolio is null) { throw new ArgumentNullException(nameof(portfolio)); } if (!_inner.Remove(portfolio.Name)) { return(false); } PortfolioChanged?.Invoke(portfolio); return(true); }
/// <inheritdoc /> public bool RemoveAssociation(string key) { if (key.IsEmpty()) { throw new ArgumentNullException(nameof(key)); } if (!_adapters.Remove(key)) { return(false); } Changed?.Invoke(key, Guid.Empty, false); return(true); }
/// <inheritdoc /> public virtual bool RemoveAssociation(string portfolioName) { if (portfolioName.IsEmpty()) { throw new ArgumentNullException(nameof(portfolioName)); } if (!_adapters.Remove(portfolioName)) { return(false); } Changed?.Invoke(); return(true); }
/// <summary> /// Delete storage. /// </summary> /// <param name="drive">Market data storage.</param> public void DeleteDrive(IMarketDataDrive drive) { if (drive == null) { throw new ArgumentNullException(nameof(drive)); } if (drive == DefaultDrive) { throw new ArgumentException(nameof(drive)); } if (_drives.Remove(CreatePair(drive.Path))) { DriveDeleted?.Invoke(drive); } }
private void Refresh() { var ids = Invoke(f => f.GetStrategies(_lastCheckTime)).ToArray(); foreach (var tuple in ids.Where(t => t.Item2 < 0)) { var strategy = _strategies.TryGetValue(tuple.Item1); if (strategy != null) { StrategyDeleted?.Invoke(strategy); } } var newIds = new List <long>(); var updatedIds = new List <long>(); foreach (var tuple in ids.Where(t => t.Item2 >= 0)) { var strategy = _strategies.TryGetValue(tuple.Item1); if (strategy != null) { updatedIds.Add(tuple.Item1); } else { newIds.Add(tuple.Item1); } } var newStrategies = Invoke(f => f.GetDescription(newIds.ToArray())); foreach (var newStrategy in newStrategies) { _strategies.Add(newStrategy.Id, newStrategy); StrategyCreated?.Invoke(newStrategy); } var updatedStrategies = Invoke(f => f.GetDescription(updatedIds.ToArray())); foreach (var updatedStrategy in updatedStrategies) { var strategy = _strategies[updatedStrategy.Id]; CopyTo(updatedStrategy, strategy); StrategyUpdated?.Invoke(strategy); } _lastCheckTime = DateTime.Now; foreach (var backtest in _backtests.CachedValues) { if (_backtestResults.ContainsKey(backtest)) { continue; } var resultId = Invoke(f => f.GetBacktestResult(SessionId, backtest.Id)); if (resultId == null) { continue; } _backtestResults.Add(backtest, resultId.Value); BacktestStopped?.Invoke(backtest); _startedBacktests.Remove(backtest); } foreach (var backtest in _startedBacktests.CachedKeys) { var count = Invoke(f => f.GetCompletedIterationCount(SessionId, backtest.Id)); var prevCount = _startedBacktests[backtest]; if (count == prevCount) { continue; } BacktestProgressChanged?.Invoke(backtest, count); if (count == backtest.Iterations.Length) { _startedBacktests.Remove(backtest); } else { _startedBacktests[backtest] = count; } } }
/// <inheritdoc /> public virtual bool RemoveAssociation(string portfolioName) { return(_adapters.Remove(portfolioName)); }
/// <inheritdoc /> public void Delete(Position position) { _positions.Remove(CreateKey(position)); }
void IChatServiceCallback.RoomDeleted(long roomId) { _rooms.Remove(roomId); _eventDispatcher.Add(() => RoomDeleted.SafeInvoke(GetRoom(roomId))); }
private void ProcessMarketDataMessage(MarketDataMessage message) { var generatorMessage = message as GeneratorMarketDataMessage; if (generatorMessage != null) { if (generatorMessage.Generator == null) { throw new ArgumentException("message"); } var tradeGen = generatorMessage.Generator as TradeGenerator; if (tradeGen != null) { if (generatorMessage.IsSubscribe) { _tradeGenerators.Add(generatorMessage.SecurityId, tradeGen); } else { _tradeGenerators.Remove(generatorMessage.SecurityId); } } else { var depthGen = generatorMessage.Generator as MarketDepthGenerator; if (depthGen != null) { if (generatorMessage.IsSubscribe) { _depthGenerators.Add(generatorMessage.SecurityId, depthGen); } else { _depthGenerators.Remove(generatorMessage.SecurityId); } } else { var olGen = generatorMessage.Generator as OrderLogGenerator; if (olGen != null) { if (generatorMessage.IsSubscribe) { _orderLogGenerators.Add(generatorMessage.SecurityId, olGen); } else { _orderLogGenerators.Remove(generatorMessage.SecurityId); } } else { throw new InvalidOperationException(); } } } return; } var security = SecurityProvider.LookupById(message.SecurityId.SecurityCode + "@" + message.SecurityId.BoardCode); if (security == null) { RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str704Params.Put(message.SecurityId))); return; } if (TryGetGenerator(message) != null) { RaiseMarketDataMessage(message, null); return; } if (StorageRegistry == null) { RaiseMarketDataMessage(message, new InvalidOperationException(LocalizedStrings.Str1117Params.Put(message.DataType, message.SecurityId))); return; } Exception error = null; switch (message.DataType) { case MarketDataTypes.Level1: { if (message.IsSubscribe) { BasketStorage.InnerStorages.Add(StorageRegistry.GetLevel1MessageStorage(security, Drive, StorageFormat)); BasketStorage.InnerStorages.Add(new InMemoryMarketDataStorage <ClearingMessage>(date => new[] { new ClearingMessage { LocalTime = date.Date + security.Board.ExpiryTime, SecurityId = message.SecurityId, ClearMarketDepth = true } })); } else { RemoveStorage <IMarketDataStorage <Level1ChangeMessage> >(security, MessageTypes.Level1Change, message.Arg); RemoveStorage <InMemoryMarketDataStorage <ClearingMessage> >(security, ExtendedMessageTypes.Clearing, message.Arg); } break; } case MarketDataTypes.MarketDepth: { if (message.IsSubscribe) { BasketStorage.InnerStorages.Add((IMarketDataStorage <QuoteChangeMessage>)StorageRegistry.GetMarketDepthStorage(security, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <QuoteChangeMessage> >(security, MessageTypes.QuoteChange, message.Arg); } break; } case MarketDataTypes.Trades: { if (message.IsSubscribe) { BasketStorage.InnerStorages.Add((IMarketDataStorage <ExecutionMessage>)StorageRegistry.GetTradeStorage(security, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <ExecutionMessage> >(security, MessageTypes.Execution, message.Arg); } break; } case MarketDataTypes.OrderLog: { if (message.IsSubscribe) { BasketStorage.InnerStorages.Add((IMarketDataStorage <ExecutionMessage>)StorageRegistry.GetOrderLogStorage(security, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <ExecutionMessage> >(security, MessageTypes.Execution, message.Arg); } break; } case MarketDataTypes.CandleTimeFrame: case MarketDataTypes.CandleTick: case MarketDataTypes.CandleVolume: case MarketDataTypes.CandleRange: case MarketDataTypes.CandlePnF: case MarketDataTypes.CandleRenko: { Type candleMessageType; MessageTypes msgType; switch (message.DataType) { case MarketDataTypes.CandleTimeFrame: msgType = MessageTypes.CandleTimeFrame; candleMessageType = typeof(TimeFrameCandleMessage); break; case MarketDataTypes.CandleTick: msgType = MessageTypes.CandleTick; candleMessageType = typeof(TickCandleMessage); break; case MarketDataTypes.CandleVolume: msgType = MessageTypes.CandleVolume; candleMessageType = typeof(VolumeCandleMessage); break; case MarketDataTypes.CandleRange: msgType = MessageTypes.CandleRange; candleMessageType = typeof(RangeCandleMessage); break; case MarketDataTypes.CandlePnF: msgType = MessageTypes.CandlePnF; candleMessageType = typeof(PnFCandleMessage); break; case MarketDataTypes.CandleRenko: msgType = MessageTypes.CandleRenko; candleMessageType = typeof(RenkoCandleMessage); break; default: throw new InvalidOperationException(); } if (message.IsSubscribe) { BasketStorage.InnerStorages.Add(StorageRegistry.GetCandleMessageStorage(candleMessageType, security, message.Arg, Drive, StorageFormat)); } else { RemoveStorage <IMarketDataStorage <CandleMessage> >(security, msgType, message.Arg); } break; } default: error = new InvalidOperationException(LocalizedStrings.Str1118Params.Put(message.DataType)); break; } RaiseMarketDataMessage(message, error); }
private void ProcessMarketData(MarketDataMessage mdMsg) { switch (mdMsg.DataType) { case MarketDataTypes.Level1: { //if (mdMsg.IsSubscribe) // _subscribedLevel1.Add(secCode); //else // _subscribedLevel1.Remove(secCode); break; } case MarketDataTypes.MarketDepth: { if (mdMsg.IsSubscribe) { _subscribedDepths.Add(mdMsg.SecurityId, mdMsg.MaxDepth); if (_subscribedDepths.Count == 1) { _pusherClient.SubscribeDepths(); } } else { _subscribedDepths.Remove(mdMsg.SecurityId); if (_subscribedDepths.Count == 0) { _pusherClient.UnSubscribeDepths(); } } break; } case MarketDataTypes.Trades: { if (mdMsg.IsSubscribe) { if (mdMsg.From == DateTime.Today) { _httpClient.RequestTransactions().Select(t => new ExecutionMessage { ExecutionType = ExecutionTypes.Tick, SecurityId = _btcUsd, TradeId = t.Id, TradePrice = (decimal)t.Price, Volume = (decimal)t.Amount, ServerTime = t.Time.ApplyTimeZone(TimeZoneInfo.Utc) }).ForEach(SendOutMessage); } _subscribedTicks.Add(mdMsg.SecurityId); if (_subscribedTicks.Count == 1) { _pusherClient.SubscribeTrades(); } } else { _subscribedTicks.Remove(mdMsg.SecurityId); if (_subscribedTicks.Count == 0) { _pusherClient.UnSubscribeTrades(); } } break; } default: { SendOutMarketDataNotSupported(mdMsg.TransactionId); return; } } var reply = (MarketDataMessage)mdMsg.Clone(); reply.OriginalTransactionId = mdMsg.OriginalTransactionId; SendOutMessage(reply); }