Exemplo n.º 1
0
        public StrategyViewModel(ITreeViewModel parent, StrategyModel model, MarketsModel markets, SettingModel settings)
        {
            _parent   = parent;
            Model     = model ?? throw new ArgumentNullException(nameof(model));
            _markets  = markets;
            _settings = settings;

            StartCommand                = new RelayCommand(() => DoStartCommand(), () => !IsBusy && !Active);
            StopCommand                 = new RelayCommand(() => DoStopCommand(), () => !IsBusy && Active);
            CloneCommand                = new RelayCommand(() => DoCloneStrategy(), () => !IsBusy);
            CloneAlgorithmCommand       = new RelayCommand(() => DoCloneAlgorithm(), () => !IsBusy && !string.IsNullOrEmpty(Model.AlgorithmLocation));
            ExportCommand               = new RelayCommand(() => DoExportStrategy(), () => !IsBusy);
            DeleteCommand               = new RelayCommand(() => DoDeleteStrategy(), () => !IsBusy);
            DeleteAllTracksCommand      = new RelayCommand(() => DoDeleteTracks(null), () => !IsBusy);
            DeleteSelectedTracksCommand = new RelayCommand <IList>(m => DoDeleteTracks(m), m => !IsBusy);
            UseParametersCommand        = new RelayCommand <IList>(m => DoUseParameters(m), m => !IsBusy);
            AddSymbolCommand            = new RelayCommand(() => DoAddSymbol(), () => !IsBusy);
            DeleteSymbolsCommand        = new RelayCommand <IList>(m => DoDeleteSymbols(m), m => !IsBusy && SelectedSymbol != null);
            ImportSymbolsCommand        = new RelayCommand(() => DoImportSymbols(), () => !IsBusy);
            ExportSymbolsCommand        = new RelayCommand <IList>(m => DoExportSymbols(m), trm => !IsBusy && SelectedSymbol != null);
            TrackDoubleClickCommand     = new RelayCommand <TrackViewModel>(m => DoSelectItem(m), m => !IsBusy);
            MoveUpSymbolsCommand        = new RelayCommand <IList>(m => OnMoveUpSymbols(m), m => !IsBusy && SelectedSymbol != null);
            MoveDownSymbolsCommand      = new RelayCommand <IList>(m => OnMoveDownSymbols(m), m => !IsBusy && SelectedSymbol != null);
            SortSymbolsCommand          = new RelayCommand(() => Symbols.Sort(), () => !IsBusy);
            MoveStrategyCommand         = new RelayCommand <ITreeViewModel>(m => OnMoveStrategy(m), m => !IsBusy);
            DropDownOpenedCommand       = new RelayCommand(() => DoDropDownOpenedCommand(), () => !IsBusy);

            Model.NameChanged          += StrategyNameChanged;
            Model.AlgorithmNameChanged += AlgorithmNameChanged;
            DataFromModel();

            Model.EndDate = DateTime.Now;
            Debug.Assert(IsUiThread(), "Not UI thread!");
        }
        public MarketsViewModel(MarketsModel markets, SettingModel settings)
        {
            Model     = markets;
            _settings = settings;

            AddCommand             = new RelayCommand(() => DoAddMarket(), () => !IsBusy);
            SelectedChangedCommand = new RelayCommand <ITreeViewModel>((vm) => DoSelectedChanged(vm), (vm) => !IsBusy && vm != null);

            DataFromModel();
        }
        public StrategiesViewModel(StrategiesModel strategies, MarketsModel markets, AccountsModel accounts, SettingModel settings)
        {
            Model     = strategies;
            _markets  = markets;
            _accounts = accounts;
            _settings = settings;

            AddCommand             = new RelayCommand(() => DoAddStrategy(), () => !IsBusy);
            ImportCommand          = new RelayCommand(() => DoImportStrategies(), () => !IsBusy);
            ExportCommand          = new RelayCommand(() => DoExportStrategies(), () => !IsBusy);
            SelectedChangedCommand = new RelayCommand <ITreeViewModel>((vm) => DoSelectedChanged(vm), (vm) => !IsBusy);

            DataFromModel();
        }
