예제 #1
0
        private static void _cel_InstrumentSubscribed(string symbol, CQGInstrument cqgInstrument)
        {
            _FullNameSYmbol = cqgInstrument.FullName;
            SubscribedSymbol.Add(symbol);

            // foreach (var symbol in symbols)
            {
                // CQGInstrument instrument = _cqgVar.Instruments[symbol];
                CQGInstrumentProperties props = cqgInstrument.Properties;
                double   tickSize             = -1;
                double   tickValue            = -1;
                string   curency    = " ";
                DateTime expiration = DateTime.Today;
                var      properties = props[eInstrumentProperty.ipTickSize];
                if (props != null && _cqgVar.IsValid(properties.Value))
                {
                    tickSize = properties.Value;
                }
                properties = props[eInstrumentProperty.ipCurrency];
                if (props != null && _cqgVar.IsValid(properties.Value))
                {
                    curency = properties.Value;
                }
                // properties = props[eInstrumentProperty.ipExpirationDate];
                // if (props != null && _cqgVar.IsValid(properties.Value))
                //    expiration = properties.Value;
                properties = props[eInstrumentProperty.ipTickValue];
                if (props != null && _cqgVar.IsValid(properties.Value))
                {
                    tickValue = properties.Value;
                }

                ClientDatabaseManager.AddNotChangedValue(symbol, tickSize, curency, tickValue);
            }
        }
예제 #2
0
        static void _cel_InstrumentSubscribed(string symbol, CQGInstrument cqgInstrument)
        {
            //Check expired date
            DateTime d = cqgInstrument.ExpirationDate;

            Console.WriteLine("Symbol: '" + symbol + "' will be expired:" + d.ToShortDateString());

            if ((d - DateTime.Now).TotalHours < (Settings.Default.DaysToExpiration * 24))
            {
                if (!Settings.Default.EmailedSymbols.Contains(symbol))
                {
                    OnSendReport("Symbol: '" + symbol + "' will expired soon", "Hello. \n The symbol: '" + symbol + "' will be expired on less then " + Settings.Default.DaysToExpiration + " days. \nExpiration date: " + d.ToShortDateString() + "\n\nGood luck");
                    Settings.Default.EmailedSymbols += symbol;
                }
            }
            //Month
            MonthCharYearModel variable = new MonthCharYearModel();

            variable.MonthChar = "def";
            variable.Year      = "def";
            foreach (var monthCharYearModel in monthCharYearlList)
            {
                if (monthCharYearModel.Symbol == symbol)
                {
                    return;
                }
            }
            CQGInstrumentProperties props = cqgInstrument.Properties;
            var properties = props[eInstrumentProperty.ipMonthChar];

            if (props != null && Cel.IsValid(properties.Value))
            {
                variable.MonthChar = properties.Value.ToString();
            }
            properties = props[eInstrumentProperty.ipYear];
            if (props != null && Cel.IsValid(properties.Value))
            {
                variable.Year = properties.Value.ToString();
            }
            variable.Symbol = symbol;
            monthCharYearlList.Add(variable);
            Cel.RemoveInstrument(cqgInstrument);
        }
예제 #3
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;
            }
        }
예제 #4
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;
            }
        }