コード例 #1
0
        public void WeightTest()
        {
            var categoryRepository = new InMemoryCategoryRepository();
            var category = categoryRepository.GetCategory("Security");
            var category2 = categoryRepository.GetCategory("Currency");
            var securityRepository = new InMemorySecurityRepository();
            var security = securityRepository.GetBySymbol("XSB.TO");
            var security2 = securityRepository.GetBySymbol("MSFT");

            using (var tokenManager = new QuestradeApiTokenManager(new Configuration()))
            {
                var api = new QuestradeService(tokenManager, securityRepository, categoryRepository);

                var weights = api.GetWeights(category, security);
                weights = api.GetWeights(category, security);
                weights = api.GetWeights(category, security2);
                weights = api.GetWeights(category2, security);
                weights = api.GetWeights(category2, security2);
            }
        }
コード例 #2
0
        private static ErrorCode QuickQuestradeWeightReportOperation(string portfolioName)
        {
            var portfolio = new Portfolio
            {
                Name = portfolioName
            };
            var categoryRepository = new InMemoryCategoryRepository();
            var securityCategory = categoryRepository.GetCategory("Security");
            var currencyCategory = categoryRepository.GetCategory("Currency");
            using (var tokenManager = new QuestradeApiTokenManager(Configuration))
            {
                var api = new QuestradeService(tokenManager, new InMemorySecurityRepository(), categoryRepository);
                portfolio.Accounts = api.GetAccounts();
                var weights = new List<CategoryWeight>();

                foreach (var account in portfolio.Accounts)
                {
                    account.Positions = api.GetPositions(account);
                    foreach (var position in account.Positions)
                    {
                        weights.AddRange(api.GetWeights(securityCategory, position.Security));
                        weights.AddRange(api.GetWeights(currencyCategory, position.Security));
                    }
                }

                var reporter = new StringWeightReporter(api);
                var report = reporter.GetReport(portfolio, new[] {securityCategory, currencyCategory}, weights.Distinct());

                Console.Write(report);
            }

            return ErrorCode.NoError;
        }