Ejemplo n.º 1
0
        public void SessionAdd(CQGSessions sessions, string symbol)
        {
            if (_shouldStop)
            {
                return;
            }
            try
            {
                foreach (CQGSession session in sessions)
                {
                    var one = new SessionData
                    {
                        StartTime          = session.StartTime,
                        EndTime            = session.EndTime,
                        DayOfWeek          = session.WorkingWeekDays,
                        Symbol             = symbol,
                        DayStartsYesterday = session.DayStartsYesterday
                    };
                    _listSession.Add(one);

                    ClientDatabaseManager.AddToSessionTable(symbol, symbol, session.StartTime, session.EndTime, "Open",
                                                            GetSessionWorkingDays(session.WorkingWeekDays), session.DayStartsYesterday, session.PrimaryFlag, session.Number, DateTime.Now);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                _logger.LogAdd("SessionAdd. " + ex.Message, Category.Error);
            }

            _aSemaphoreSessions.Release();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles events that require the system to execute a database stored procedure based on the configuration.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="storedProcedureName"></param>
        private static void DatabaseStoredProcedure(EventNotificationData eventData, string storedProcedureName)
        {
            var storedProcedureSettings = campusLogicConfigSection.StoredProcedures.GetStoredProcedure(storedProcedureName);

            if (storedProcedureSettings != null)
            {
                // Parse parameters based on config.
                List <OdbcParameter> parameters =
                    storedProcedureSettings.GetParameters().Select(p => ParseParameter(p, eventData)).ToList();

                //Adding logging in case client experiences weird argument error, we can better determine what we are trying to pass
                //logger.Info($"Parameters to be pass into database: { String.Join(", ", parameters.Select(x => x.ParameterName + ": " + x.Value.ToString() + " - DataType: " + Enum.GetName(typeof(OdbcType), x.OdbcType)))}");

                // For each parameter, need to add a placeholder "?" in the sql command.
                // This is just part of the ODBC syntax.
                string placeholders = string.Join(",", parameters.Select(p => "?").ToArray());
                if (placeholders.Length > 0)
                {
                    placeholders = " (" + placeholders + ")";
                }

                // Final output should look like this: {CALL sproc_name (?, ?, ?)}
                string command = $"{{CALL {storedProcedureSettings.Name}{placeholders}}}";

                //logger.Info(command);
                ClientDatabaseManager.ExecuteDatabaseStoredProcedure(command, parameters);
            }
            else
            {
                //Static db procedure
                GetDefaultDatabaseProcedure(eventData, storedProcedureName);
            }
        }
Ejemplo n.º 3
0
        public static void GetDefaultDatabaseProcedure(EventNotificationData eventData, string storedProcedureName)
        {
            var parameters = new List <OdbcParameter>();

            //Define parameters
            parameters.Add(new OdbcParameter
            {
                ParameterName = "StudentId",
                OdbcType      = OdbcType.VarChar,
                Size          = 9,
                Value         = eventData.PropertyValues[EventPropertyConstants.StudentId].Value <string>()
            });

            parameters.Add(new OdbcParameter
            {
                ParameterName = "AwardYear",
                OdbcType      = OdbcType.VarChar,
                Size          = 4,
                Value         = eventData.PropertyValues[EventPropertyConstants.AwardYear].IsNullOrEmpty() ? string.Empty : (eventData.PropertyValues[EventPropertyConstants.AwardYear].Value <string>().Substring(2, 2) + eventData.PropertyValues[EventPropertyConstants.AwardYear].Value <string>().Substring(7, 2))
            });

            parameters.Add(new OdbcParameter
            {
                ParameterName = "TransactionCategoryId",
                OdbcType      = OdbcType.Int,
                Value         = eventData.PropertyValues[EventPropertyConstants.SvTransactionCategoryId].IsNullOrEmpty() ? 0 : eventData.PropertyValues[EventPropertyConstants.SvTransactionCategoryId].Value <int>()
            });

            parameters.Add(new OdbcParameter
            {
                ParameterName = "EventNotificationId",
                OdbcType      = OdbcType.Int,
                Value         = eventData.PropertyValues[EventPropertyConstants.EventNotificationId].Value <int>()
            });

            if (!eventData.PropertyValues[EventPropertyConstants.SvDocumentId].IsNullOrEmpty() && eventData.PropertyValues[EventPropertyConstants.SvDocumentId].Value <int>() > 0)
            {
                var manager = new DocumentManager();
                DocumentMetaData metaData = manager.GetDocumentMetaData(eventData.PropertyValues[EventPropertyConstants.SvDocumentId].Value <int>());

                parameters.Add(new OdbcParameter
                {
                    ParameterName = "DocumentName",
                    OdbcType      = OdbcType.VarChar,
                    Size          = 128,
                    Value         = metaData != null ? metaData.DocumentName : string.Empty
                });
            }
            else
            {
                parameters.Add(new OdbcParameter
                {
                    ParameterName = "DocumentName",
                    OdbcType      = OdbcType.VarChar,
                    Size          = 128,
                    Value         = string.Empty
                });
            }
            ClientDatabaseManager.ExecuteDatabaseStoredProcedure("{CALL " + storedProcedureName + " (?, ?, ?, ?, ?)}", parameters);
        }
Ejemplo n.º 4
0
        private void ui_ButtonX_add_Click(object sender, EventArgs e)
        {
            if (ui_textBoxXSymbolName.Text == "")
            {
                ToastNotification.Show(this, "Please, enter new symbol name");
                return;
            }
            if (_symbols.Exists(a => a.SymbolName == ui_textBoxXSymbolName.Text))
            {
                ToastNotification.Show(this, "The name of symbol already exists");
                return;
            }
            var newSymbol = ui_textBoxXSymbolName.Text;

            if (!ClientDatabaseManager.CurrentDbIsShared)
            {
                ClientDatabaseManager.AddNewSymbol(newSymbol);
            }
            if (ClientDatabaseManager.CurrentDbIsShared)
            {
                if (!_allSymbols.Exists(a => a.SymbolName == newSymbol))
                {
                    ClientDatabaseManager.AddNewSymbol(newSymbol);
                }
                ClientDatabaseManager.Commit();
                var symbolId = ClientDatabaseManager.GetAllSymbols().Find(a => a.SymbolName == newSymbol).SymbolId;
                ClientDatabaseManager.AddSymbolForUser(_userID, symbolId, ApplicationType.TickNet);
            }
            RefreshSymbols();
            ToastNotification.Show(this, "Symbol '" + newSymbol + "' added");
            OnUpdateSymbolsEvent();
        }
Ejemplo n.º 5
0
        private static void AddTick(CQGTick tick, string symbol, DateTime runDateTime, int groupId, string userName)
        {
            try
            {
                var str   = symbol.Trim().Split('.');
                var query = "INSERT IGNORE INTO T_" + str[str.Length - 1] + "_" + GetIso8601WeekOfYear(tick.Timestamp);
                query += "(Symbol, Price, Volume, TickTime, SystemTime, ContinuationType, PriceType, GroupId, UserName) VALUES";
                query += "('";
                query += symbol + "',";
                query += GetValueAsString(tick.Price) + ",";
                query += GetValueAsString(tick.Volume) + ",";
                query += GetValueAsString(tick.Timestamp) + ",";
                query += GetValueAsString(runDateTime) + ",";
                query += "'" + _continuationType + "',";
                query += "'" + tick.PriceType.ToString() + "',";
                query += GetValueAsString(groupId) + ",";
                query += "'" + userName + "');";

                ClientDatabaseManager.AddToQueue(query, 2);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception.AddTick." + ex.Message);
            }
        }
Ejemplo n.º 6
0
        private void ui_buttonX_replace_Click(object sender, EventArgs e)
        {
            if (ui_listBox_symbols.SelectedItem == null)
            {
                ToastNotification.Show(this, "Please, select symbol");
                return;
            }
            if (ui_textBoxXSymbolName.Text == "")
            {
                ToastNotification.Show(this, "Please, enter new symbol name");
                return;
            }
            if (_symbols.Exists(symbol => symbol.SymbolName == ui_textBoxXSymbolName.Text) || (!ClientDatabaseManager.CurrentDbIsShared && _allSymbols.Exists(a => a.SymbolName == ui_textBoxXSymbolName.Text)))
            {
                ToastNotification.Show(this, "Symbol with this name already exists");
                return;
            }
            var ind     = ui_listBox_symbols.SelectedIndex;
            var oldName = ui_listBox_symbols.SelectedItem.ToString();
            var newName = ui_textBoxXSymbolName.Text;

            if (
                MessageBox.Show("Do you wish to replace symbol " + oldName + " by " + newName + " ?", "Replacing symbol", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                ClientDatabaseManager.EditSymbol(oldName, newName, _userID, ApplicationType.TickNet);
                RefreshSymbols();
                ui_listBox_symbols.SelectedIndex = ind;
                ToastNotification.Show(this, "The symbol '" + oldName + "' replaaced by '" + newName + "'");
                OnUpdateSymbolsEvent();
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        internal static void UpdateMonthAndYearForSymbols(List <string> selectedSymbols)
        {
            new Thread(
                () =>
            {
                for (int i = 0; i < selectedSymbols.Count; i++)
                {
                    var listOfTables = ClientDatabaseManager.GetListOfBarTables(selectedSymbols[i]);
                    int k            = 0;
                    var progr        = 0;
                    var rowsMaxCount = listOfTables.Count;
                    var cto          = (double)rowsMaxCount;
                    OnProgressBarChanged(2);

                    foreach (var table in listOfTables)
                    {
                        Console.WriteLine("table: " + table);
                        //try load data from TblExpiration

                        var listOfExpirations = ClientDatabaseManager.GetExpirationDatesForSymbol(selectedSymbols[i]);

                        string month, year;

                        if (!ClientDatabaseManager.MonthCharYearExist(table))
                        {
                            ClientDatabaseManager.AddMonthCharYearColumnsToBarTable(table);
                        }
                        if (ClientDatabaseManager.YearCharExist(table))
                        {
                            ClientDatabaseManager.DeleteWrongColumnsFromTable(table);
                        }


                        //Update table: item
                        if (IsNoCont(table, out month, out year))
                        {
                            ClientDatabaseManager.UpdateMonthAndYearForStandardSymbol(table, month, year);
                        }
                        else
                        {
                            UpdateTableMonthChar(table, listOfExpirations);
                        }
                    }
                    k++;
                    var newProgr = (int)Math.Round((k / cto) * 100f);
                    if (newProgr > progr)
                    {
                        progr = newProgr;
                        OnProgressBarChanged(progr);
                    }
                }

                OnProgressBarChanged(100);
            })
            {
                Name = "UpdateMonthAndYearForSymbols"
            }.Start();
        }
Ejemplo n.º 9
0
        private static void AddBar(CQGTimedBar timedBar, string symbol, DateTime runDateTime, string tType, string userName)
        {
            try
            {
                string MonthChar = "";
                string Year      = "";
                foreach (var monthCharYearModel in monthCharYearlList)
                {
                    if (symbol == monthCharYearModel.Symbol)
                    {
                        MonthChar = monthCharYearModel.MonthChar;
                        Year      = monthCharYearModel.Year;
                    }
                }
                var str5 = symbol.Trim();
                var str  = str5.Split('.');
                str5 = str[str.Length - 1];

                if (GetValueAsString(timedBar.Open) == "N/A")
                {
                }
                else
                {
                    GetValueAsString(timedBar.Open);
                }
                GetValueAsString(timedBar.Timestamp);
                var str3 = "'" + symbol + "'," +
                           GetValueAsString(Math.Max(timedBar.Open, 0)) + "," +
                           GetValueAsString(Math.Max(timedBar.High, 0)) + "," +
                           GetValueAsString(Math.Max(timedBar.Low, 0)) + "," +
                           GetValueAsString(Math.Max(timedBar.Close, 0)) + "," +

                           GetValueAsString(Math.Max(timedBar.TickVolume, 0)) + "," +
                           GetValueAsString(Math.Max(timedBar.ActualVolume, 0)) + "," +
                           GetValueAsString(Math.Max(timedBar.AskVolume, 0)) + "," +
                           GetValueAsString(Math.Max(timedBar.BidVolume, 0)) + "," +
                           GetValueAsString(Math.Max(timedBar.OpenInterest, 0)) + "," +

                           GetValueAsString(timedBar.Timestamp) + "," +
                           GetValueAsString(runDateTime) + ",'" +
                           _continuationType + "','" +
                           userName + "','" +
                           MonthChar + "','" +
                           Year + "'";

                var sql = "INSERT IGNORE INTO B_" + str5 + "_" + tType + " (Symbol, OpenValue, HighValue, LowValue, CloseValue," +
                          " TickVol, ActualVol, AskVol, BidVol, OpenInterest," +
                          "BarTime, SystemTime, ContinuationType, UserName, MonthChar, Year) VALUES (" + str3 + ");";

                ClientDatabaseManager.AddToQueue(sql, 5);
            }
            catch (Exception ex)
            {
                Console.WriteLine("AddBar." + ex.Message);
            }
        }
Ejemplo n.º 10
0
        private void ui_buttonX_join_Click(object sender, EventArgs e)
        {
            var message    = "";
            var symbCount  = ui_listBox_symbols.SelectedItems.Count;
            var groupCount = ui_listBox_groups.SelectedItems.Count;

            if (symbCount == 0)
            {
                ToastNotification.Show(this, "Please, select symbols");
                return;
            }
            if (groupCount == 0)
            {
                ToastNotification.Show(this, "Please, select groups");
                return;
            }

            for (int i = 0; i < symbCount; i++)
            {
                var currSmb   = ui_listBox_symbols.SelectedItems[i].ToString();
                var currSmbId = _symbols.Find(a => a.SymbolName == currSmb).SymbolId;

                for (int j = 0; j < groupCount; j++)
                {
                    var currGroupName    = ui_listBox_groups.SelectedItems[j].ToString();
                    var currGrp          = _groups.Find(a => a.GroupName == currGroupName);
                    var currGroupId      = currGrp.GroupId;
                    var currGroupSymbols = ClientDatabaseManager.GetSymbolsInGroup(currGroupId);


                    if (!currGroupSymbols.Exists(a => a.SymbolName == currSmb))
                    {
                        var sModel = new SymbolModel {
                            SymbolId = currSmbId, SymbolName = currSmb
                        };

                        if (GetCntTypeOfSymbol(currSmb) == currGrp.CntType)
                        {
                            ClientDatabaseManager.AddSymbolIntoGroup(currGroupId, sModel);
                        }
                        else
                        {
                            message += " Symbol: '" + currSmb + "' can't be added to '" + currGroupName + "' group";
                        }
                    }
                }
            }
            ToastNotification.Show(this, "Joined.");
            if (!String.IsNullOrEmpty(message))
            {
                ToastNotification.Show(this, message);
            }

            OnUpdateGroupsEvent();
        }
Ejemplo n.º 11
0
        private static void TickScheduler()
        {
            var now = DateTime.Now;

            for (int index = 0; index < _groups.Count; index++)
            {
                var groupModel = _groups[index].GroupModel;
                if (!groupModel.IsAutoModeEnabled)
                {
                    continue;
                }

                var sess         = ClientDatabaseManager.GetSessionsInGroup(groupModel.GroupId);
                var foundedRight = false;
                foreach (var oneSess in sess)
                {
                    if (oneSess.IsStartYesterday)
                    {
                        if (IsNowAGoodDay(DateTime.Today.AddDays(1), oneSess.Days) && (oneSess.TimeStart.TimeOfDay < DateTime.Now.TimeOfDay))
                        {
                            foundedRight = true; break;
                        }

                        if (IsNowAGoodDay(DateTime.Today, oneSess.Days) && (oneSess.TimeEnd.TimeOfDay >= DateTime.Now.TimeOfDay))
                        {
                            foundedRight = true; break;
                        }
                    }
                    else
                    {
                        if (IsNowAGoodDay(DateTime.Today, oneSess.Days) && (oneSess.TimeStart.TimeOfDay < DateTime.Now.TimeOfDay) &&
                            (oneSess.TimeEnd.TimeOfDay >= DateTime.Now.TimeOfDay))
                        {
                            foundedRight = true; break;
                        }
                    }
                }
                //if (sess.Any(oo => oo.TimeStart.TimeOfDay < DateTime.Now.TimeOfDay && oo.TimeEnd.TimeOfDay > DateTime.Now.TimeOfDay && IsNowAGoodDay(oo.Days)))//startToday
                if (foundedRight)
                {
                    if (_groups[index].GroupState != GroupState.InQueue)
                    {
                        _groups[index].GroupState = GroupState.InQueue;
                        OnItemStateChanged(index, GroupState.InQueue);
                    }
                }
                else
                {
                    _groups[index].GroupState = GroupState.NotInQueue;
                    OnItemStateChanged(index, GroupState.NotInQueue);
                }
            }
            StartFromGroups();
            //Start();
        }
Ejemplo n.º 12
0
        private void RefreshSymbols()
        {
            ui_listBox_symbols.Invoke((Action)(() => ui_listBox_symbols.Items.Clear()));

            _symbols    = ClientDatabaseManager.GetSymbols(_userID, false);
            _allSymbols = ClientDatabaseManager.GetAllSymbols();
            foreach (var item in _symbols)
            {
                SymbolModel item1 = item;
                ui_listBox_symbols.Invoke((Action)(() => ui_listBox_symbols.Items.Add(item1.SymbolName)));
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Validating database connection
        /// if the database connection is required
        /// </summary>
        /// <param name="eventNotifications"></param>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        public static bool ValidateConnectionStringValid(IList <EventNotificationHandler> eventNotifications, string connectionString)
        {
            string[] handlersWithoutConnectionString = { "DocumentRetrieval", "FileStore", "FileStoreAndDocumentRetrieval", "AwardLetterPrint", "BatchProcessingAwardLetterPrint", "ApiIntegration", "PowerFAIDS" };

            if (eventNotifications.All(x => handlersWithoutConnectionString.Contains(x.HandleMethod)))
            {
                return(true);
            }

            var result = ClientDatabaseManager.TestConnectionString(connectionString);

            return(string.IsNullOrEmpty(result));
        }
Ejemplo n.º 14
0
        private void LoadSessions()
        {
            var sessionsList = ClientDatabaseManager.GetSessionsInGroup(GroupId);

            foreach (var sessions in sessionsList)
            {
                var res = listViewEx_times.Items.Add(listViewEx_times.Items.Count.ToString());
                res.SubItems.Add(sessions.Name);
                res.SubItems.Add(sessions.TimeStart.ToShortTimeString());

                res.SubItems.Add(sessions.Days);
            }
        }
Ejemplo n.º 15
0
 private void RefreshGroups()
 {
     _groups = ClientDatabaseManager.GetGroups(_userID, ApplicationType.TickNet);
     ui_listBox_groups.Invoke((Action)(() => ui_listBox_groups.Items.Clear()));
     if (ClientDatabaseManager.CurrentDbIsShared)
     {
         _allGroups = ClientDatabaseManager.GetAllGroups(ApplicationType.TickNet);
     }
     foreach (var item in _groups)
     {
         var item1 = item;
         ui_listBox_groups.Invoke((Action)(() => ui_listBox_groups.Items.Add(item1.GroupName)));
     }
 }
Ejemplo n.º 16
0
        public static void StoreBarData(CQGTimedBars mCurTimedBars, CQGError cqgError, string userName)
        {
            //try
            //{g

            if (cqgError != null && cqgError.Code != 0)
            {
                FinishCollectingSymbol(mCurTimedBars.Request.Symbol, false, 0, "Expired! Error code: " + cqgError.Code + ". Description:" + cqgError.Description);
            }
            else
            {
                var str5 = mCurTimedBars.Request.Symbol.Trim();
                var str  = str5.Split('.');
                str5 = str[str.Length - 1];
                var tableName = "B_" + str5 + "_" + GetTableType(_historicalPeriod);


                var realyInsertedRows = 0;

                if (mCurTimedBars.Status == eRequestStatus.rsSuccess)
                {
                    ClientDatabaseManager.DeleteLastBar("B_" + str5 + "_" + GetTableType(_historicalPeriod));

                    var lastExisting3000BarData = ClientDatabaseManager.GetLast3000BarData(tableName);

                    if (mCurTimedBars.Count != 0)
                    {
                        for (int i = mCurTimedBars.Count - 1; i >= 0; i--)
                        {
                            if (!lastExisting3000BarData.Contains(mCurTimedBars[i].Timestamp))
                            {
                                AddBar(mCurTimedBars[i], mCurTimedBars.Request.Symbol, DateTime.Now, GetTableType(_historicalPeriod), userName);
                                realyInsertedRows++;
                            }
                        }
                    }
                    ClientDatabaseManager.CommitQueueBar();
                }
                //var rowsCount = mCurTimedBars.Count;//DatabaseManager.GetRowsCount("B_" + str5 + "_" + GetTableType(_historicalPeriod)) - beforeRowsCount
                FinishCollectingSymbol(mCurTimedBars.Request.Symbol, true, realyInsertedRows, "");
            }



            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("BarsAdd."+ex.Message);
            //}
        }
Ejemplo n.º 17
0
        private void buttonX_add_Click(object sender, EventArgs e)
        {
            var sess = new SessionModel {
                Id               = -1,
                Name             = textBoxX_sessionsName.Text,
                IsStartYesterday = checkBox_sy.Checked,
                Days             = GetDaysStr(),
                TimeStart        = dateTimeInput1.Value,
                TimeEnd          = dateTimeInput2.Value,
            };

            AddSessionToList(sess);
            ClientDatabaseManager.AddSessionForGroup(AGroupModel.GroupId, sess);
        }
Ejemplo n.º 18
0
        private void LoadExistingSessions()
        {
            comboBoxEx_existigsSessions.Items.Clear();
            var sessionsList = ClientDatabaseManager.GetSessions();

            addedSessions = new List <SessionModel>();
            foreach (var sessions in sessionsList)
            {
                if (!addedSessions.Exists(oo => oo.Name == sessions.Name))
                {
                    comboBoxEx_existigsSessions.Items.Add(" [" + sessions.TimeStart.ToShortTimeString() + " - " + sessions.TimeEnd.ToShortTimeString() + "]" + (sessions.IsStartYesterday ? "SY" : "  ") + " (" + sessions.Days + ")   " + sessions.Name);
                    addedSessions.Add(sessions);
                }
            }
        }
Ejemplo n.º 19
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listViewEx_times.SelectedItems.Count <= 0)
            {
                return;
            }
            var index = listViewEx_times.SelectedIndices[0];
            var name  = listViewEx_times.Items[index].SubItems[1].Text;

            listViewEx_times.Items.RemoveAt(index);


            var id = ClientDatabaseManager.GetSessionsInGroup(GroupId).Find(oo => oo.Name.ToUpper() == name.ToUpper()).Id;

            ClientDatabaseManager.RemoveSession(GroupId, id);
        }
Ejemplo n.º 20
0
        private static void UpdateTableMonthChar(string table, List <ExpirationModel> listOfExpirations)
        {
            if (listOfExpirations.Count == 0)
            {
                return;
            }

            listOfExpirations.OrderBy(oo => oo.EndDate);


            ClientDatabaseManager.UpdateMonthAndYearForSymbol(table, listOfExpirations[0]);

            for (int i = 1; i < listOfExpirations.Count; i++)
            {
                ClientDatabaseManager.UpdateMonthAndYearForSymbol(table, listOfExpirations[i - 1], listOfExpirations[i]);
            }
        }
Ejemplo n.º 21
0
        private void ui_buttonX_delGroup_Click(object sender, EventArgs e)
        {
            var listSymbols = new List <string>();
            var list        = "";

            foreach (var item in ui_listBox_groups.SelectedItems)
            {
                listSymbols.Add(item.ToString());
                list += item + ", ";
            }
            list = list.Substring(0, list.Length - 2);

            if (listSymbols.Count == 0)
            {
                ToastNotification.Show(this, "Please, select group");
                return;
            }


            if (MessageBox.Show("Do you wish to delete " + listSymbols.Count + " group(s) [" + list + "] ?", "Deleting groups", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                foreach (var item in listSymbols)
                {
                    if (!ClientDatabaseManager.CurrentDbIsShared)
                    {
                        ClientDatabaseManager.DeleteGroupForUser(_userID,
                                                                 _groups.Find(a => a.GroupName == item).GroupId, ApplicationType.TickNet.ToString());
                    }

                    if (ClientDatabaseManager.CurrentDbIsShared)
                    {
                        var groupId = _allGroups.Find(a => a.GroupName == item).GroupId;
                        if (ClientDatabaseManager.IsGroupOnlyForThisUser(groupId))
                        {
                            ClientDatabaseManager.DeleteGroupOfSymbols(groupId);
                        }
                        ClientDatabaseManager.DeleteGroupForUser(_userID, groupId, ApplicationType.TickNet.ToString());
                    }
                }

                RefreshGroups();
                ToastNotification.Show(this, listSymbols.Count + " group(s) [" + list + "] deleted");
                OnUpdateGroupsEvent();
            }
        }
Ejemplo n.º 22
0
        static void _cel_InstrumentSubscribed(string symbol, CQGInstrument cqgInstrument)
        {
            if (_symbolsInProgress.Exists(oo => oo.Name == symbol))
            {
                var item = _symbolsInProgress.Find(oo => oo.Name == symbol);
                item.Description   = "Subscribed.";
                item.CqgInstrument = cqgInstrument;
                item.TickData      = new TickData(ClientDatabaseManager.GetTableTsName(symbol), symbol);
                item.DomData       = new DomDataModel(ClientDatabaseManager.GetTableTsName(symbol), symbol);

                ClientDatabaseManager.CreateLiveTableTs(symbol);
                ClientDatabaseManager.CreateLiveTableDm(symbol);

                OnSymbolSubscribed(item.Name, item.Depth);
                RefreshSubscribedSymbolOnUi();
            }
        }
Ejemplo n.º 23
0
        //*** UI


        private void MissingBarRequest(CQGCEL cel, List <string> symbols, int maxCount, bool isAuto = false)
        {
            if (_shouldStop)
            {
                return;
            }
            _maxBarsLookBack = Math.Abs(maxCount);
            _symbolState.Clear();

            ClientDatabaseManager.CreateMissingBarExceptionTable();
            ClientDatabaseManager.CreateSessionHolidayTimesTable();
            ClientDatabaseManager.CreateFullReportTable();

            _semaphoreGettingSessionData = new Semaphore(0, 1);


            foreach (string smb in symbols)
            {
                OnMissingBarStart(smb);
            }


            // Store Holidays
            new Thread(() =>
            {
                Thread.CurrentThread.Name = "AsyncGetingSessionsDataThread";
                StartAsyncGetingSessionsData(cel, symbols);
                _semaphoreGettingSessionData.Release();
            }).Start();

            // Finding Missed bars
            new Thread(() =>
            {
                Thread.CurrentThread.Name = "AsyncCheckingMissedBarsThread";
                _semaphoreGettingSessionData.WaitOne();
                if (isAuto)
                {
                    StartAsyncCheckingMissedBarsAuto(symbols, _maxBarsLookBack);
                }
                else
                {
                    StartAsyncCheckingMissedBars(symbols);
                }
            }).Start();
        }
Ejemplo n.º 24
0
        public HttpResponseMessage TestConnectionString(string connectionString)
        {
            string result = string.Empty;
            HttpResponseMessage httpResponseMessage = null;

            result = ClientDatabaseManager.TestConnectionString(connectionString);

            if (string.IsNullOrEmpty(result))
            {
                httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                httpResponseMessage = Request.CreateErrorResponse(HttpStatusCode.BadRequest, result);
            }

            return(httpResponseMessage);
        }
Ejemplo n.º 25
0
        private void LoadSymbols()
        {
            var symbolsList = ClientDatabaseManager.GetSymbolsInGroup(GroupId);

            foreach (var symbol in symbolsList)
            {
                var exist = false;
                foreach (var item in lbSelList.Items)
                {
                    if (item.ToString() == symbol.SymbolName)
                    {
                        exist = true;
                    }
                }
                if (!exist)
                {
                    lbSelList.Items.Add(symbol.SymbolName);
                }
            }
        }
Ejemplo n.º 26
0
        private static void TickScheduler()
        {
            for (int index = 0; index < _groups.Count; index++)
            {
                var groupModel = _groups[index].GroupModel;

                /* if (DateTime.Now.Minute == DateTime.Today.Minute && DateTime.Now.Hour == DateTime.Today.Hour)
                 * {
                 *   groupModel.End = new DateTime();
                 *   DatabaseManager.SetGroupEndDatetime(groupModel.GroupId, new DateTime());
                 * }*/
                var sess = ClientDatabaseManager.GetSessionsInGroup(groupModel.GroupId);
                //
                bool any = false;
                foreach (SessionModel ss in sess)
                {
                    if (IsNowAGoodDay(ss.Days))
                    {
                        if (ss.TimeStart.Hour == DateTime.Now.Hour && ss.TimeStart.Minute == DateTime.Now.Minute)
                        {
                            if ((DateTime.Now - groupModel.End).TotalMinutes > 1)
                            {
                                any = true;
                                Console.WriteLine("Start collecting! Last collecting was at: " + (TrimSeconds(groupModel.End).ToString()) + " Now: " + DateTime.Now.ToString());

                                break;
                            }
                        }
                    }
                }
                if (groupModel.IsAutoModeEnabled && (any))//startToday
                {
                    if (_groups[index].GroupState == GroupState.NotInQueue || _groups[index].GroupState == GroupState.Finished)
                    {
                        _groups[index].GroupState = GroupState.InQueue;
                        OnItemStateChanged(index, GroupState.InQueue);
                    }
                }
            }
            Start();
        }
Ejemplo n.º 27
0
        private void ui_listBox_groups_SelectedIndexChanged(object sender, EventArgs e)
        {
            //ui_listBox_symbolsInGroup.Items.Clear();
            ui_buttonX_delGroup.Enabled  = true;
            ui_buttonX_editGroup.Enabled = true;
            ui_buttonX_join.Enabled      = true;
            if (ui_listBox_groups.SelectedItems.Count <= 0)
            {
                return;
            }

            var privilege = new GroupPrivilege();
            int groupId   = 0;

            for (int i = 0; i < ui_listBox_groups.SelectedItems.Count; i++)
            {
                var groupName = ui_listBox_groups.SelectedItems[i].ToString();

                groupId   = _groups.Find(a => a.GroupName == groupName).GroupId;
                privilege = ClientDatabaseManager.GetUserPrivilegeForGroup(groupId, _userID, ApplicationType.DataNet.ToString());

                if (privilege != GroupPrivilege.Creator)
                {
                    ui_buttonX_delGroup.Enabled  = false;
                    ui_buttonX_editGroup.Enabled = false;
                    ui_buttonX_join.Enabled      = false;
                }
            }

            /*
             * if (ui_listBox_groups.SelectedItems.Count == 1 && privilege != GroupPrivilege.UseGroup)
             * {
             *  var symbolsForCurrGroup = DatabaseManager.GetSymbolsInGroup(groupId);
             *
             *  foreach (var symbolModel in symbolsForCurrGroup)
             *  {
             *      ui_listBox_symbolsInGroup.Items.Add(symbolModel.SymbolName);
             *  }
             * }*/
        }
Ejemplo n.º 28
0
        static void CQG_var_InstrumentChanged(CQGInstrument cqgInstrument, CQGQuotes cqgQuotes,
                                              CQGInstrumentProperties cqgInstrumentProperties)
        {
            double qtIndicativeOpen = -1;
            double qtSettlement     = -1;
            double qtMarker         = -1;
            double qtTodayMarker    = -1;
            //var dailyValueModel=new DailyValueModel();
            // var prop=cqgInstrument.Properties[ep]
            var quote = cqgInstrument.Quotes[eQuoteType.qtIndicativeOpen];

            if (quote != null && quote.IsValid)
            {
                qtIndicativeOpen = quote.Price;
            }
            quote = cqgInstrument.Quotes[eQuoteType.qtSettlement];
            if (quote != null && quote.IsValid)
            {
                qtSettlement = quote.Price;
            }
            quote = cqgInstrument.Quotes[eQuoteType.qtMarker];
            if (quote != null && quote.IsValid)
            {
                qtMarker = quote.Price;
            }
            quote = cqgInstrument.Quotes[eQuoteType.qtTodayMarker];
            if (quote != null && quote.IsValid)
            {
                qtTodayMarker = quote.Price;
            }


            ClientDatabaseManager.AddDailyValue(qtIndicativeOpen, qtMarker, qtSettlement, qtTodayMarker, cqgInstrument.FullName, DateTime.Today, cqgInstrument.ExpirationDate);
            _cqgVar.RemoveInstrument(cqgInstrument);
            SubscribedSymbol.Remove(cqgInstrument.FullName);


            //To DB
        }
Ejemplo n.º 29
0
        public static void UpdateDailyValues(List <string> symbols)
        {
            if (!_cqgIsStarted)
            {
                return;
            }

            foreach (var symbol in symbols)
            {
                if (!ClientDatabaseManager.IfTodayWeHadSettingDailyValue(symbol) && !SubscribedSymbol.Contains(symbol))
                {
                    // _subscribedSymbol.Add(symbol);
                    if (IsNoCont(symbol))
                    {
                        _cqgVar.NewInstrument(symbol);
                    }
                    else
                    {
                        _cqgVar.NewInstrument(symbol + (Settings.Default.IsAdditionalTextReuired?Settings.Default.AdditionalText:""));
                    }
                }
            }
        }
Ejemplo n.º 30
0
        private void StartAsyncGetingSessionsData(CQGCEL cel, List <string> symbols)
        {
            for (int i = 0; i < symbols.Count(); i++)
            {
                var symbol = symbols[i];

                var progress = (i * (50 / symbols.Count()));
                OnProgress(progress);

                _aSemaphoreHolidays = new Semaphore(0, 1);
                _aSemaphoreSessions = new Semaphore(0, 1);

                List <DateTime> aResultDateTimes = ClientDatabaseManager.GetAllDateTimes(ClientDatabaseManager.GetTableFromSymbol(symbol));

                if (aResultDateTimes == null || aResultDateTimes.Count == 0)
                {
                    continue;
                }

                var rangeBegin = aResultDateTimes.First();
                var rangeEnd   = aResultDateTimes.Last();
                var req        = cel.CreateHistoricalSessionsRequest();


                req.Type       = eHistoricalSessionsRequestType.hsrtTimeRange;
                req.Symbol     = symbol;
                req.RangeStart = rangeBegin;
                req.RangeEnd   = rangeEnd;

                cel.RequestHistoricalSessions(req);
                _aSemaphoreHolidays.WaitOne(20000);// wait


                cel.NewInstrument(symbol);
                _aSemaphoreSessions.WaitOne(20000);// wait
            }
        }