예제 #1
0
        public AlphaVantageServiceFactory()
        {
            _httpClient = new HttpClient();
            var service = new AlphaVantageService(_httpClient, AppSettings, CacheService);

            Forex = service;
        }
예제 #2
0
        public async Task FunctionHandler()
        {
            // Get all the unique symbols
            var docs = await DynamoDbService.GetAllAsync <TimeSeries>();

            var timeSeries = FilterTimeSeries(docs);

            // Get the quotes for the unique symbols
            foreach (var t in timeSeries)
            {
                var symbol = await AlphaVantageService.GetSymbol(t, DateTime.Parse(t.date));

                // Save quotes to DynamoDB
                await DynamoDbService.SaveToDynamoAsync(symbol);
            }
        }
예제 #3
0
 public TestController(AlphaVantageService alphaVantageService, TaxeeService taxeeService, IMapper mapper)
 {
     this.alphaVantageService = alphaVantageService;
     this.taxeeService        = taxeeService;
     this.mapper = mapper;
 }
예제 #4
0
 /// <summary>
 /// Used for unit testing
 /// </summary>
 /// <param name="dynamoDbService"></param>
 /// <param name="alphaVantageService"></param>
 public Function(IDynamoDbService dynamoDbService, AlphaVantageService alphaVantageService)
 {
     AlphaVantageService = alphaVantageService;
     DynamoDbService     = dynamoDbService;
 }
예제 #5
0
        public async Task ShouldGetSymbol()
        {
            // ARRANGE
            const string symbol   = "TEST";
            const string name     = "Test Symbol";
            const string currency = "CAD";
            const string type     = "Equity";
            const string region   = "Toronto";
            var          date     = DateTime.UtcNow.ToString("yyyy-MM-dd");
            const string open     = "100.00";
            const string low      = "100.00";
            const string high     = "100.00";
            const string close    = "100.00";
            const string volume   = "1000000";

            var content    = $@"
                    {{
                        ""Meta Data"": {{
                                ""1. Information"": ""Daily Prices (open, high, low, close) and Volumes"",
                                ""2. Symbol"": ""{symbol}"",
                                ""3. Last Refreshed"": ""{DateTime.Today:yyyy-MM-dd}"",
                                ""4. Output Size"": ""Compact"",
                                ""5. Time Zone"": ""US/Eastern""
                            }},
                            ""Time Series (Daily)"": {{
                                ""{date}"": {{
                                    ""1. open"": ""{open}"",
                                    ""2. high"": ""{high}"",
                                    ""3. low"": ""{low}"",
                                    ""4. close"": ""{close}"",
                                    ""5. volume"": ""{volume}""
                                }}
                            }}
                    }}";
            var httpClient = MockHttpClient(content);

            var ssmClient = new Mock <AmazonSimpleSystemsManagementClient>();

            ssmClient.Setup(s => s.GetParameterAsync(It.IsAny <GetParameterRequest>(), CancellationToken.None))
            .ReturnsAsync(new GetParameterResponse
            {
                Parameter = new Parameter
                {
                    Value = "TestApiKey"
                }
            });

            var timeSeries = new TimeSeries
            {
                symbol    = symbol,
                name      = name,
                currency  = currency,
                type      = type,
                region    = region,
                date      = date,
                open      = decimal.Parse(open),
                low       = decimal.Parse(low),
                high      = decimal.Parse(high),
                close     = decimal.Parse(close),
                volume    = long.Parse(volume),
                createdAt = DateTime.UtcNow,
                updatedAt = DateTime.UtcNow
            };
            var today = DateTime.Today;

            // ACT
            var alphaVantageService = new AlphaVantageService(httpClient, ssmClient.Object);
            var results             = await alphaVantageService.GetSymbol(timeSeries, today);

            // ASSERT
            results.Count().Should().Be(1);
            results.First().Symbol.Should().Be(symbol);
            results.First().Name.Should().Be(name);
            results.First().Currency.Should().Be(currency);
            results.First().Type.Should().Be(type);
            results.First().Region.Should().Be(region);
            results.First().Date.Should().Be(date);
            results.First().Open.Should().Be(open);
            results.First().Low.Should().Be(low);
            results.First().High.Should().Be(high);
            results.First().Close.Should().Be(close);
            results.First().Volume.Should().Be(volume);
        }