public static int CheckPriceMatch(decimal tempTradePrice, ExternalBlock b) { if (b.symbol.Equals("Buy") && b.price != -1) //buy at limit price { if (tempTradePrice < b.price) { return(1); } else { return(-1); } } else if (b.symbol.Equals("Sell") && b.price != -1) // sell at limit price { if (tempTradePrice > b.price) { return(1); } else { return(-1); } } else // market price buy or sell will always go through { return(1); } }
public static decimal GetTradePrice(ExternalBlock b) { Random r = new Random(); decimal finalTradePrice; //BrokerSecurity bs = new BrokerSecurity(); var bs = (from n in context.BrokerSecurities where n.securitySymbol.Equals(b.symbol) select n).FirstOrDefault(); var x = (from n in context.BrokerSecurities where n.securitySymbol.Equals(b.symbol) select n).FirstOrDefault(); if (b.side.Equals("Buy")) { if (b.price == -1) //market price buy side { //market price int randomSpread = r.Next(0, bs.maxSpread); int randomSign = r.Next(0, 1); // = r.NextDouble((bs.tradePrice * (1 - (randomSpread / 100) )), (bs.tradePrice * (randomSpread / 100 + 1))); if (randomSign == 0) { finalTradePrice = bs.tradePrice * ((100 - randomSpread) / 100); } else { finalTradePrice = bs.tradePrice * (randomSpread + 100) / 100; } } else //limit price buy side { //limit price int ran = r.Next(0, bs.maxSpread); finalTradePrice = (bs.tradePrice * (100 - ran)) / 100; } } else //sell side { if (b.price != -1) //limit price { //sell side with limit price finalTradePrice = (bs.tradePrice * (100 + r.Next(0, bs.maxSpread))) / 100; } else { //sell side with market price //no change to trade price required finalTradePrice = bs.tradePrice; } } return(finalTradePrice); }
public void EOD() { var x = from n in context.ExternalBlocks where n.blockStatus.Equals("Partial") select n; List <ExternalBlock> blocks = new List <ExternalBlock>(); blocks = x.ToList(); foreach (var item in blocks) { ExternalBlock bb = context.ExternalBlocks.Find(item.blockId); item.blockStatus = "Expired"; } context.SaveChanges(); }