public async Task<IHttpActionResult> Sync(string symbol, QuotePeriod period, int bars) { /* 1. Get JSON 2. Locate the Latest date 3. Get CSV for new data 4. Merge Quotes 5. Store as JSON 5. Return as JSON */ var storedQuotesResponse = _storageClient.Load(new LoadHistoricalQuotesRequest(symbol, period)); var liveQuotesRequest = new GetQuotesRequest(symbol, period, bars); var liveQuotesResponse = await _provider.GetQuotes(liveQuotesRequest); if (liveQuotesResponse.Quotes != null && liveQuotesResponse.Quotes.Any()) { var response = new HistoricalQuotes { Symbol = liveQuotesRequest.Symbol, Period = liveQuotesRequest.Period.ToString(), LastUpdated = DateTime.UtcNow, Quotes = liveQuotesResponse.Quotes }; response.Merge(storedQuotesResponse); _storageClient.Store(new StoreHistoricalQuotesRequest(symbol, period, response)); return Ok(); } return NotFound(); }
public async Task<IHttpActionResult> Live(string symbol, QuotePeriod period, int bars) { var liveQuotesRequest = new GetQuotesRequest(symbol, period, bars); var quotes = await _provider.GetQuotes(liveQuotesRequest); if (quotes.Quotes != null && quotes.Quotes.Any()) { return Ok(quotes); } return NotFound(); }
public async Task<GetQuotesResponse> GetQuotes(GetQuotesRequest request) { var content = await _client.Post(new NasdaqRequest { Symbol = request.Symbol, ResourceUrl = String.Format("symbol/{0}/historical", request.Symbol.ToLower()), TimeFrame = request.TimeFrame, TimeFrameValue = request.TimeFrameValue }); var quotes = _csvParser.Parse(content).ToList(); var total = quotes.Count; if (total > request.Bars) { quotes = quotes.Skip(total - request.Bars).Take(request.Bars).ToList(); } return new GetQuotesResponse() { Quotes = quotes }; }
public async Task<IHttpActionResult> Update(string symbol, QuotePeriod period, int bars) { var liveQuotesRequest = new GetQuotesRequest(symbol, period, bars) ; var liveQuotesResponse = await _provider.GetQuotes(liveQuotesRequest); if (liveQuotesResponse.Quotes != null && liveQuotesResponse.Quotes.Any()) { var response = new HistoricalQuotes { Symbol = liveQuotesRequest.Symbol, Period = liveQuotesRequest.Period.ToString(), LastUpdated = DateTime.UtcNow, Quotes = liveQuotesResponse.Quotes }; _storageClient.Store(new StoreHistoricalQuotesRequest(symbol, period, response)); return Ok(response); } return NotFound(); }