/// <summary> /// OperationId is not mandatory - but is should be there when the update was requested by a special recepient. /// </summary> public void TradingValuesUpdate(string symbol, int operationId, double time, int period, int availableBarsCount, Int64[] times, decimal[] opens, decimal[] closes, decimal[] highs, decimal[] lows, decimal[] volumes) { TracerHelper.TraceEntry(); CombinedDataSubscriptionInformation session = GetDataSession(symbol); if (session == null) { SystemMonitor.Error("Failed to find symbol session [" + symbol + "], quotes not sent."); return; } try { // History update. TimeSpan periodValue = TimeSpan.FromMinutes(period); DataHistoryUpdate update = new DataHistoryUpdate(periodValue, GenerateDataBars(periodValue, times, opens, closes, highs, lows, volumes)); update.AvailableHistorySize = availableBarsCount; DataHistoryUpdateMessage message = new DataHistoryUpdateMessage(session.SessionInformation.Info, update, true); SendToDataSubscribers(session, null, message); } catch (Exception ex) {// Make sure we handle any possible unexpected exceptions, as otherwise they bring the // entire package (MT4 included) down with a bad error. SystemMonitor.Error(ex.Message); } TracerHelper.TraceExit(); }
public void UpdateDataHistory(DataSessionInfo session, DataHistoryUpdate update) { if (OperationalState != OperationalStateEnum.Operational) { SystemMonitor.Warning("Stub used while not operational, operation ignored."); return; } DataHistoryUpdateMessage message = new DataHistoryUpdateMessage(session, update, true); CombinedDataSubscriptionInformation combined; lock (this) { combined = GetUnsafeSessionSubscriptions(session); } lock (combined) { foreach (KeyValuePair <TransportInfo, DataSubscriptionInfo> info in combined.SubscriptionsUnsafe.Values) { if (info.Value.AcceptsUpdate(update)) { SendResponding(info.Key, message); } } } }
void SendDataHistoryUpdate(TransportInfo[] receivers, DataSessionInfo session, DataHistoryRequest request) { DataSourceStub.IImplementation implementation = Implementation; if (implementation == null) { return; } DataHistoryUpdate responce = implementation.GetDataHistoryUpdate(session, request); SendRespondingToMany(receivers, new DataHistoryUpdateMessage(session, responce, responce != null)); }
/// <summary> /// /// </summary> public DataHistoryUpdateMessage(DataSessionInfo session, DataHistoryUpdate update, bool operationResult) : base(session, operationResult) { _update = update; }
/// <summary> /// Request bar dataDelivery from entry. /// </summary> public bool RequestDataHistoryUpdate(DataSessionInfo sessionInfo, DataHistoryRequest request, bool waitResult) { DataStoreEntry entry = DataStore.Instance.GetEntryBySessionInfo(sessionInfo); if (this.OperationalState != OperationalStateEnum.Operational || entry == null) { SystemMonitor.OperationError("Data history request received while not operational, or invalid session requrested."); return(false); } if (entry.Period != request.Period) { SystemMonitor.OperationError("Data history request received but period not recognized."); return(false); } if (request.MaxValuesRetrieved.HasValue == false) { request.MaxValuesRetrieved = int.MaxValue; } if (request.StartIndex.HasValue == false) { request.StartIndex = -1; } GeneralHelper.GenericReturnDelegate <bool> operationDelegate = delegate() { if (request.IsTickBased) { DataReaderWriter <DataTick> readerWriter = entry.GetDataTickReaderWriter(); List <DataTick> dataTicks; DataHistoryUpdate update = new DataHistoryUpdate(request.Period, new DataTick[] { }); if (readerWriter.Read(request.StartIndex.Value, request.MaxValuesRetrieved.Value, out dataTicks)) { update.DataTicksUnsafe.AddRange(dataTicks); if (DataHistoryUpdateEvent != null) { DataHistoryUpdateEvent(this, sessionInfo, update); } return(true); } } else { DataReaderWriter <DataBar> readerWriter = entry.GetDataBarReaderWriter(); if (readerWriter == null) { SystemMonitor.OperationError("Failed to establish file reader writer for entry."); return(false); } List <DataBar> dataBars; DataHistoryUpdate update = new DataHistoryUpdate(request.Period, new DataBar[] { }); bool readResult = false; if (request.StartIndex.Value < 0) {// Instruction is to read the last count items. readResult = readerWriter.ReadLast( request.MaxValuesRetrieved.Value, out dataBars); } else { readResult = readerWriter.Read(request.StartIndex.Value, request.MaxValuesRetrieved.Value, out dataBars); } if (readResult) { update.DataBarsUnsafe.AddRange(dataBars); if (DataHistoryUpdateEvent != null) { DataHistoryUpdateEvent(this, sessionInfo, update); } return(true); } } return(false); }; if (waitResult) { return(operationDelegate()); } else { GeneralHelper.FireAndForget(operationDelegate); return(true); } }