private void Search()
        {
            Instruments.Clear();
            var contract = new Contract
            {
                Symbol         = SymbolTextBox.Text,
                SecurityType   = TWSUtils.SecurityTypeConverter((InstrumentType)InstrumentTypeBox.SelectedItem),
                Exchange       = ExchangeBox.Text == "All" ? "" : ExchangeBox.Text,
                IncludeExpired =
                    IncludeExpiredCheckBox.IsChecked != null && (bool)IncludeExpiredCheckBox.IsChecked
            };

            if (Expirationpicker.SelectedDate.HasValue)
            {
                contract.Expiry = Expirationpicker.SelectedDate.Value.ToString("yyyyMM");
            }

            if (StrikeTextBox.Text != "")
            {
                double strike;
                bool   success = double.TryParse(StrikeTextBox.Text, out strike);
                if (success)
                {
                    contract.Strike = strike;
                }
            }

            _client.RequestContractDetails(_nextRequestID, contract);
        }
Exemplo n.º 2
0
        protected override void OnSubscribe(Instrument instrument)
        {
            // Get size of bar.
            barSize = (long)Global[barSizeCode];

            // Get spread instrument.
            spread = instrument;

            // Add legs instruments to bar factory.
            foreach (Leg leg in spread.Legs)
            {
                BarFactory.Add(leg.Instrument, BarType.Time, barSize);
            }

            // Remove instruments from strategy.
            Instruments.Clear();

            // Add legs instruments to strategy.
            foreach (Leg leg in spread.Legs)
            {
                AddInstrument(leg.Instrument);
            }

            processors = new System.Collections.Generic.LinkedList <OrderProcessor>();
            groups     = new Dictionary <Instrument, Group[]>();

            AddGroups();
        }
Exemplo n.º 3
0
 private void ReadInstruments(Stream stream)
 {
     Instruments.Clear();
     for (uint i = 0; i < numberOfInstruments; i++)
     {
         XM_Instrument inst = new XM_Instrument();
         Instruments.Add(inst);
         inst.ReadFromStream(stream, ref i);
     }
 }
Exemplo n.º 4
0
 private void ReadInstruments(Stream stream)
 {
     Instruments.Clear();
     for (uint i = 0; i < numberOfSamples; i++)
     {
         MOD_Instrument inst = new MOD_Instrument();
         Instruments.Add(inst);
         inst.ReadHeaderFromStream(stream, ref i);
     }
     DebugMes(InstrumentsToString());
 }
Exemplo n.º 5
0
        public void RefreshCollections()
        {
            Tags.Clear();
            Instruments.Clear();

            using (var context = new MyDBContext())
            {
                Tags.AddRange(context.Tags.ToList());

                var im = new InstrumentRepository(context);
                Instruments.AddRange(im.FindInstruments().Result);
            }
        }
        private void Search(int page = 1)
        {
            Instruments.Clear();
            int count            = 0;
            var foundInstruments = QuandlUtils.FindInstruments(SymbolTextBox.Text, out count, page);

            foreach (var i in foundInstruments)
            {
                i.Datasource   = _thisDS;
                i.DatasourceID = _thisDS.ID;
                i.Multiplier   = 1;
                Instruments.Add(i);
            }

            StatusLabel.Content = count + " contracts found";

            CurrentPageTextBox.Text = page.ToString();
        }
Exemplo n.º 7
0
        protected override void OnSubscribe(Instrument instrument)
        {
            spread            = instrument;
            futureInstrument  = spread.Legs[1].Instrument;
            currentInstrument = spread.Legs[0].Instrument;

            // Remove instruments from strategy.
            Instruments.Clear();

            // Add legs instruments to strategy.
            foreach (Leg leg in spread.Legs)
            {
                AddInstrument(leg.Instrument);
            }

            processors = new System.Collections.Generic.LinkedList <OrderProcessor>();

            //	AddGroups();
        }
