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 <ChartLayoutModel> GetDefaultLayoutAsync(QuotePeriod period) { var result = new ChartLayoutModel(); using (var scope = _container.BeginLifetimeScope()) { var repository = scope.Resolve <IChartLayoutRepository>(); var layout = await repository.GetDefaultAsync(period); if (layout == null) { return(result); } result.LayoutId = layout.LayoutId; result.Deleted = layout.Deleted; result.Title = layout.Title; //result.Period = layout.Period; result.Default = layout.Default; result.Description = layout.Description; result.Plots = await GetChartPlotsForLayout(scope, result.LayoutId); } return(result); }
public async Task <IList <ChartLayoutModel> > GetLayoutsForPeriodAsync(QuotePeriod period) { var result = new List <ChartLayoutModel>(); using (var scope = _container.BeginLifetimeScope()) { var repository = scope.Resolve <IChartLayoutRepository>(); var layouts = await repository.GetForPeriodAsync(period); if (layouts == null || !layouts.Any()) { return(result); } result.AddRange(layouts.Select(layout => new ChartLayoutModel { LayoutId = layout.LayoutId, Deleted = layout.Deleted, Title = layout.Title, //Period = layout.Period, Default = layout.Default, Description = layout.Description })); foreach (var layout in result) { layout.Plots = await GetChartPlotsForLayout(scope, layout.LayoutId); } } return(result); }
public async Task <IChartLayoutEntity> GetDefaultAsync(QuotePeriod period) { //var record = await Dbset.FirstOrDefaultAsync(r => r.Period == period && r.Default) ?? // await Dbset.FirstOrDefaultAsync(r => r.Period == period); //return record; throw new NotImplementedException(); }
public static string BuildHistoricalQuotesUrl(string symbol, QuotePeriod period, QuoteTimeFrame timeFrame, int timeFrameValue) { return string.Format("api/hist/{0}/{1}/{2}-{3}", symbol.ToLower(), period.ToString().ToLower(), timeFrameValue, timeFrame.ToString().ToLower() ); }
public async Task <List <Indicator> > GetIndicatorsAsync(QuotePeriod period) { using (var scope = _container.BeginLifetimeScope()) { var repository = scope.Resolve <IIndicatorRepository>(); var entities = await repository.GetAllAsync(period); return(entities); } }
public async Task <List <Rule> > GetRules(QuotePeriod period) { using (var scope = _container.BeginLifetimeScope()) { var repository = scope.Resolve <IRuleRepository>(); var entities = await repository.GetAllAsync(period, false); return(entities); } }
public async Task <List <RuleSet> > GetRuleSetsAsync(QuotePeriod period, bool includeDeleted) { using (var scope = _container.BeginLifetimeScope()) { var repository = scope.Resolve <IRuleSetRepository>(); var entities = await repository.GetAsync(period, includeDeleted); return(entities); } }
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(); }
private ChartData CalculateChartData(QuotePeriod period) { var maxPeriod = _configuration.Indicators.Where(i => i.Period == period).Max(p => p.Params.Max(c => c.Value)); var quotes = CalculateVirtualPeriod(period, maxPeriod); var indicators = CalculateIndicators(quotes, _configuration.Indicators.Where(i => i.Period == period).ToList()); return(new ChartData() { Quotes = quotes.Take(Bars).ToList(), Indicators = indicators, Period = period }); }
public async Task <IList <IChartIndicatorEntity> > GetForPeriodAsync(QuotePeriod period) { const string query = @" SELECT I.* FROM dbo.ChartLayout L INNER JOIN dbo.ChartIndicator I ON L.PlotId = I.PlotId WHERE L.Deleted = 0 AND L.Period = @Period "; var records = await Dbset.SqlQuery(query, new object[] { new SqlParameter("@Period", (int)period) }).ToListAsync(); return(records.Select(r => r as IChartIndicatorEntity).ToList()); }
private List <QuotesModel> CalculateVirtualPeriod(QuotePeriod period, int virtualOffset) { switch (period) { case QuotePeriod.Daily: return(_configuration.Quotes.Where(q => q.Date <= CurrentDate).Take(Bars + virtualOffset).ToList()); case QuotePeriod.Weekly: return(_configuration.Quotes.Where(q => q.Date <= CurrentDate).ToList().ToWeeekly().Take(Bars + virtualOffset).ToList()); default: throw new ArgumentOutOfRangeException(nameof(period), period, null); } }
public async Task<IHttpActionResult> Get(string symbol, QuotePeriod period, int bars) { var quotes = await _storageClient.LoadAsync(new LoadHistoricalQuotesRequest(symbol, period)); if (quotes == null) { return await Update(symbol, period, bars); } if (quotes.Quotes != null && quotes.Quotes.Any()) { return Ok(quotes); } return NotFound(); }
public async Task <List <StrategyRuleSet> > GetAsync(int strategyId, QuotePeriod period) { var query = @" SELECT S.*, R.[Name] FROM [dbo].[RuleSet] R INNER JOIN [dbo].[StrategyRuleSet] S ON R.[RuleSetId] = S.[RuleSetId] WHERE S.[StrategyId] = @strategyId AND R.[Period] = @period ORDER BY S.OrderId"; var records = await DbContext.Database.SqlQuery <StrategyRuleSet>(query, new SqlParameter("@strategyId", strategyId), new SqlParameter("@period", (int)period)).ToListAsync(); return(records); }
public async Task <List <RuleSetModel> > GetRuleSetsAsync(QuotePeriod period) { using (var scope = _container.BeginLifetimeScope()) { var repository = scope.Resolve <IVRuleSetRepository>(); var data = (await repository.GetAllAsync(period, false)).Select(c => c as IRuleSetView).ToList(); var result = new List <RuleSetModel>(); foreach (var item in data) { if (result.All(r => r.RuleSetId != item.RuleSetId)) { result.Add(new RuleSetModel(data, item.RuleSetId)); } } return(result); } }
public GetQuotesRequest(string symbol, QuotePeriod period, int bars) { Symbol = symbol; Period = period; Bars = bars; DateTime startDate = DateTime.UtcNow; switch (period) { case QuotePeriod.Daily: startDate = startDate.AddDays(-(int) (bars*1.36)); break; case QuotePeriod.Weekly: startDate = startDate.AddDays(-(bars * 7)); break; } var totalYears = DateTime.Today.Year - startDate.Year; if (totalYears > 5) { TimeFrame = QuoteTimeFrame.Year; TimeFrameValue = 5; } else { var totalMonths = totalYears * 12 + DateTime.Today.Month - startDate.Month; if (totalMonths < 12) { TimeFrame = QuoteTimeFrame.Month; TimeFrameValue = totalMonths > 0 ? totalMonths : 1; } else { TimeFrame = QuoteTimeFrame.Year; TimeFrameValue = totalYears; } } }
public StoreHistoricalQuotesRequest(string symbol, QuotePeriod period, HistoricalQuotes data) : base(symbol, period) { Data = data; }
public async Task <List <Indicator> > GetAllAsync(QuotePeriod period) { var records = await Dbset.Where(r => r.Period == period && !r.Deleted && !r.Global).OrderBy(r => r.Name).ToListAsync(); return(records); }
public async Task <List <vRuleSet> > GetAllAsync(QuotePeriod period, bool includeDeleted) { var records = await Dbset.Where(r => r.Period == (int)period && (!r.Deleted || includeDeleted)).OrderBy(r => r.RuleName).ThenBy(r => r.OrderId).ToListAsync(); return(records); }
public LoadHistoricalQuotesRequest(string symbol, QuotePeriod period) { _symbol = symbol; _period = period; }
public async Task <List <RuleSet> > GetAsync(QuotePeriod period, bool includeDeleted) { var records = await Dbset.Where(r => !r.Deleted || includeDeleted && r.Period == period).OrderBy(r => r.Name).ToListAsync(); return(records); }
public async Task <IList <IChartLayoutEntity> > GetForPeriodAsync(QuotePeriod period) { //var records = await Dbset.Where(r => r.Period == period).ToListAsync(); //return records.Select(r => r as IChartLayoutEntity).ToList(); throw new NotImplementedException(); }
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 async Task <List <StrategyRuleSet> > GetStrategyRuleSetsAsync(int strategyId, QuotePeriod period) { using (var scope = _container.BeginLifetimeScope()) { var repository = scope.Resolve <IStrategyRuleSetRepository>(); var entities = await repository.GetAsync(strategyId, period); return(entities); } }