/// <summary> /// /// </summary> void _historyClient_OnDataEvent(int lRequestId, object pHist, enumHistEventType evt) { List <DataBar> extractedBars = new List <DataBar>(); if (pHist is MbtHistDayBar) { MbtHistDayBar bars = (MbtHistDayBar)pHist; bars.First(); while (bars.Eof == false) { decimal open = (decimal)bars.Open; decimal close = (decimal)bars.Close; decimal high = (decimal)bars.High; decimal low = (decimal)bars.Low; extractedBars.Insert(0, new DataBar(bars.CloseDate, open, high, low, close, bars.TotalVolume)); bars.Next(); } } else if (pHist is MbtHistMinBar) { MbtHistMinBar bars = (MbtHistMinBar)pHist; bars.First(); while (bars.Eof == false) { decimal open = (decimal)bars.Open; decimal close = (decimal)bars.Close; decimal high = (decimal)bars.High; decimal low = (decimal)bars.Low; extractedBars.Insert(0, new DataBar(bars.UTCDateTime, open, high, low, close, bars.TotalVolume)); bars.Next(); } } DataHistoryOperation operation = (DataHistoryOperation)_operationStub.GetOperationById(lRequestId.ToString()); if (operation != null) { _operationStub.CompleteOperation(lRequestId.ToString(), new DataHistoryUpdate(operation.Request.Period, extractedBars)); } }
public bool StartOperation(OperationInformation operationInformation) { DataHistoryOperation operation = (DataHistoryOperation)operationInformation; bool result = true; _messageLoopOperator.Invoke(delegate() {// Placing the request on the stolen main application thread, since we need the requestMessage pump for this to work properly. MbtHistMgr historyClient = _historyClient; if (historyClient == null) { result = false; return; } if (operation.Request.IsMinuteBased == false && operation.Request.IsDayBased == false) { result = false; return; } int?time = GetConvertedTime(operation); if (operation.Request.IsDayBased) { MbtHistDayBar histBar; histBar = historyClient.CreateHistDayBar(); histBar.Clear(); histBar.SendRequest(operation.Symbol, Int32.Parse(operation.Id), time.Value, new DateTime(0), new DateTime(0), operation.Request.MaxValuesRetrieved.HasValue ? operation.Request.MaxValuesRetrieved.Value : int.MaxValue, true); } else if (operation.Request.IsMinuteBased) { MbtHistMinBar histBar = historyClient.CreateHistMinBar(); histBar.Clear(); histBar.SendRequest(operation.Symbol, Int32.Parse(operation.Id), time.Value, new DateTime(0), new DateTime(0), operation.Request.MaxValuesRetrieved.HasValue ? operation.Request.MaxValuesRetrieved.Value : int.MaxValue, true); } }); return(result); }