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 void Merge(HistoricalQuotes storedQuotesResponse)
 {
     var lastQoute = Quotes.LastOrDefault();
     if (lastQoute != null
         && storedQuotesResponse != null
         && storedQuotesResponse.Quotes != null
         && storedQuotesResponse.Quotes.Any())
     {
         Quotes.AddRange(
             storedQuotesResponse.Quotes
                 .Where(q => q.Date < lastQoute.Date)
                 .OrderByDescending(q => q.Date));
     }
 }
        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();
        }
 public StoreHistoricalQuotesRequest(string symbol, QuotePeriod period, HistoricalQuotes data)
     : base(symbol, period)
 {
     Data = data;
 }