public async Task AddPendingOrder(Domain.StrategysStock strategysStock, Domain.Order order) { var stratagysStock = GetStatagysStockFromDb(strategysStock); _context.Add(new Order { OrderPlaced = order.OrderPlacedTime, AttemptedCostPerShare = order.MarketPrice, AttemptedSharesBought = order.SharesBought, PositionId = stratagysStock.Id }); await _context.SaveChangesAsync(); }
public void AddStock(Company company) { // Arrange var testSettings = new TestProjectSettings(); StockContext testContext = null; Repository <Company> tested = null; try { testContext = new StockContext(testSettings); testContext.Database.EnsureCreated(); tested = new Repository <Company>(testContext); testContext.Add(company); var changesCount = testContext.SaveChanges(); // Act var actual = testContext.Set <Company>().Count(); var expected = 1; // Assert Assert.Equal(expected, actual); } finally { testContext?.Database.EnsureDeleted(); tested?.Dispose(); testContext?.Dispose(); } }
public async Task GetSymbols(string exchange) { var result = _dbContext.Exchanges .Where(b => b.Code.Contains(exchange)); if (result.Count() == 1) { Symbol[] symbols = await _finnhubClient.Stock.GetSymbols(exchange); foreach (var symbol in symbols) { var query = _dbContext.StockProperties .Where(b => b.Symbol == symbol.CandleSymbol); if (!(query.Count() > 0)) { _dbContext.Add(new StockProperty { Symbol = symbol.CandleSymbol, DisplaySymbol = symbol.DisplaySymbol, ExchangeFK = result.First().ExchangeId, Watching = false }); } else { Log.Information($"Record not added, Table[AssetProperties]: {query.FirstOrDefault().Symbol} already exists in db and was not added."); } } _dbContext.SaveChanges(); } else { var exchangeConnector = new ExchangeConnector(_finnhubClient, _dbContext); await exchangeConnector.GetExchanges(); } }
private void CrawlPricePage(int codeNum) { var code = codeNum.ToString("D6"); string uri = $"https://fchart.stock.naver.com/sise.nhn?symbol={code}&timeframe=day&count=5000&requestType=0"; var pageString = GetPageString(uri); var root = XElement.Parse(pageString.Trim()); if (root.HasElements == false) { return; } var chartdata = root.Element("chartdata"); var name = chartdata.Attribute("name").Value; _logger.LogInformation($"Insert: {name} [{code}]"); var stock = new StockCosmos() { StockName = name, StockCode = code, }; foreach (var dayPrice in root.Element("chartdata").Elements("item")) { //<item data="20200407|7300|7450|6930|7430|178992" /> //날짜, 시가, 고가, 저가, 종가, 거래량 var splitedData = dayPrice.Attribute("data").Value.Split('|'); var dateInfo = DateTime.ParseExact(splitedData[0], "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); var price = new Price() { PriceDate = dateInfo, StartPrice = Int32.Parse(splitedData[1]), HighPrice = Int32.Parse(splitedData[2]), LowPrice = Int32.Parse(splitedData[3]), EndPrice = Int32.Parse(splitedData[4]), Volumn = Int32.Parse(splitedData[5]), }; if (price.PriceDate < DateTime.ParseExact("20100101", "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture).ToUniversalTime()) { continue; } stock.Prices.Add(price); } using (var context = new StockContext()) { context.Database.EnsureCreated(); context.Add(stock); context.SaveChanges(); } }
public async Task <IActionResult> Create([Bind("ProdID,Name,Qty,Price")] Stock stock) { if (ModelState.IsValid) { _context.Add(stock); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stock)); }
public async Task <IActionResult> Create([Bind("ID,Open,Close,High,Low,Type")] Stock3 stock3) { if (ModelState.IsValid) { _context.Add(stock3); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stock3)); }
public async Task <IActionResult> Create([Bind("ID,Symbol,LastPrice,DateScrapped,Change,ChangeRate,Currency,MarketTime,Volume,ShareData,AverageVolume,MarketCapData")] Stocks stocks) { if (ModelState.IsValid) { context.Add(stocks); await context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stocks)); }
public async Task <IActionResult> Create([Bind("ID,Symbol,LastPrice,Change,PercentChange,Currency,MarketTime,Volume,Shares,AvgVol3m,MarketCap,Date")] Stock stock) { if (ModelState.IsValid) { _context.Add(stock); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stock)); }
public async Task <IActionResult> Create([Bind("CategoryID,Name")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("ComponentTypeID,ComponentTypeName,ComponentInfo,Location,Status,Datasheet,ImageUrl,Manufacturer,WikiLink,AdminComment")] ComponentType componentType, string[] selectedCategories) { //selected category ids are in selectedCategories array AddComponentTypeCategories(selectedCategories, componentType); if (ModelState.IsValid) { _context.Add(componentType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } PopulateCategoryData(componentType); return(View(componentType)); }
public async Task <IActionResult> Create( [Bind("ComponentTypeID,ComponentNumber,SerialNo,Status,AdminComment,UserComment,CurrentLoanInformationId")] Component component) { try { if (ModelState.IsValid) { _context.Add(component); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException) { ModelState.AddModelError("", "unable to save changes, try again or ask admin"); } ViewData["ComponentTypeID"] = new SelectList(_context.ComponentTypes, "ComponentTypeID", "ComponentTypeName", component.ComponentTypeID); return(View(component)); }
public async Task GetExchanges() { StockExchange[] exchanges = await _finnhubClient.Stock.GetExchanges(); foreach (var exchange in exchanges) { var query = _dbContext.Exchanges .Where(b => b.Code == exchange.Code); if (!(query.Count() > 0)) { _dbContext.Add(new Exchange { Code = exchange.Code, Name = exchange.Name }); } else { Log.Information($"Duplicate Record, Table[Exchange]: {exchange.Code} already exists in db"); } } _dbContext.SaveChanges(); }
public async Task <IActionResult> Create([FromBody] Models.Stock stock) { if (ModelState.IsValid) { try { _context.Add(stock); await _context.SaveChangesAsync(); if (stock.Id > 0) { return(Ok(stock.Id)); } return(NotFound()); } catch (Exception) { return(BadRequest()); } } return(BadRequest()); }
public async Task InsertAsync(Category obj) { _context.Add(obj); await _context.SaveChangesAsync(); }
public void InsertStock(Stock stock) { _dbContext.Add(stock); Save(); }
public void AddStock(Stock stock) { context.Add(stock); context.SaveChanges(); }
public IEnumerable <Stock> Post(Stock body) { _stockContext.Add(body); _stockContext.SaveChanges(); return(_stockContext.Stocks); }
public void InsertStockInvoice(StockInvoice stockInvoice) { _dbContext.Add(stockInvoice); Save(); }
public void InsertCategory(Category category) { _dbContext.Add(category); Save(); }
public async Task InsertAsync(Product obj) { _context.Add(obj); await _context.SaveChangesAsync(); }
public void AddHashtag(Hashtag newHashtag) { _context.Add(newHashtag); _context.SaveChanges(); }