Esempio n. 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;
            }
        }
Esempio n. 2
0
        public void CEL_InstrumentSubscribed(string symbol1, ICQGInstrument instrument)
        {
            var sdata = new SymbolData();

            try
            {
                var symbol    = symbol1;
                var symbolLen = symbol.Length;
                sdata = new SymbolData("DM_" + symbol.Substring(5, symbolLen - 5).ToUpper())
                {
                    Instrument = instrument, Depth = GetDepthForSymbol(instrument.FullName)
                };
                sdata.SymbolName = symbol;

                if (_addSybolsList.Count == 0)
                {
                    return;
                }
                sdata.MsgObject = _addSybolsList[symbol];
                var tdata = new TickData("TS_" + symbol.Substring(5, symbol.Length - 5).ToUpper(), symbol);

                DatabaseManager.DoSqlLive(QueryBuilder.createTable_tick(tdata.TableName));
                DatabaseManager.DoSqlLive(QueryBuilder.createTable_dom(sdata.TableName));

                if (_isMoreInfo)
                {
                    sdata.MsgObject.Text      = @"Subscribed. Waiting for data...";
                    sdata.MsgObject.ForeColor = Color.Green;
                }
                else
                {
                    sdata.MsgObject.Text      = @"Subscribed";
                    sdata.MsgObject.ForeColor = Color.Green;
                }
                instrument.DataSubscriptionLevel = eDataSubscriptionLevel.dsQuotesAndDOM;
                sdata.GroupId = 0;

                Console.WriteLine(@"dom:" + sdata.GroupId);
                if (!_symbolsTable.ContainsKey(instrument.FullName))
                {
                    _symbolsTable.Add(instrument.FullName, sdata);
                }

                tdata.GroupID = 0;
                if (!_tickTable.ContainsKey(instrument.FullName))
                {
                    _tickTable.Add(instrument.FullName, tdata);
                }

                if (!_subscribedSymbols.Exists(oo => oo == symbol1))
                {
                    _subscribedSymbols.Add(symbol1);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                if (sdata.MsgObject != null)
                {
                    sdata.MsgObject.ForeColor = Color.OrangeRed;
                    sdata.MsgObject.Text      = ex.Message;
                }
            }
        }