Exemplo n.º 8
0
        async Task ExecuteLoadItemsCommand()
        {
            IsBusy = true;

            try
            {
                Instruments.Clear();
                var instruments = await InstrumentDataStore.GetItemsAsync(true);

                foreach (var instrument in instruments)
                {
                    Instruments.Add(instrument);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 9
0
 private void ExecuteSearch()
 {
     Instruments.Clear();
     SendContractDetailsRequest(Symbol);
 }
Exemplo n.º 10
0
 protected virtual void ClearNavigationProperties()
 {
     Instruments.Clear();
 }
Exemplo n.º 11
0
 public virtual void Dispose()
 {
     Instruments.Clear();
     Model = null;
 }
Exemplo n.º 12
0
        public override void Refresh()
        {
            //tags
            var selectedTags = Tags
                               .Where(x => x.IsChecked)
                               .Select(x => x.Item)
                               .ToList();

            Tags.Clear();

            foreach (var checkItem in Context
                     .Tags
                     .OrderBy(x => x.Name)
                     .ToList()
                     .Select(x => new CheckListItem <Tag>(x, selectedTags.Contains(x))))
            {
                Tags.Add(checkItem);
            }

            //strategies
            var selectedStrats = Strategies
                                 .Where(x => x.IsChecked)
                                 .Select(x => x.Item)
                                 .ToList();

            Strategies.Clear();

            foreach (var checkItem in Context
                     .Strategies
                     .OrderBy(x => x.Name)
                     .ToList()
                     .Select(x => new CheckListItem <Strategy>(x, selectedStrats.Contains(x))))
            {
                Strategies.Add(checkItem);
            }

            //Instruments
            if (Instruments.Count == 0)
            {
                //on first load we want all instruments selected, otherwise remember previous selection
                foreach (var checkItem in Context
                         .Instruments
                         .OrderBy(x => x.Symbol)
                         .ToList()
                         .Select(x => new CheckListItem <Instrument>(x, true)))
                {
                    Instruments.Add(checkItem);
                }
            }
            else
            {
                var selectedInstruments = Instruments
                                          .Where(x => x.IsChecked)
                                          .Select(x => x.Item)
                                          .ToList();
                Instruments.Clear();

                foreach (var checkItem in Context
                         .Instruments
                         .OrderBy(x => x.Symbol)
                         .ToList()
                         .Select(x => new CheckListItem <Instrument>(x, selectedInstruments.Contains(x))))
                {
                    Instruments.Add(checkItem);
                }
            }

            //benchmarks
            Benchmarks.Clear();
            foreach (Benchmark b in Context.Benchmarks.OrderBy(x => x.Name))
            {
                Benchmarks.Add(b);
            }

            //backtest results from the external data source
            BacktestSeries.Clear();
            if (Datasourcer.ExternalDataSource.Connected)
            {
                BacktestSeries.AddRange(
                    Datasourcer
                    .ExternalDataSource
                    .GetBacktestSeries());
            }
        }
Exemplo n.º 13
0
        public AddInstrumentBinanceViewModel(IDataClient client, IDialogCoordinator dialogCoordinator)
        {
            _client            = client;
            _dialogCoordinator = dialogCoordinator;

            //Create commands
            Load = ReactiveCommand.CreateFromTask(async _ =>
            {
                //load datasource
                var dsResult = await _client.GetDatasources().ConfigureAwait(true);
                if (dsResult.WasSuccessful)
                {
                    _thisDS = dsResult.Result.FirstOrDefault(x => x.Name == "Binance");
                }
                else
                {
                    _logger.Error("Could not find Binance datasource");
                    return;
                }

                //load instruments
                try
                {
                    var instruments = await BinanceUtils.GetInstruments(_thisDS);
                    foreach (var inst in instruments)
                    {
                        Instruments.Add(inst);
                        _allInstruments.Add(inst);
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Could not load symbols from binance");
                }
            });

            Search = ReactiveCommand.Create(() =>
            {
                Instruments.Clear();
                foreach (var i in _allInstruments.Where(x => string.IsNullOrEmpty(Symbol) || //case-insensitive Contains()
                                                        x.Symbol.IndexOf(Symbol, StringComparison.OrdinalIgnoreCase) >= 0))
                {
                    Instruments.Add(i);
                }
            });

            Add = ReactiveCommand.CreateFromTask <IList>(async selectedInstruments =>
            {
                int count = 0;

                foreach (Instrument instrument in selectedInstruments)
                {
                    instrument.Datasource   = _thisDS;
                    instrument.DatasourceID = _thisDS.ID;

                    var result = await _client.AddInstrument(instrument).ConfigureAwait(true);
                    if (await result.DisplayErrors(this, _dialogCoordinator).ConfigureAwait(true))
                    {
                        continue;
                    }

                    count++;
                    AddedInstruments.Add(result.Result);
                }

                Status = string.Format("{0}/{1} instruments added.", count, selectedInstruments.Count);
            });

            this.WhenAny(x => x.Symbol, x => x)
            .Select(x => new Unit())     //hack
            .InvokeCommand(Search);
        }
Exemplo n.º 14
0
        public AddInstrumentQuandlViewModel(IDataClient client, IDialogCoordinator dialogCoordinator, string authToken)
        {
            _client            = client;
            _dialogCoordinator = dialogCoordinator;

            //Create commands
            Load = ReactiveCommand.CreateFromTask(async _ =>
            {
                var dsResult = await _client.GetDatasources().ConfigureAwait(true);
                if (dsResult.WasSuccessful)
                {
                    _thisDS = dsResult.Result.FirstOrDefault(x => x.Name == "Quandl");
                }
                else
                {
                    _logger.Error("Could not find FRED datasource");
                }
            });

            var canSearch = this.WhenAnyValue(x => x.Symbol).Select(x => !string.IsNullOrEmpty(x));

            Search = ReactiveCommand.CreateFromTask(async _ =>
            {
                Status = "Searching...";

                Instruments.Clear();
                QuandlUtils.QuandlInstrumentSearchResult foundInstruments;
                try
                {
                    foundInstruments = await QuandlUtils.FindInstruments(Symbol, authToken, CurrentPage ?? 1).ConfigureAwait(true);
                }
                catch (Exception ex)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Error", ex.Message).ConfigureAwait(true);
                    return;
                }

                foreach (var i in foundInstruments.Instruments)
                {
                    i.Datasource   = _thisDS;
                    i.DatasourceID = _thisDS.ID;
                    i.Multiplier   = 1;
                    Instruments.Add(i);
                }

                Status = foundInstruments.Count + " contracts found";

                CurrentPage = CurrentPage ?? 1;
            }, canSearch);

            Add = ReactiveCommand.CreateFromTask <IList>(async selectedInstruments =>
            {
                int count = 0;

                foreach (Instrument instrument in selectedInstruments)
                {
                    instrument.Datasource   = _thisDS;
                    instrument.DatasourceID = _thisDS.ID;

                    var result = await _client.AddInstrument(instrument).ConfigureAwait(true);
                    if (await result.DisplayErrors(this, _dialogCoordinator).ConfigureAwait(true))
                    {
                        continue;
                    }

                    count++;
                    AddedInstruments.Add(result.Result);
                }

                Status = string.Format("{0}/{1} instruments added.", count, selectedInstruments.Count);
            });

            this.WhenAny(x => x.CurrentPage, x => x)
            .Select(x => new Unit())     //hack
            .InvokeCommand(Search);

            IncrementPage = ReactiveCommand.Create(() => CurrentPage == null ? 1 : CurrentPage++);
            DecrementPage = ReactiveCommand.Create(() => Math.Max(1, CurrentPage == null ? 1 : (int)CurrentPage--));
        }