Exemplo n.º 4
0
        public StrategiesViewModel(StrategiesModel strategies, MarketsModel markets, SettingModel settings)
        {
            Model     = strategies;
            _markets  = markets;
            _settings = settings;

            AddCommand             = new RelayCommand(() => DoAddStrategy(), () => !IsBusy);
            ImportCommand          = new RelayCommand(() => DoImportStrategies(), () => !IsBusy);
            ExportCommand          = new RelayCommand(() => DoExportStrategies(), () => !IsBusy);
            SelectedChangedCommand = new RelayCommand <ITreeViewModel>((vm) => DoSelectedChanged(vm), (vm) => !IsBusy && vm != null);

            DataFromModel();
            Debug.Assert(IsUiThread(), "Not UI thread!");
        }
Exemplo n.º 5
0
        private static IEnumerable <MarketModel> GetExternalMarketsFeed()
        {
            try
            {
                using HttpClient client = new HttpClient();
                HttpResponseMessage response = client.GetAsync("https://raw.githubusercontent.com/GeorgeLeithead/LiLo.Markets/main/Markets.json").Result;                 // Want to do this synchronously to ensure that we don't start anything else until this is complete!
                if (response.IsSuccessStatusCode)
                {
                    string marketsJson = response.Content.ReadAsStringAsync().Result;
                    if (!string.IsNullOrEmpty(marketsJson))
                    {
                        MarketsModel markets = JsonSerializer.Deserialize <MarketsModel>(marketsJson);
                        marketsData = markets.Markets.ToList();
                        return(marketsData.OrderBy(n => n.Rank));
                    }
                }
            }
            catch (HttpRequestException)
            {
                throw;
            }

            throw new HttpRequestException("No markets data found!");
        }
Exemplo n.º 6
0
        internal static IEnumerable <MarketModel> GetExternalMarketsFeed()
        {
            string versionMarketsJsonFile = string.Format(Constants.Sources.MarketFeed.Versioned, Version);

            try
            {
                string            droidSource       = null;
                string            iosSource         = null;
                HttpClientHandler httpClientHandler = new()
                {
                    ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); }
                };
                using HttpClient client = new(httpClientHandler);
                HttpResponseMessage response = client.GetAsync(versionMarketsJsonFile).Result;                 // Want to do this synchronously to ensure that we don't start anything else until this is complete!
                if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    response = client.GetAsync(Constants.Sources.MarketFeed.Default).Result;                     // Want to do this synchronously to ensure that we don't start anything else until this is complete!
                }

                if (response.IsSuccessStatusCode)
                {
                    string marketsJson = response.Content.ReadAsStringAsync().Result;
                    if (!string.IsNullOrEmpty(marketsJson))
                    {
                        MarketsModel markets = JsonSerializer.Deserialize <MarketsModel>(marketsJson);
                        if (string.IsNullOrEmpty(markets.IconSourceDroid))
                        {
                            droidSource = Constants.Sources.Icons.DroidSource;
                            iosSource   = Constants.Sources.Icons.IosSource;
                        }
                        else
                        {
                            droidSource = markets.IconSourceDroid;
                            iosSource   = markets.IconSourceIos;
                        }

                        marketsData = markets.Markets.OrderBy(n => n.Rank).ToList();
                    }
                }

                if (marketsData.Count > 0)
                {
                    string imageSource = null;
                    switch (Device.RuntimePlatform)
                    {
                    case Device.iOS:
                        imageSource = iosSource;
                        break;

                    case Device.UWP:
                        break;

                    default:
                        imageSource = droidSource;
                        break;
                    }

                    foreach (MarketModel market in marketsData)
                    {
                        market.SymbolImage = new UriImageSource
                        {
                            Uri            = new Uri(string.Format(imageSource, market.SymbolString.ToLowerInvariant())),
                            CachingEnabled = true,
                            CacheValidity  = TimeSpan.FromDays(Constants.Sources.Icons.CacheDuration)
                        };
                    }
                }

                return(marketsData);
            }
            catch (HttpRequestException)
            {
                throw;
            }

            throw new HttpRequestException(Resources.AppResources.ErrorNoMarkets);
        }
 public MarketNameConverter()
 {
     _markets = SimpleIoc.Default.GetInstance <MarketsModel>();
 }