public async Task <Job> Create(JobViewModel jobViewmodel) { if (jobViewmodel.WatchlistId > 0) { var strategy = new Strategy() { MaxLoss = jobViewmodel.MaxLoss, MaxProfit = jobViewmodel.MaxProfit, WatchlistId = jobViewmodel.WatchlistId }; _context.Strategies.Add(strategy); await _context.SaveChangesAsync(); var job = new Job() { CreatedDate = DateTime.Now, HangfireId = Guid.NewGuid().ToString(), StrategyId = strategy.Id, }; _context.Jobs.Add(job); await _context.SaveChangesAsync(); return(job); } return(null); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name")] Watchlist watchlist) { if (ModelState.IsValid) { watchlist.CreatedDate = DateTime.Now; db.Watchlists.Add(watchlist); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(watchlist)); }
public async Task <bool> DataRefereshAsync(IList <Instrument> instruments) { //await _context.Database.ExecuteSqlCommandAsync("TRUNCATE TABLE trading.Symbol"); //await _context.SaveChangesAsync(); //var symbols = _context.Symbols.Select(x=> uint.Parse( x.InstrumentToken)).ToList(); foreach (var instrument in instruments) { _context.Symbols.Add(new Symbol() { Exchange = instrument.Exchange, ExchangeToken = Convert.ToString(instrument.ExchangeToken), TradingSymbol = instrument.TradingSymbol, TickSize = instrument.TickSize, Expiry = instrument.Expiry, CreatedDate = DateTime.Now, InstrumentToken = Convert.ToString(instrument.InstrumentToken), InstrumentType = instrument.InstrumentType, LotSize = instrument.LotSize, Name = instrument.Name, Segment = instrument.Segment, Strike = instrument.Strike }); } await _context.SaveChangesAsync(); return(true); }
public async Task <bool> SyncPositions(IList <Position> positions) { if (positions != null && positions.Count() > 0) { foreach (var position in positions) { _context.BrokerPositions.Add(new BrokerPosition() { AveragePrice = position.AveragePrice, CreatedDate = DateTime.Now, DayBuyPrice = position.DayBuyPrice, DayBuyQuantity = position.DayBuyQuantity, DayBuyValue = position.DayBuyQuantity, DaySellPrice = position.DaySellPrice, DaySellQuantity = position.DaySellQuantity, DaySellValue = position.DaySellValue, Exchange = position.Exchange, PNL = position.PNL, Realised = position.Realised, TradingSymbol = position.TradingSymbol, Unrealised = position.Unrealised }); } await _context.SaveChangesAsync(); return(true); } return(false); }
public async Task <bool> SyncOrders(IList <Order> orders) { if (orders != null && orders.Count() > 0) { foreach (var order in orders) { _context.BrokerOrders.Add(new BrokerOrder() { BrokerOrderId = order.OrderId, CreatedDate = order.ExchangeTimestamp, DisclosedQuantity = order.DisclosedQuantity, JobId = Convert.ToInt32(order.Tag), OrderStatus = order.Status, OrderType = order.OrderType, Price = order.Price, Tag = order.Tag, Product = order.Product, Quantity = order.Quantity, TradingSymbol = order.Tradingsymbol, TriggerPrice = order.TriggerPrice, TransactionType = order.TransactionType, Validity = order.Validity, Variety = order.Variety }); } await _context.SaveChangesAsync(); return(true); } return(false); }
public async Task <bool> SetCurrentSession(UserSessionModel userSession) { var existingSession = await _context.UserSessions.Where(x => x.CreatedDate >= DateTime.Today).FirstOrDefaultAsync(); if (existingSession == null) { _context.UserSessions.Add(new UserSession() { AccessToken = userSession.AccessToken, ApiKey = userSession.ApiKey, AppSecret = userSession.AppSecret, CreatedDate = DateTime.Now, PublicToken = userSession.PublicToken, UserId = userSession.UserId }); } else { existingSession.AccessToken = userSession.AccessToken; existingSession.ApiKey = userSession.ApiKey; existingSession.AppSecret = userSession.AppSecret; existingSession.CreatedDate = DateTime.Now; existingSession.PublicToken = userSession.PublicToken; existingSession.UserId = userSession.UserId; } await _context.SaveChangesAsync(); return(true); }