private void SessionOnInstrumentDomChanged(CQGInstrument cqgInstrument, CQGDOMQuotes prevAsks, CQGDOMQuotes prevBids) { SendOutMessage(new QuoteChangeMessage { SecurityId = new SecurityId { SecurityCode = cqgInstrument.Commodity, BoardCode = cqgInstrument.ExchangeAbbreviation, }, ServerTime = cqgInstrument.ServerTimestamp.ApplyTimeZone(TimeHelper.Est), Bids = cqgInstrument.DOMBids .Cast <CQGQuote>() .Where(q => q.IsValid) .Select(q => new QuoteChange(Sides.Buy, (decimal)q.Price, q.HasVolume ? q.Volume : 0)), Asks = cqgInstrument.DOMAsks .Cast <CQGQuote>() .Where(q => q.IsValid) .Select(q => new QuoteChange(Sides.Sell, (decimal)q.Price, q.HasVolume ? q.Volume : 0)), }); }
private void SessionOnInstrumentDomChanged(CQGInstrument cqgInstrument, CQGDOMQuotes prevAsks, CQGDOMQuotes prevBids) { SendOutMessage(new QuoteChangeMessage { SecurityId = new SecurityId { SecurityCode = cqgInstrument.Commodity, BoardCode = cqgInstrument.ExchangeAbbreviation, }, ServerTime = cqgInstrument.ServerTimestamp.ApplyTimeZone(TimeHelper.Est), Bids = cqgInstrument.DOMBids .Cast<CQGQuote>() .Where(q => q.IsValid) .Select(q => new QuoteChange(Sides.Buy, (decimal)q.Price, q.HasVolume ? q.Volume : 0)), Asks = cqgInstrument.DOMAsks .Cast<CQGQuote>() .Where(q => q.IsValid) .Select(q => new QuoteChange(Sides.Sell, (decimal)q.Price, q.HasVolume ? q.Volume : 0)), }); }
static void Cel_InstrumentDOMChanged(CQGInstrument instrument, CQGDOMQuotes prev_asks, CQGDOMQuotes prev_bids) { var symbolData = _symbolsInProgress.Find(oo => oo.Name == instrument.FullName); if (symbolData == null) return; lock (_waitingLocker) { var domData = symbolData.DomData; if (!(Cel.IsValid(instrument.DOMBids) && Cel.IsValid(instrument.DOMAsks))) return; if (!domData.FirstTride) { const double epsilon = 0.0000001; if ((Math.Abs(instrument.Trade.Price - domData.PrevTradePrice) > epsilon) || (Math.Abs(instrument.Trade.Volume - domData.PrevTradeVol) > epsilon)) { domData.IsNewTrade = true; //if (_isMoreInfo) //{ // if (symbolData.MsgObject.Parent.Parent != null) // symbolData.MsgObject.Parent.Parent.BeginInvoke( // new Action( // () => // symbolData.MsgObject.Text = // @"DOMBids depth: " + instrument.DOMBids.Count + @" DOMAsks depth: " + // instrument.DOMAsks.Count)); //} } else { domData.IsNewTrade = false; } domData.PrevTradePrice = instrument.Trade.Price; domData.PrevTradeVol = instrument.Trade.Volume; domData.PrevTradeTime = instrument.Timestamp; } else { domData.PrevTradePrice = instrument.Trade.Price; domData.PrevTradeVol = instrument.Trade.Volume; domData.PrevTradeTime = instrument.Timestamp; } domData.FirstTride = false; double askPrice; double bidPrice; int askVol; int bidVol; var serverTimestamp = new DateTime(instrument.ServerTimestamp.Year, instrument.ServerTimestamp.Month, instrument.ServerTimestamp.Day, instrument.ServerTimestamp.Hour, instrument.ServerTimestamp.Minute, instrument.ServerTimestamp.Second, instrument.ServerTimestamp.Millisecond); var query = QueryBuilder.InsertData_dom(domData.TableName, instrument, Convert.ToInt32(symbolData.Depth), ++domData.GroupId, domData.IsNewTrade, _userName, out askPrice, out askVol, out bidPrice, out bidVol, serverTimestamp); if (instrument.ServerTimestamp < DateTime.Now.AddDays(-1)) return; var tickDomData = new TickData { AskPrice = askPrice, AskVolume = askVol, BidPrice = bidPrice, BidVolume = bidVol, SymbolName = domData.SymbolName, Timestamp = serverTimestamp, GroupID = domData.GroupId }; ClientDatabaseManager.AddToBuffer(query, true, tickDomData); if (!ClientDatabaseManager.CurrentDbIsShared || symbolData.CanInsert) { //if (DatabaseManager.CurrentDbIsShared && serverTimestamp < _allowedSymbols[instrument.FullName])return; ClientDatabaseManager.RunSQLLive(query, "InsertData", instrument.FullName); } symbolData.DomData = domData; } }
private void CEL_InstrumentDOMChanged(CQGInstrument instrument, CQGDOMQuotes prevAsks, CQGDOMQuotes prevBids) { if (!_symbolsTable.Keys.Contains(instrument.FullName)) return; lock (_waitingLocker) { SymbolData symbolData = _symbolsTable[instrument.FullName]; if (symbolData.IsCanceled) { RemoveSymbol(instrument.FullName); return; } if (!(_cel.IsValid(instrument.DOMBids) && _cel.IsValid(instrument.DOMAsks))) return; if (!symbolData.FirstTride) { const double epsilon = 0.0000001; if ((Math.Abs(instrument.Trade.Price - symbolData.PrevTradePrice) > epsilon) || (Math.Abs(instrument.Trade.Volume - symbolData.PrevTradeVol) > epsilon)) { symbolData.IsNewTrade = true; if (_isMoreInfo) { if (symbolData.MsgObject.Parent.Parent != null) symbolData.MsgObject.Parent.Parent.BeginInvoke( new Action( () => symbolData.MsgObject.Text = @"DOMBids depth: " + instrument.DOMBids.Count + @" DOMAsks depth: " + instrument.DOMAsks.Count)); } } else { symbolData.IsNewTrade = false; } symbolData.PrevTradePrice = instrument.Trade.Price; symbolData.PrevTradeVol = instrument.Trade.Volume; symbolData.PrevTradeTime = instrument.Timestamp; } else { symbolData.PrevTradePrice = instrument.Trade.Price; symbolData.PrevTradeVol = instrument.Trade.Volume; symbolData.PrevTradeTime = instrument.Timestamp; } symbolData.FirstTride = false; double askPrice; double bidPrice; int askVol; int bidVol; var serverTimestamp = new DateTime(instrument.ServerTimestamp.Year, instrument.ServerTimestamp.Month, instrument.ServerTimestamp.Day, instrument.ServerTimestamp.Hour, instrument.ServerTimestamp.Minute, instrument.ServerTimestamp.Second, instrument.ServerTimestamp.Millisecond); var query = QueryBuilder.InsertData_dom(symbolData.TableName, instrument, Convert.ToInt32(symbolData.Depth), ++symbolData.GroupId, symbolData.IsNewTrade, _userName, out askPrice, out askVol, out bidPrice, out bidVol, serverTimestamp); if (instrument.ServerTimestamp < DateTime.Now.AddDays(-1)) return; var tickDomData = new TickData { AskPrice = askPrice, AskVolume = askVol, BidPrice = bidPrice, BidVolume = bidVol, SymbolName = symbolData.SymbolName, Timestamp = serverTimestamp, GroupID = symbolData.GroupId }; if (_onSymbolsList.Contains(instrument.FullName)) { DatabaseManager.AddToBuffer(query, true, tickDomData); if (_allowedSymbols.ContainsKey(_symbolsTable[instrument.FullName].SymbolName) || !DatabaseManager.CurrentDbIsShared) { if (DatabaseManager.CurrentDbIsShared && serverTimestamp < _allowedSymbols[instrument.FullName]) return; DatabaseManager.RunSQLLive(query, "InsertData", instrument.FullName); } } _symbolsTable[instrument.FullName] = symbolData; } }
private List<KaiTrade.Interfaces.IDOMSlot> ProcessDOM(CQGInstrument instrument, CQGDOMQuotes prev_asks, CQGDOMQuotes prev_bids) { List<KaiTrade.Interfaces.IDOMSlot> domSlots = new List<KaiTrade.Interfaces.IDOMSlot>(); try { decimal? price; decimal? vol; CQGQuote bidQt; CQGQuote askQt; CQGQuote prevBidQt; CQGQuote prevAskQt; int prevBidQtIndex = 0; int prevAskQtIndex = 0; int qtBidIndex = 0; int qtAskIndex = 0; //dumpDOMUpdate(instrument, prev_asks, prev_bids); while ((qtBidIndex < instrument.DOMBids.Count) || (qtAskIndex < instrument.DOMAsks.Count)) { bidQt = instrument.DOMBids[9 - qtBidIndex]; askQt = instrument.DOMAsks[qtAskIndex]; prevBidQt = prev_bids[9 - prevBidQtIndex]; prevAskQt = prev_asks[prevBidQtIndex]; if (qtBidIndex < instrument.DOMAsks.Count) { // start at bottom of current bids if (bidQt.Price < prevBidQt.Price) { // prices have dropped // ADD SLOT with BidZ = sz AskSz =null domSlots.Add(new K2DataObjects.DOMSlot((decimal)bidQt.Price, (decimal)bidQt.Volume, null)); qtBidIndex++; } if (bidQt.Price == prevBidQt.Price) { // same price so just replace if (bidQt.Volume != prevBidQt.Volume) { domSlots.Add(new K2DataObjects.DOMSlot((decimal)bidQt.Price, (decimal)bidQt.Volume, null)); } prevBidQtIndex++; qtBidIndex++; } if (bidQt.Price > prevBidQt.Price) { // prices moved up if (prevBidQtIndex < prev_bids.Count) { domSlots.Add(new K2DataObjects.DOMSlot((decimal)prevBidQt.Price, null, null)); prevBidQtIndex++; } else { domSlots.Add(new K2DataObjects.DOMSlot((decimal)bidQt.Price, (decimal)bidQt.Volume, null)); qtBidIndex++; } } } else { // do the asks if (askQt.Price < prevAskQt.Price) { // prices have dropped domSlots.Add(new K2DataObjects.DOMSlot((decimal)askQt.Price, null, (decimal)askQt.Volume)); qtAskIndex++; } if (askQt.Price == prevAskQt.Price) { // same price so just replace if (askQt.Volume != prevAskQt.Volume) { domSlots.Add(new K2DataObjects.DOMSlot((decimal)askQt.Price, null, (decimal)askQt.Volume)); } prevAskQtIndex++; qtAskIndex++; } if (askQt.Price > prevAskQt.Price) { // prices moved up if (prevAskQtIndex < prev_asks.Count) { // this slot would have been done in the bid processing //domSlots[slotIndex++] = new K2DataObjects.DOMSlot((decimal)prevAskQt.Price, null, null); prevAskQtIndex++; } else { domSlots.Add(new K2DataObjects.DOMSlot((decimal)askQt.Price, null, (decimal)askQt.Volume)); qtAskIndex++; } } } } } catch { } return domSlots; }
private List<KaiTrade.Interfaces.IDOMSlot> ProcessDOMasImage(CQGInstrument instrument, CQGDOMQuotes prev_asks, CQGDOMQuotes prev_bids) { List<KaiTrade.Interfaces.IDOMSlot> domSlots = new List<KaiTrade.Interfaces.IDOMSlot>(); try { CQGQuote bidQt; CQGQuote askQt; int qtBidIndex = instrument.DOMBids.Count - 1; int qtAskIndex = 0; while (qtBidIndex >= 0) { bidQt = instrument.DOMBids[qtBidIndex--]; domSlots.Add(new K2DataObjects.DOMSlot((decimal)bidQt.Price, (decimal)bidQt.Volume, null)); } while (qtAskIndex < instrument.DOMAsks.Count) { askQt = instrument.DOMAsks[qtAskIndex++]; domSlots.Add(new K2DataObjects.DOMSlot((decimal)askQt.Price, null, (decimal)askQt.Volume)); } } catch { } return domSlots; }
private void dumpDOMUpdate(CQGInstrument instrument, CQGDOMQuotes prev_asks, CQGDOMQuotes prev_bids) { try { for (int i = 0; i < prev_bids.Count; i++) { string temp = string.Format("BID px {0} sz {1} prev: px {2} sz {3}", instrument.DOMBids[i].Price, instrument.DOMBids[i].Volume, prev_bids[i].Price, prev_bids[i].Volume); log.Error(temp); } for (int i = 0; i < prev_asks.Count; i++) { string temp = string.Format("ASK px {0} sz {1} prev: px {2} sz {3}", instrument.DOMAsks[i].Price, instrument.DOMAsks[i].Volume, prev_asks[i].Price, prev_asks[i].Volume); log.Error(temp); } } catch (Exception myE) { } }
void CQGApp_InstrumentDOMChanged(CQGInstrument cqg_instrument, CQGDOMQuotes prev_asks, CQGDOMQuotes prev_bids) { try { int prevAskCount = prev_asks.Count; int prevBidCount = prev_bids.Count; int x = cqg_instrument.DOMAsks.Count; int y = cqg_instrument.DOMBids.Count; if (_publisherRegister.ContainsKey(cqg_instrument.FullName)) { //List<KaiTrade.Interfaces.IDOMSlot> slots = ProcessDOM(cqg_instrument,prev_asks, prev_bids); List<KaiTrade.Interfaces.IDOMSlot> slots = ProcessDOMasImage(cqg_instrument, prev_asks, prev_bids); base.ApplyDOMUpdate(cqg_instrument.FullName, slots.ToArray()); return; } } catch (Exception myE) { log.Error("CQGApp_InstrumentDOMChanged", myE); } }
private void CEL_InstrumentDOMChanged(CQGInstrument instrument, CQGDOMQuotes prevAsks, CQGDOMQuotes prevBids) { ticks += 1; if (!isCanceled) { tsAskDpth.Text = Convert.ToString(instrument.DOMAsks.Count); tsBidDpth.Text = Convert.ToString(instrument.DOMBids.Count); if (!firstTride) { if ((instrument.Trade.Price != PrevTradePrice) || (instrument.Trade.Volume != PrevTradeVol) || (instrument.Timestamp != PrevTradeTime)) { isNewTrade = true; } else { isNewTrade = false; } PrevTradePrice = instrument.Trade.Price; PrevTradeVol = instrument.Trade.Volume; PrevTradeTime = instrument.Timestamp; } else { PrevTradePrice = instrument.Trade.Price; PrevTradeVol = instrument.Trade.Volume; PrevTradeTime = instrument.Timestamp; } firstTride = false; String _query = QueryBuilder.InsertData(m_tableName, instrument, Convert.ToInt32(nudDOMDepth.Value), m_qroup_ID,isNewTrade); RunSQL(_query, "InsertData"); m_qroup_ID +=1; } else { RunSQL("DROP TABLE IF EXISTS " + m_tableName, "flush"); //m_CEL.Shutdown(); connector.CQG_Stop(); //isCanceled = false; } }
private void CEL_InstrumentDOMChanged(CQGInstrument instrument, CQGDOMQuotes prevAsks, CQGDOMQuotes prevBids) { if (!_symbolsTable.Keys.Contains(instrument.FullName)) { return; } lock (_waitingLocker) { SymbolData symbolData = _symbolsTable[instrument.FullName]; if (symbolData.IsCanceled) { RemoveSymbol(instrument.FullName); return; } if (!(_cel.IsValid(instrument.DOMBids) && _cel.IsValid(instrument.DOMAsks))) { return; } if (!symbolData.FirstTride) { const double epsilon = 0.0000001; if ((Math.Abs(instrument.Trade.Price - symbolData.PrevTradePrice) > epsilon) || (Math.Abs(instrument.Trade.Volume - symbolData.PrevTradeVol) > epsilon)) { symbolData.IsNewTrade = true; if (_isMoreInfo) { if (symbolData.MsgObject.Parent.Parent != null) { symbolData.MsgObject.Parent.Parent.BeginInvoke( new Action( () => symbolData.MsgObject.Text = @"DOMBids depth: " + instrument.DOMBids.Count + @" DOMAsks depth: " + instrument.DOMAsks.Count)); } } } else { symbolData.IsNewTrade = false; } symbolData.PrevTradePrice = instrument.Trade.Price; symbolData.PrevTradeVol = instrument.Trade.Volume; symbolData.PrevTradeTime = instrument.Timestamp; } else { symbolData.PrevTradePrice = instrument.Trade.Price; symbolData.PrevTradeVol = instrument.Trade.Volume; symbolData.PrevTradeTime = instrument.Timestamp; } symbolData.FirstTride = false; double askPrice; double bidPrice; int askVol; int bidVol; var serverTimestamp = new DateTime(instrument.ServerTimestamp.Year, instrument.ServerTimestamp.Month, instrument.ServerTimestamp.Day, instrument.ServerTimestamp.Hour, instrument.ServerTimestamp.Minute, instrument.ServerTimestamp.Second, instrument.ServerTimestamp.Millisecond); var query = QueryBuilder.InsertData_dom(symbolData.TableName, instrument, Convert.ToInt32(symbolData.Depth), ++symbolData.GroupId, symbolData.IsNewTrade, _userName, out askPrice, out askVol, out bidPrice, out bidVol, serverTimestamp); if (instrument.ServerTimestamp < DateTime.Now.AddDays(-1)) { return; } var tickDomData = new TickData { AskPrice = askPrice, AskVolume = askVol, BidPrice = bidPrice, BidVolume = bidVol, SymbolName = symbolData.SymbolName, Timestamp = serverTimestamp, GroupID = symbolData.GroupId }; if (_onSymbolsList.Contains(instrument.FullName)) { DatabaseManager.AddToBuffer(query, true, tickDomData); if (_allowedSymbols.ContainsKey(_symbolsTable[instrument.FullName].SymbolName) || !DatabaseManager.CurrentDbIsShared) { if (DatabaseManager.CurrentDbIsShared && serverTimestamp < _allowedSymbols[instrument.FullName]) { return; } DatabaseManager.RunSQLLive(query, "InsertData", instrument.FullName); } } _symbolsTable[instrument.FullName] = symbolData; } }
static void Cel_InstrumentDOMChanged(CQGInstrument instrument, CQGDOMQuotes prev_asks, CQGDOMQuotes prev_bids) { var symbolData = _symbolsInProgress.Find(oo => oo.Name == instrument.FullName); if (symbolData == null) { return; } lock (_waitingLocker) { var domData = symbolData.DomData; if (!(Cel.IsValid(instrument.DOMBids) && Cel.IsValid(instrument.DOMAsks))) { return; } if (!domData.FirstTride) { const double epsilon = 0.0000001; if ((Math.Abs(instrument.Trade.Price - domData.PrevTradePrice) > epsilon) || (Math.Abs(instrument.Trade.Volume - domData.PrevTradeVol) > epsilon)) { domData.IsNewTrade = true; //if (_isMoreInfo) //{ // if (symbolData.MsgObject.Parent.Parent != null) // symbolData.MsgObject.Parent.Parent.BeginInvoke( // new Action( // () => // symbolData.MsgObject.Text = // @"DOMBids depth: " + instrument.DOMBids.Count + @" DOMAsks depth: " + // instrument.DOMAsks.Count)); //} } else { domData.IsNewTrade = false; } domData.PrevTradePrice = instrument.Trade.Price; domData.PrevTradeVol = instrument.Trade.Volume; domData.PrevTradeTime = instrument.Timestamp; } else { domData.PrevTradePrice = instrument.Trade.Price; domData.PrevTradeVol = instrument.Trade.Volume; domData.PrevTradeTime = instrument.Timestamp; } domData.FirstTride = false; double askPrice; double bidPrice; int askVol; int bidVol; var serverTimestamp = new DateTime(instrument.ServerTimestamp.Year, instrument.ServerTimestamp.Month, instrument.ServerTimestamp.Day, instrument.ServerTimestamp.Hour, instrument.ServerTimestamp.Minute, instrument.ServerTimestamp.Second, instrument.ServerTimestamp.Millisecond); var query = QueryBuilder.InsertData_dom(domData.TableName, instrument, Convert.ToInt32(symbolData.Depth), ++domData.GroupId, domData.IsNewTrade, _userName, out askPrice, out askVol, out bidPrice, out bidVol, serverTimestamp); if (instrument.ServerTimestamp < DateTime.Now.AddDays(-1)) { return; } var tickDomData = new TickData { AskPrice = askPrice, AskVolume = askVol, BidPrice = bidPrice, BidVolume = bidVol, SymbolName = domData.SymbolName, Timestamp = serverTimestamp, GroupID = domData.GroupId }; ClientDatabaseManager.AddToBuffer(query, true, tickDomData); if (!ClientDatabaseManager.CurrentDbIsShared || symbolData.CanInsert) { //if (DatabaseManager.CurrentDbIsShared && serverTimestamp < _allowedSymbols[instrument.FullName])return; ClientDatabaseManager.RunSQLLive(query, "InsertData", instrument.FullName); } symbolData.DomData = domData; } }