/// <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)); } }
/// <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)); } }
//pmh MbtHist events #################################################################################### public void m_HistMgr_OnDataEvent(int lRequestId, object pHist, enumHistEventType evt) { debug(String.Format("m_HistMgr_OnDataEvent lRequestId: {0}, evt: {1}", lRequestId, evt)); Bar b; int date, time; long vol; decimal open, high, low, close; string symbol; // Notice we are using lRequestId in the original SendRequest()s to indicate whether we're // dealing with a Day, Min or Tick bar object. Process accordingly. BarRequest br; int MbtCustInt; //pmh ?!? debug("Unknown barrequest handle: "); if (!_barhandle2barrequest.TryGetValue(lRequestId, out br)) { debug("Unknown barrequest handle, lRequestId: " + lRequestId); return; } int lRequestType = lRequestId % 10; switch (lRequestType) { case 1: //pmh ?!? - debug("number of client"); MbtHistDayBar barDay = pHist as MbtHistDayBar; debug("Day bar, " + barDay.Count + " recs"); barDay.Last(); while (!barDay.Bof) { debug("number of client"); //pmh ?!? symbol = barDay.Symbol; //pmh - 10/4/12 - was absent, but not sure if needed open = Convert.ToDecimal(barDay.Open, System.Globalization.CultureInfo.InvariantCulture); high = Convert.ToDecimal(barDay.High, System.Globalization.CultureInfo.InvariantCulture); low = Convert.ToDecimal(barDay.Low, System.Globalization.CultureInfo.InvariantCulture); close = Convert.ToDecimal(barDay.Close, System.Globalization.CultureInfo.InvariantCulture); vol = Convert.ToInt64(barDay.TotalVolume, System.Globalization.CultureInfo.InvariantCulture); date = Util.ToTLDate(barDay.CloseDate); time = 0; MbtCustInt = MbtDayInt2CustInt((int)br.Interval / 100); b = new BarImpl(open, high, low, close, vol, date, time, barDay.Symbol, MbtCustInt); debug("number of client" + tl.NumClients); debug("bar" + BarImpl.Serialize(b)); tl.TLSend(BarImpl.Serialize(b), MessageTypes.BARRESPONSE, br.Client); barDay.Previous(); } //use this message to inform that the data for requestID is completed tl.TLSend(Convert.ToString(lRequestId), MessageTypes.CUSTOM40, br.Client); break; case 2: MbtHistMinBar barMin = pHist as MbtHistMinBar; debug("Min bar, " + barMin.Count + " recs"); barMin.Last(); while (!barMin.Bof) { symbol = barMin.Symbol; //pmh - 10/4/12 - was absent, but not sure if needed open = Convert.ToDecimal(barMin.Open, System.Globalization.CultureInfo.InvariantCulture); high = Convert.ToDecimal(barMin.High, System.Globalization.CultureInfo.InvariantCulture); low = Convert.ToDecimal(barMin.Low, System.Globalization.CultureInfo.InvariantCulture); close = Convert.ToDecimal(barMin.Close, System.Globalization.CultureInfo.InvariantCulture); vol = Convert.ToInt64(barMin.TotalVolume, System.Globalization.CultureInfo.InvariantCulture); date = Util.ToTLDate(barMin.LocalDateTime); time = Util.ToTLTime(barMin.LocalDateTime); MbtCustInt = MbtMinInt2CustInt((int)br.Interval / 100); b = new BarImpl(open, high, low, close, vol, date, time, barMin.Symbol, MbtCustInt); tl.TLSend(BarImpl.Serialize(b), MessageTypes.BARRESPONSE, br.Client); barMin.Previous(); } //use this message to inform that the data for requestID is completed tl.TLSend(Convert.ToString(lRequestId), MessageTypes.CUSTOM40, br.Client); break; case 3: /* pmh * 0 = All ticks * 1 = Trade ticks * 2 = Bid/Ask ticks * 3 = Bid ticks * 4 = Ask ticks */ MbtHistTick barTick = pHist as MbtHistTick; debug("Tick bar, " + barTick.Count + " recs (showing only 1 - Trade ticks)"); TickImpl k = new TickImpl(barTick.Symbol); //MBT default tick data is trade data int lTickFilter = 1; barTick.First(); switch (lTickFilter) { case 1: while (!barTick.Bof) { k.symbol = barTick.Symbol; //pmh - 10/4/12 - was absent, but not sure if needed k.trade = Convert.ToDecimal(barTick.Price); k.ex = barTick.Exchange; k.size = barTick.Volume; k.date = Util.ToTLDate(barTick.LocalDateTime); k.time = Util.ToTLTime(barTick.LocalDateTime); SendNewTick(k); barTick.Previous(); }; break; } break; case 4: //pmh - 9/15/12 - PV bars MbtHistPVBar barPV = pHist as MbtHistPVBar; debug("PV bar, " + barPV.Count + " recs"); barPV.Last(); while (!barPV.Bof) { open = high = low = 0; symbol = barPV.Symbol; //pmh - 10/4/12 - was absent, but not sure if needed close = Convert.ToDecimal(barPV.Price, System.Globalization.CultureInfo.InvariantCulture); vol = Convert.ToInt64(barPV.Volume, System.Globalization.CultureInfo.InvariantCulture); date = Util.ToTLDate(barPV.LocalDateTime); time = Util.ToTLTime(barPV.LocalDateTime); MbtCustInt = MbtMinInt2CustInt((int)br.Interval / 100); b = new BarImpl(open, high, low, close, vol, date, time, barPV.Symbol, MbtCustInt); tl.TLSend(BarImpl.Serialize(b), MessageTypes.BARRESPONSE, br.Client); barPV.Previous(); } //use this message to inform that the data for requestID is completed tl.TLSend(Convert.ToString(lRequestId), MessageTypes.CUSTOM40, br.Client); break; } if (_barrequests.hasItems) { // BarRequest br1= new BarRequest(); try { br = _barrequests.Read(); submitBarRequest(br); } catch (Exception ex) { debug("error on historical bar request: " + br.ToString()); debug(ex.Message + ex.StackTrace); } } else waitforhistorical2complete = false; }
public void m_Hist_OnDataEvent(int lRequestId, object pHist, enumHistEventType evt) { debug("Processing Id: " + lRequestId + " evt: " + evt); Bar b; int date, time; long vol; decimal open, high, low, close; string symbol; // Notice we are using lRequestId in the original SendRequest()s to indicate whether we're // dealing with a Day, Min or Tick bar object. Process accordingly. BarRequest br; int MbtCustInt; debug("Unknown barrequest handle: "); if (!_barhandle2barrequest.TryGetValue(lRequestId, out br)) { debug("Unknown barrequest handle: " + lRequestId); return; } int lRequestType = lRequestId % 10; switch (lRequestType) { case 1: debug("number of client"); MbtHistDayBar mhd = pHist as MbtHistDayBar; mhd.Last(); while (!mhd.Bof) { debug("number of client"); open = Convert.ToDecimal(mhd.Open, System.Globalization.CultureInfo.InvariantCulture); high = Convert.ToDecimal(mhd.High, System.Globalization.CultureInfo.InvariantCulture); low = Convert.ToDecimal(mhd.Low, System.Globalization.CultureInfo.InvariantCulture); close = Convert.ToDecimal(mhd.Close, System.Globalization.CultureInfo.InvariantCulture); vol = Convert.ToInt64(mhd.TotalVolume, System.Globalization.CultureInfo.InvariantCulture); date = Util.ToTLDate(mhd.CloseDate); time = 0; MbtCustInt = MbtDayInt2CustInt((int)br.Interval / 100); b = new BarImpl(open, high, low, close, vol, date, time, mhd.Symbol, MbtCustInt); debug("number of client" + tl.NumClients); debug("bar" + BarImpl.Serialize(b)); tl.TLSend(BarImpl.Serialize(b), MessageTypes.BARRESPONSE, br.Client); mhd.Previous(); } //use this mesage to inform that the data for requestID is compeleted tl.TLSend(Convert.ToString(lRequestId), MessageTypes.CUSTOM40, br.Client); break; case 2: MbtHistMinBar mhm = pHist as MbtHistMinBar; mhm.Last(); while (!mhm.Bof) { open = Convert.ToDecimal(mhm.Open, System.Globalization.CultureInfo.InvariantCulture); high = Convert.ToDecimal(mhm.High, System.Globalization.CultureInfo.InvariantCulture); low = Convert.ToDecimal(mhm.Low, System.Globalization.CultureInfo.InvariantCulture); close = Convert.ToDecimal(mhm.Close, System.Globalization.CultureInfo.InvariantCulture); vol = Convert.ToInt64(mhm.TotalVolume, System.Globalization.CultureInfo.InvariantCulture); date = Util.ToTLDate(mhm.LocalDateTime); time = Util.ToTLTime(mhm.LocalDateTime); MbtCustInt = MbtMinInt2CustInt((int)br.Interval / 100); b = new BarImpl(open, high, low, close, vol, date, time, mhm.Symbol, MbtCustInt); tl.TLSend(BarImpl.Serialize(b), MessageTypes.BARRESPONSE, br.Client); mhm.Previous(); } //use this mesage to inform that the data for requestID is compeleted tl.TLSend(Convert.ToString(lRequestId), MessageTypes.CUSTOM40, br.Client); break; case 3: MbtHistTick mht = pHist as MbtHistTick; TickImpl k = new TickImpl(mht.Symbol); //MBT default tick data is trade data int lTickFilter = 1; mht.First(); switch (lTickFilter) { case 1: while (!mht.Bof) { k.trade = Convert.ToDecimal(mht.Price); k.ex = mht.Exchange; k.size = mht.Volume; k.date = Util.ToTLDate(mht.LocalDateTime); k.time = Util.ToTLTime(mht.LocalDateTime); SendNewTick(k); mht.Previous(); } ; break; } break; } if (_barrequests.hasItems) { // BarRequest br1= new BarRequest(); try { br = _barrequests.Read(); submitBarRequest(br); } catch (Exception ex) { debug("error on historical bar request: " + br.ToString()); debug(ex.Message + ex.StackTrace); } } else waitforhistorical2complete = false; }