/// <summary> /// синхронный запуск /// </summary> void getStock() { while (true) { try { //получаем список компаний List <string> companies; using (Context db = new Context()) { companies = (from c in db.Companies select c.Ticker).ToList(); } IStockPrice stockPrice = null; if (_setting.Source == 1) { stockPrice = new Finnhub(); } else if (_setting.Source == 2) { stockPrice = new Moex(); } else { stockPrice = new Finnhub(); } Dictionary <string, double> prices = stockPrice.GetStock(companies); //добавляем полученный данные в бд using (Context db = new Context()) { List <Stock> stocks = new List <Stock>(); foreach (var item in prices) { int id = (from c in db.Companies where c.Ticker == item.Key select c.Id).FirstOrDefault(); DateTime date = DateTime.UtcNow; stocks.Add(new Stock() { SourceId = _setting.Source, Price = item.Value, Date = date, CompanyId = id });; } db.Stocks.AddRange(stocks); db.SaveChanges(); } //ждем положенное время Thread.Sleep(_setting.Time); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
public Form1() { InitializeComponent(); try { newsControl = new List<Control>(); analysisControl = new List<Control>(); EndpointAddress stockPriceAddress = new EndpointAddress("http://localhost:90/StockPrice"); EndpointAddress stockNewsAddress = new EndpointAddress("http://localhost:90/StockNews"); EndpointAddress stockFinanceAddress = new EndpointAddress("http://localhost:90/StockFinance"); EndpointAddress stockForecastAddress = new EndpointAddress("http://localhost:90/StockForecast"); BasicHttpBinding stockPriceBinding = new BasicHttpBinding(); BasicHttpBinding stockNewsBinding = new BasicHttpBinding(); WSDualHttpBinding stockForecastBinding = new WSDualHttpBinding(); stockForecastBinding.ClientBaseAddress = new Uri("http://localhost:90/"); stockPriceProxy = ChannelFactory<IStockPrice>.CreateChannel(stockPriceBinding, stockPriceAddress); stockNewsProxy = ChannelFactory<IStockNews>.CreateChannel(stockNewsBinding, stockNewsAddress); stockFinanceProxy = ChannelFactory<IFinancialIndicatorService>.CreateChannel(new BasicHttpBinding(), stockFinanceAddress); InstanceContext insContext = new InstanceContext(this); stockForecastProxy = new ForecastServiceClient(insContext, stockForecastBinding, stockForecastAddress); List<string[]> mostIncrease = stockPriceProxy.GetMostIncrease(); List<string[]> mostDecrease = stockPriceProxy.GetMostDecrease(); List<string[]> mostTraded = stockPriceProxy.GetMostTraded(); DataTable mostIncreaseSource = ToDataTable(mostIncrease, new string[] { "Stock", "Open", "High", "Low", "Close", "Volume", "Change(%)" }, new int[] { 1, 3, 4, 5, 6, 7, 8 }); DataTable mostDecreaseSource = ToDataTable(mostDecrease, new string[] { "Stock", "Open", "High", "Low", "Close", "Volume", "Change(%)" }, new int[] { 1, 3, 4, 5, 6, 7, 8 }); DataTable mostTradedSource = ToDataTable(mostTraded, new string[] { "Stock", "Open", "High", "Low", "Close", "Volume" }, 5); dgvMostIncrease.DataSource = mostIncreaseSource; dgvMostDecrease.DataSource = mostDecreaseSource; dgvMostTraded.DataSource = mostTradedSource; int colCount = dgvMostIncrease.Columns.Count; int colWidth = (dgvMostIncrease.Width - 41) / 7; AutoSizeColumns(dgvMostIncrease, new int[] { 69, 69, 69, 69, 69, 69, 68 }); AutoSizeColumns(dgvMostDecrease, new int[] { 69, 69, 69, 69, 69, 69, 68 }); AutoSizeColumns(dgvMostTraded, new int[] { 80, 80, 80, 80, 81, 81 }); AddNews(stockNewsProxy.GetNews("", Convert.ToInt32(txtViewCount.Value))); AddAnalysis(stockNewsProxy.GetExpertAnalysis("", Convert.ToInt32(txtAnalysisCount.Value))); List<string[]> periodsList = stockFinanceProxy.GetPeriods("HNM"); foreach (string[] period in periodsList) { string result = "Q" + period[0] + "/" + period[1]; cbbQuarter.Items.Add(result); } cbbQuarter.SelectedIndex = cbbQuarter.Items.Count - 1; cbbForecastsNum.SelectedIndex = cbbForecastsNum.Items.Count - 1; } catch (Exception e) { MessageBox.Show("Error connecting to service. Press OK to quit"); Environment.Exit(-1); } }
public StockData() { _stockPrice = NinjectWebCommon.GetConcreteInstance <IStockPrice>(); _apiHelper = NinjectWebCommon.GetConcreteInstance <IAPIHelper>(); }
private void drawData(Graphics g, ChartData cd, int start, int end) { if (cd.style == ChartStyle.STOCKCANDLE) { IStockDataTable table = (IStockDataTable)cd.table; int b = area.XPixelsPerGrids / 2; using (SolidBrush brush = new SolidBrush(cd.color)) { using (Pen pen = new Pen(cd.color)) { for (int x = start; x <= end; x++) { IStockPrice price = table[ScaleTypeX, x]; int h = price.end - price.start; int x2 = area.xpics(x) + b; if (h > 0) { g.DrawLine(pen, x2, area.ypics(price.high), x2, area.ypics(price.end)); g.DrawLine(pen, x2, area.ypics(price.start), x2, area.ypics(price.low)); g.DrawRectangle(pen, area.rect(x, price.end, 1, h)); } else { g.DrawLine(pen, x2, area.ypics(price.low), x2, area.ypics(price.high)); g.FillRectangle(brush, area.rect(x, price.start, 1, -h)); } } // for(x) } // using (pen) } // using (brush) } else { ILongDataTable table = (ILongDataTable)cd.table; switch (cd.style) { case ChartStyle.COLUMN: using (Pen pen = new Pen(cd.color)) { Rectangle[] colm = new Rectangle[end - start + 1]; int i = 0; for (int x = start; x <= end; x++) { Rectangle r = area.rect(x, 0, 1, table[ScaleTypeX, x]); r.Inflate(-1, 0); colm[i++] = r; } g.DrawRectangles(pen, colm); break; } case ChartStyle.AREA: using (SolidBrush brush = new SolidBrush(cd.color)) { Point[] poly = new Point[end - start + 3]; int i = 0; for (int x = start; x <= end; x++) { poly[i++] = area.point(x, table[ScaleTypeX, x]); } poly[i++] = area.point(end, 0); poly[i++] = area.point(start, 0); g.FillPolygon(brush, poly); break; } case ChartStyle.LINE: using (Pen pen = new Pen(cd.color)) { Point[] poly = new Point[end - start + 1]; int i = 0; for (int x = start; x <= end; x++) { poly[i++] = area.point(x, table[ScaleTypeX, x]); } g.DrawLines(pen, poly); break; } } // switch } // else }
public StockData() { _stockPrice = NinjectWebCommon.GetConcreteInstance<IStockPrice>(); _apiHelper = NinjectWebCommon.GetConcreteInstance<IAPIHelper>(); }