Beispiel #1
0
        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;
            }
        }
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;
            }
        }