Ejemplo n.º 1
0
        private void ExchangeComboBox_OnSelectedIndexChanged(object sender, RoutedEventArgs e)
        {
            if (TheInstrument.SessionsSource == SessionsSource.Exchange)
            {
                SelectedSessions.Clear();

                foreach (ExchangeSession s in TheInstrument.Exchange.Sessions)
                {
                    SelectedSessions.Add(s.ToInstrumentSession());
                }
            }
        }
Ejemplo n.º 2
0
        private void FillSessionsFromTemplate()
        {
            SelectedSessions.Clear();

            var template = (SessionTemplate)TemplateComboBox.SelectedItem;

            if (template == null)
            {
                TheInstrument.SessionTemplateID = -1; //we can check for this later and deny the new instrument if its sessions are not set properly
                return;
            }

            TheInstrument.SessionTemplateID = template.ID;
            foreach (TemplateSession s in template.Sessions.OrderBy(x => x.OpeningDay))
            {
                SelectedSessions.Add(s.ToInstrumentSession());
            }
        }
Ejemplo n.º 3
0
        private void ExchangeRadioBtn_Checked(object sender, RoutedEventArgs e)
        {
            if (TheInstrument.Exchange == null)
            {
                return;
            }
            if (TheInstrument.SessionsSource == SessionsSource.Exchange)
            {
                return;                                                          //we don't want to re-load them if it's already set
            }
            SelectedSessions.Clear();
            TheInstrument.SessionsSource = SessionsSource.Exchange;

            foreach (ExchangeSession s in TheInstrument.Exchange.Sessions)
            {
                SelectedSessions.Add(s.ToInstrumentSession());
            }
        }
Ejemplo n.º 4
0
        private void AddSessionItemBtn_Click(object sender, RoutedEventArgs e)
        {
            var toAdd = new InstrumentSession {
                IsSessionEnd = true
            };

            if (SelectedSessions.Count == 0)
            {
                toAdd.OpeningDay = DayOfTheWeek.Monday;
                toAdd.ClosingDay = DayOfTheWeek.Monday;
            }
            else
            {
                DayOfTheWeek maxDay = (DayOfTheWeek)Math.Min(6, SelectedSessions.Max(x => (int)x.OpeningDay) + 1);
                toAdd.OpeningDay = maxDay;
                toAdd.ClosingDay = maxDay;
            }
            SelectedSessions.Add(toAdd);
        }
Ejemplo n.º 5
0
        private void DeleteSessionItemBtn_Click(object sender, RoutedEventArgs e)
        {
            var selectedSession = (InstrumentSession)SessionsGrid.SelectedItem;

            SelectedSessions.Remove(selectedSession);
        }
Ejemplo n.º 6
0
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            if (_addingNew &&
                _context.Instruments.Any(
                    x => x.DatasourceID == TheInstrument.DatasourceID &&
                    x.ExchangeID == TheInstrument.ExchangeID &&
                    x.Symbol == TheInstrument.Symbol &&
                    x.Expiration == TheInstrument.Expiration)
                )
            {
                //there's already an instrument with this key
                MessageBox.Show("Instrument already exists. Change datasource, exchange, or symbol.");
                return;
            }

            //check that if the user picked a template-based session set, he actually selected one of the templates
            if (TheInstrument.SessionsSource == SessionsSource.Template && TheInstrument.SessionTemplateID == -1)
            {
                MessageBox.Show("You must pick a session template.");
                return;
            }

            if (TheInstrument.IsContinuousFuture && TheInstrument.Type != InstrumentType.Future)
            {
                MessageBox.Show("Continuous futures type must be Future.");
                return;
            }

            if (TheInstrument.Datasource == null)
            {
                MessageBox.Show("You must select a data source.");
                return;
            }

            if (TheInstrument.Multiplier == null)
            {
                MessageBox.Show("Must have a multiplier value.");
                return;
            }

            //Validate the sessions
            if (SelectedSessions.Count > 0)
            {
                try
                {
                    MyUtils.ValidateSessions(SelectedSessions.ToList <ISession>());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }

            //move selected sessions to the instrument
            TheInstrument.Sessions.Clear();
            foreach (InstrumentSession s in SelectedSessions)
            {
                //need to attach?
                TheInstrument.Sessions.Add(s);
            }

            TheInstrument.Tags.Clear();

            foreach (Tag t in Tags.Where(x => x.IsChecked).Select(x => x.Item))
            {
                _context.Tags.Attach(t);
                TheInstrument.Tags.Add(t);
            }

            ContinuousFuture tmpCF = null;

            if (_addingNew)
            {
                if (TheInstrument.Exchange != null)
                {
                    _context.Exchanges.Attach(TheInstrument.Exchange);
                }
                if (TheInstrument.PrimaryExchange != null)
                {
                    _context.Exchanges.Attach(TheInstrument.PrimaryExchange);
                }
                _context.Datasources.Attach(TheInstrument.Datasource);

                if (TheInstrument.IsContinuousFuture)
                {
                    tmpCF = TheInstrument.ContinuousFuture; //EF can't handle circular references, so we hack around it
                    TheInstrument.ContinuousFuture   = null;
                    TheInstrument.ContinuousFutureID = null;
                }
                _context.Instruments.Add(TheInstrument);
            }
            else //simply manipulating an existing instrument
            {
                //make sure any "loose" sessions are deleted
                if (!_addingNew)
                {
                    foreach (InstrumentSession s in _originalSessions.Where(s => !TheInstrument.Sessions.Any(x => x.ID == s.ID)))
                    {
                        _context.InstrumentSessions.Remove(s);
                    }
                }
            }

            _context.Database.Connection.Open();
            _context.SaveChanges();

            if (tmpCF != null)
            {
                _context.UnderlyingSymbols.Attach(tmpCF.UnderlyingSymbol);

                TheInstrument.ContinuousFuture              = tmpCF;
                TheInstrument.ContinuousFuture.Instrument   = TheInstrument;
                TheInstrument.ContinuousFuture.InstrumentID = TheInstrument.ID.Value;
                _context.SaveChanges();
            }

            InstrumentAdded = true;
            Hide();
        }
 private void PlaySession()
 {
     PlaySessionWindow = new PlaySession(SelectedSessions.First());
     PlaySessionWindow.Show();
 }
 private void DeleteSelection()
 {
     DBUpdater.DeleteFromSelection(SelectedSessions);
     SessionsCollection = new SessionCollection(SessionsCollection.Where(x => !SelectedSessions.Contains(x)));
 }