public async Task HistoricalPriceNonZeroAsync(string symbol, ChartRange range = ChartRange.OneMonth, DateTime?date = null, QueryStringBuilder qsb = null) { var response = await sandBoxClient.StockPrices.HistoricalPriceAsync(symbol, range); Assert.IsNull(response.ErrorMessage); Assert.IsNotNull(response.Data); foreach (var ohlc in response.Data) { assertNotZeroIfNotNull(ohlc.open); assertNotZeroIfNotNull(ohlc.high); assertNotZeroIfNotNull(ohlc.low); assertNotZeroIfNotNull(ohlc.close); Assert.NotZero(ohlc.volume); assertNotZeroIfNotNull(ohlc.uOpen); assertNotZeroIfNotNull(ohlc.uHigh); assertNotZeroIfNotNull(ohlc.uLow); assertNotZeroIfNotNull(ohlc.uClose); Assert.NotZero(ohlc.uVolume.Value); } void assertNotZeroIfNotNull(decimal?num) { if (num != null) { Assert.NotZero(num.Value); } } }
public Candle[] GetCandles(TradingSymbol symbol, ChartRange range, DateTime to, int count) { var granularity = ConvertGranurality(range); var task = apiEndpoint.GetBidAskCandles(symbol.Symbol, granularity: granularity, count: count, end: to, includeFirst: true); return(task.Result.Select(oandaCandle => new Candle(oandaCandle.Time, oandaCandle.OpenAsk, oandaCandle.HighAsk, oandaCandle.LowAsk, oandaCandle.CloseAsk, oandaCandle.Volume)).ToArray()); }
public async Task ChartAsync(string symbol, ChartRange range = ChartRange._1m, DateTime?date = null, QueryStringBuilder qsb = null) { var response = await prodClient.Stock.ChartAsync(symbol, range, date, qsb); Assert.IsNotNull(response); Assert.GreaterOrEqual(response.Count(), 0); }
public Candle[] GetCandles(TradingSymbol symbol, ChartRange range, DateTime from, DateTime to) { if (candles.TryGetValue(range, out var value)) { var providingCandles = value.Where(c => c.Time >= from && c.Time <= to).ToArray(); ProvidedCandles.AddRange(providingCandles); return(providingCandles); } return(Array.Empty <Candle>()); }
public void SetCandle(ChartRange range, IEnumerable <Candle> candles) { if (this.candles.TryGetValue(range, out var value)) { value.AddRange(candles); } else { this.candles[range] = candles.ToList(); } }
public async Task HistoricalPriceAsync(string symbol, ChartRange range = ChartRange._1m, QueryStringBuilder qsb = null) { var response = await sandBoxClient.Stock.HistoricalPriceAsync(symbol, range); Assert.IsNull(response.ErrorMessage); Assert.IsNotNull(response.Data); Assert.GreaterOrEqual(response.Data.Count(), 1); Assert.IsNotEmpty(response.Data.First().date); Assert.Greater(response.Data.First().GetDateTimeInUTC(), DateTime.MinValue); }
public CandleChart(TradingSymbol symbol, ChartRange range, Candle[] candles) { foreach (var candle in candles) { latestCandle = candle; store.Enqueue(candle); } this.symbol = symbol; this.range = range; updateSnapshot(); }
public Candle[] GetCandles(TradingSymbol symbol, ChartRange range, DateTime to, int count) { if (candles.TryGetValue(range, out var value)) { var providingCandles = value.Where(c => c.Time <= to) .OrderByDescending(c => c.Time) .Take(count) .OrderBy(c => c.Time) .ToArray(); ProvidedCandles.AddRange(providingCandles); return(providingCandles); } return(Array.Empty <Candle>()); }
public ChartEntryEntity FindOrCreateEntry(TradingSymbol symbol, ChartRange range) { var entry = ChartEntries.Where(ce => ce.Symbol == symbol.Symbol && ce.Range == range).FirstOrDefault(); if (entry == null) { entry = new ChartEntryEntity() { Symbol = symbol.Symbol, Range = range, }; ChartEntries.AddAsync(entry); SaveChangesAsync(); } return(entry); }
public async Task <IEXResponse <IEnumerable <ChartResponse> > > ChartAsync(string symbol, ChartRange range = ChartRange._1m, DateTime?date = null, QueryStringBuilder qsb = null) { const string urlPattern = "stock/[symbol]/chart/[range]/[date]"; qsb = qsb ?? new QueryStringBuilder(); var pathNvc = new NameValueCollection { { "symbol", symbol }, { "range", range.ToString().Replace("_", string.Empty) }, { "date", date == null?DateTime.Now.ToString("yyyyMMdd") : ((DateTime)date).ToString("yyyyMMdd") } }; return(await _executor.ExecuteAsync <IEnumerable <ChartResponse> >(urlPattern, pathNvc, qsb)); }
public async Task HistoricalPriceNonZeroAsync(string symbol, ChartRange range = ChartRange._1m, DateTime?date = null, QueryStringBuilder qsb = null) { var response = await sandBoxClient.Stock.HistoricalPriceAsync(symbol, range); foreach (var ohlc in response.Data) { Assert.NotZero(ohlc.open); Assert.NotZero(ohlc.high); Assert.NotZero(ohlc.low); Assert.NotZero(ohlc.close); Assert.NotZero(ohlc.volume); Assert.NotZero(ohlc.uOpen); Assert.NotZero(ohlc.uHigh); Assert.NotZero(ohlc.uLow); Assert.NotZero(ohlc.uClose); Assert.NotZero(ohlc.uVolume); } }
public CandleChart GetChart(TradingSymbol symbol, ChartRange range) { var chartKey = Tuple.Create(symbol, range); if (charts.TryGetValue(chartKey, out var chartAndUpdater)) { return(chartAndUpdater.Item1); } var provider = candleProviderFactory(symbol, range); var chart = new CandleChart(symbol, range); var updater = new CandleChartUpdater(chart, store, provider); charts.Add(chartKey, Tuple.Create(chart, updater)); var now = currentTime; updater.Update(now, 100); return(chart); }
public ActionResult GetSymbolContent(int symbol_id, string main_chart_type, ChartRange chartRange, CandelRange candelRange, int portfolio_id = 0) { SymbolContentModel symbol_content = new SymbolContentModel(portfolio_id, symbol_id); symbol_content.Symbol_Dashboard = DashboardService.GetSymbolDashboard(portfolio_id, symbol_id, chartRange, candelRange, true); object data = symbol_content.GetDataInJSONFormat(main_chart_type); object data_series_main_chart = symbol_content.GetDataSeriesInfoForMainChart(main_chart_type); object data_view_main_chart = symbol_content.GetDataViewInfoForMainChartData(main_chart_type); object volume_chart_view = symbol_content.GetDataViewInfoForVolumeChart(main_chart_type); object date_range_selector_view = symbol_content.GetDataViewInfoForDateRangeSelector(main_chart_type); object[] data_indicators = symbol_content.GetDataInfoForChartIndicators(main_chart_type); object max_data_date = symbol_content.max_date.ToString("r"); object response = new { data = data, series_main_chart = data_series_main_chart, view_main_chart = data_view_main_chart, indicators = data_indicators, date_range_selector_view = date_range_selector_view, max_data_date = max_data_date, volume_chart_view = volume_chart_view }; var jsonResult = Json(response, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return(jsonResult); }
private async Task Update(List <PortfolioItem> items, ChartRange range) { ProgressRing.IsActive = true; PortfolioGrid.ItemsSource = null; using (var iexCloudClient = IEXCloudService.GetClient()) { foreach (var item in items) { // Needs to be inside the loop. // The IEXSharp ExecutorREST helper changes the QueryStringBuilder and blocks reuse. var queryStringBuilder = new IEXSharp.Helper.QueryStringBuilder(); queryStringBuilder.Add("chartCloseOnly", "true"); queryStringBuilder.Add("chartSimplify", "true"); var response = await iexCloudClient.StockPrices.HistoricalPriceAsync(item.Symbol, range, queryStringBuilder); if (response.ErrorMessage != null) { Console.WriteLine(response.ErrorMessage); } else { item.HistoricalPrices = response.Data; } } } PortfolioGrid.ItemsSource = items; await Task.Delay(1000); // Give the GridView some time to render the containers. PortfolioGrid.RegisterImplicitAnimations(); ProgressRing.IsActive = false; }
public async Task <IEXResponse <IEnumerable <HistoricalPriceResponse> > > HistoricalPriceAsync(string symbol, ChartRange range = ChartRange.OneMonth, QueryStringBuilder qsb = null) { const string urlPattern = "stock/[symbol]/chart/[range]"; var pathNvc = new NameValueCollection { { "symbol", symbol }, { "range", range.GetDescriptionFromEnum() }, }; return(await executor.ExecuteAsync <IEnumerable <HistoricalPriceResponse> >(urlPattern, pathNvc, qsb)); }
public static List <Candel> GetSymbolQuotes(int symbol_id, ChartRange chartRange, CandelRange candelRange, string user_type) { DateTime chartMinDate = DateTime.Now; DateTime today = DateTime.Now.Date; switch (chartRange) { case ChartRange.Month: chartMinDate = chartMinDate.AddMonths(-1); break; case ChartRange.ThreeMonths: chartMinDate = chartMinDate.AddMonths(-3); break; case ChartRange.SixMonths: chartMinDate = chartMinDate.AddMonths(-6); break; case ChartRange.Year: chartMinDate = chartMinDate.AddYears(-1); break; case ChartRange.ThreeYears: chartMinDate = chartMinDate.AddYears(-3); break; default: chartMinDate = DateTime.MinValue.AddDays(200); break; } List <Candel> candels = new List <Candel>(); using (ctaDBEntities entities = new ctaDBEntities()) { entities.Database.Connection.Open(); bool createCandel = false; Candel currentCandel = null; DateTime startDate = chartMinDate.AddDays(-200); List <Stock_Quote> quotes = entities.Stock_Quote.Where(s => s.stock_id == symbol_id && (s.date_round > startDate && (user_type != "FREE" || s.date_round < today))).OrderBy(sq => sq.date_round).ToList(); Stock_Quote quote = null; for (int i = 0; i < quotes.Count; i++) { quote = quotes[i]; currentCandel = (currentCandel != null) ? currentCandel : new Candel() { Date = quote.date_round, Open = quote.opening, Close = quote.closing, Minimun = quote.minimun, Maximun = quote.maximun, Volume = (double)quote.volume }; if (candelRange == CandelRange.Daily) { createCandel = true; } else if (candelRange == CandelRange.Weekly) { currentCandel.Minimun = (currentCandel.Minimun > quote.minimun) ? quote.minimun : currentCandel.Minimun; currentCandel.Maximun = (currentCandel.Maximun < quote.maximun) ? quote.maximun : currentCandel.Maximun; if (quote.date_round.DayOfWeek == DayOfWeek.Friday) { currentCandel.Close = quote.closing; currentCandel.Date = quote.date_round; createCandel = true; } } else { currentCandel.Minimun = (currentCandel.Minimun > quote.minimun) ? quote.minimun : currentCandel.Minimun; currentCandel.Maximun = (currentCandel.Maximun < quote.maximun) ? quote.maximun : currentCandel.Maximun; if (currentCandel.Date.Month != quote.date_round.Month) { createCandel = true; i--; } else { currentCandel.Date = quote.date_round; } } if (createCandel || i + 1 == quotes.Count) { currentCandel.Close = quote.closing; currentCandel.Visible = (currentCandel.Date >= chartMinDate.Date); candels.Add(currentCandel); currentCandel = null; createCandel = false; } } entities.Database.Connection.Close(); } return(candels); }
public async Task <IEXResponse <TechnicalIndicatorsResponse> > TechnicalIndicatorsAsync(string symbol, string indicator, ChartRange range, bool lastIndicator = false, bool indicatorOnly = false) { const string urlPattern = "stock/[symbol]/indicator/[indicator]"; var qsb = new QueryStringBuilder(); qsb.Add("range", range.GetDescriptionFromEnum()); qsb.Add("lastIndicator", lastIndicator); qsb.Add("indicatorOnly", indicatorOnly); var pathNvc = new NameValueCollection { { "symbol", symbol }, { "indicator", indicator } }; return(await executor.ExecuteAsync <TechnicalIndicatorsResponse>(urlPattern, pathNvc, qsb)); }
public async Task <IEXResponse <IEnumerable <HistoricalPriceResponse> > > HistoricalPriceAsync(string symbol, ChartRange range = ChartRange._1m, QueryStringBuilder qsb = null) { const string urlPattern = "stock/[symbol]/chart/[range]"; var pathNvc = new NameValueCollection { { "symbol", symbol }, { "range", range.ToString().Replace("_", string.Empty) }, }; return(await executor.ExecuteAsync <IEnumerable <HistoricalPriceResponse> >(urlPattern, pathNvc, qsb)); }
public async Task TechnicalIndicatorsAsyncTest(string symbol, string indicator, ChartRange range, bool lastIndicator = false, bool indicatorOnly = false) { var response = await sandBoxClient.StockResearch.TechnicalIndicatorsAsync(symbol, indicator, range, lastIndicator, indicatorOnly); Assert.IsNull(response.ErrorMessage); Assert.IsNotNull(response.Data); }
private Granularity ConvertGranurality(ChartRange range) { return((Granularity)(int)range); }
public SymbolDashboardModel(int portfolio_id, int symbol_id, string username, ChartRange chartRange, CandelRange candelRange, bool withQuotes) { // TODO: Complete member initialization this.portfolio_id = portfolio_id; this.symbol_id = symbol_id; this.Username = username; this.symbol_content = new SymbolContentModel(portfolio_id, symbol_id); this.symbol_content.Symbol_Dashboard = DashboardService.GetSymbolDashboard(portfolio_id, symbol_id, chartRange, candelRange, withQuotes); this.Indicators = DashboardService.GetIndicatorsDetails(); this.LastTimeSync = StockService.GetLastTimeSynchronized(symbol_id); }
public static IEnumerable <Candle> CreateRomdomCandles(DateTime from, DateTime to, ChartRange range) { var intRange = (int)range; var count = 0; for (var d = from; d <= to; d += TimeSpan.FromSeconds(intRange)) { count += 1; } var year2000 = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); Func <DateTime, double> func1 = d => (year2000 - d).TotalDays / 365; Func <double, double> func2 = x => Math.Cos(1 / 4 * Math.PI * x) + (Math.Cos(Math.PI * x) / 4) + (Math.Cos(3 * Math.PI * x) / 10) + (Math.Cos(30 * Math.PI * x) / 16); Func <int, DateTime> time = t => from + TimeSpan.FromSeconds(t); Func <DateTime, decimal> value = t => (decimal)func2(func1(t)); Func <DateTime, decimal> price = t => value(t) * 20 + 40; Func <DateTime, int> volume = t => (int)value(t) * 2 + 40; return(Enumerable.Range(0, count) .Select(i => new { open = from + TimeSpan.FromSeconds(i * intRange), close = from + TimeSpan.FromSeconds((i + 1) * intRange) }) .Select(oc => new { oc.open, oc.close, times = Enumerable.Range(0, intRange / 60) .Select(i => oc.open + TimeSpan.FromMinutes(i)) .ToArray() }) .Where(oc => oc.open.DayOfWeek != DayOfWeek.Saturday || oc.open.DayOfWeek != DayOfWeek.Sunday) .Select(oct => new { oct.open, oct.close, prices = oct.times.Select(t => price(t)).ToArray(), volumes = oct.times.Select(t => volume(t)).ToArray() }) .Select(ocpv => new Candle(ocpv.open, ocpv.prices.First(), ocpv.prices.Max(), ocpv.prices.Min(), ocpv.prices.Last(), ocpv.volumes.Sum()))); }
public static SymbolDashboard GetSymbolDashboard(int portfolio_id, int symbol_id, ChartRange chartRange, CandelRange candelRange, bool withQuotes) { bool indicatorUpdate, shapeUpdate; if (SymbolDashboardCache != null && SymbolDashboardCache.Portfolio_Id == portfolio_id && SymbolDashboardCache.Symbol_Id == symbol_id && false) { var indicators = DashboardService.GetSymbolIndicators(SymbolDashboardCache.Symbol, SymbolDashboardCache.Indicators.Count(), withQuotes, candelRange, out indicatorUpdate); var shapes = DashboardService.GetSymbolShapes(SymbolDashboardCache.Symbol, SymbolDashboardCache.Shapes.Count(), withQuotes, out shapeUpdate); SymbolDashboardCache.Indicators = indicatorUpdate ? indicators : SymbolDashboardCache.Indicators; SymbolDashboardCache.Shapes = shapeUpdate ? shapes : SymbolDashboardCache.Shapes; return(SymbolDashboardCache); } else { SymbolDashboard symbol_dashboard = new SymbolDashboard() { Portfolio_Id = portfolio_id, Symbol_Id = symbol_id }; symbol_dashboard.Symbol = DashboardService.GetSymbol(portfolio_id, symbol_id, chartRange, candelRange, withQuotes); symbol_dashboard.Indicators = DashboardService.GetSymbolIndicators(symbol_dashboard.Symbol, -1, withQuotes, candelRange, out indicatorUpdate); symbol_dashboard.Shapes = DashboardService.GetSymbolShapes(symbol_dashboard.Symbol, -1, withQuotes, out shapeUpdate); SymbolDashboardCache = symbol_dashboard; return(symbol_dashboard); } }
public CandleChart(TradingSymbol symbol, ChartRange range) : this(symbol, range, new Candle[0]) { }
private static ctaCOMMON.Charts.Symbol GetSymbol(int portfolio_id, int symbol_id, ChartRange chartRange, CandelRange candelRange, bool withQuotes) { if (DashBoardCache != null && DashBoardCache.DashboardItems.Count > 0 && false) { var symbol = DashBoardCache.DashboardItems.Where(x => x.Portfolio_Id == portfolio_id) .SelectMany(x => x.Symbols) .Where(x => x.Symbol_ID == symbol_id) .FirstOrDefault(); return(symbol); } else { ctaCOMMON.Charts.Symbol symbol = new ctaCOMMON.Charts.Symbol(); using (ctaDBEntities entities = new ctaDBEntities()) { entities.Database.Connection.Open(); string user_type = (portfolio_id == 0) ? "FREE" : entities.Portfolios.Where(p => p.Id == portfolio_id).Select(p => p.Tenant.Tenant_Type.Name).First(); var stock_entity = entities.Stocks.Where(s => s.Id == symbol_id).First(); symbol.Portfolio_ID = portfolio_id; symbol.Symbol_ID = stock_entity.Id; symbol.Symbol_Name = stock_entity.symbol; symbol.Symbol_Company_Name = stock_entity.name; symbol.Symbol_Market_ID = stock_entity.market_id; symbol.Symbol_Market = stock_entity.Market.name; symbol.Intradiary_Info = QuotesService.GetSymbolIntradiaryInfo(symbol_id); if (withQuotes) { symbol.Quotes = QuotesService.GetSymbolQuotes(symbol.Symbol_ID, chartRange, candelRange, user_type); } entities.Database.Connection.Close(); } return(symbol); } }