Beispiel #1
0
        static void Cel_InstrumentChanged(CQGInstrument instrument, CQGQuotes quotes, CQGInstrumentProperties cqg_instrument_properties)
        {
            var symbolData = _symbolsInProgress.Find(oo => oo.Name == instrument.FullName);

            if (symbolData == null)
            {
                return;
            }


            lock (_waitingLocker)
            {
                var tickData = symbolData.TickData;

                tickData.TickCount = 0;
                foreach (CQGQuote item in quotes)
                {
                    CQGQuote tick = item;

                    tickData.IsNewTrade = tick.Name == "Trade";
                    switch (tick.Name)
                    {
                    case "Ask":
                    {
                        tickData.AskPrice    = tick.Price;
                        tickData.AskVolume   = tick.Volume;
                        tickData.TradePrice  = 0;
                        tickData.TradeVolume = 0;
                        break;
                    }

                    case "Bid":
                    {
                        tickData.BidPrice    = tick.Price;
                        tickData.BidVolume   = tick.Volume;
                        tickData.TradePrice  = 0;
                        tickData.TradeVolume = 0;
                        break;
                    }

                    case "Trade":
                    {
                        tickData.TradePrice  = tick.Price;
                        tickData.TradeVolume = tick.Volume;
                        break;
                    }
                    }
                    tickData.TickCount++;
                }

                if (tickData.TickCount > 0)
                {
                    var quoteList = (from CQGQuote item in quotes
                                     where item.Name == "Ask" ||
                                     item.Name == "Bid" ||
                                     item.Name == "Trade"
                                     select item).ToList();
                    quoteList.OrderBy(quote => quote.ServerTimestamp);
                    if (quoteList.Any())
                    {
                        tickData.Timestamp = quoteList.Last().ServerTimestamp;
                        tickData.TickType  = quoteList.Last().Name;
                    }
                    else
                    {
                        tickData.Timestamp = instrument.ServerTimestamp;
                    }
                    var query = QueryBuilder.InsertData(tickData.TableName, tickData.SymbolName,
                                                        tickData.BidPrice,
                                                        tickData.BidVolume,
                                                        tickData.AskPrice, tickData.AskVolume,
                                                        tickData.TradePrice,
                                                        tickData.TradeVolume,
                                                        tickData.IsNewTrade, tickData.Timestamp,
                                                        ++tickData.GroupID,
                                                        _userName, tickData.TickType);
                    if (tickData.Timestamp < DateTime.Now.AddDays(-1))
                    {
                        return;
                    }

                    ClientDatabaseManager.AddToBuffer(query, false, tickData);
                    if (!ClientDatabaseManager.CurrentDbIsShared || symbolData.CanInsert)
                    {
                        //todo if (DatabaseManager.CurrentDbIsShared && tickData.Timestamp < _allowedSymbols[tickData.SymbolName])return;
                        ClientDatabaseManager.RunSQLLive(query, "InsertData", instrument.FullName);
                    }
                }

                symbolData.TickData = tickData;
            }
        }
Beispiel #2
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;
            }
        }