public Common.Entities.Deal MakeDeal(UnitOfWork unit, Common.Entities.Order order, DateTime dateTime, decimal price) { Random rnd = new Random(); Common.Entities.Deal deal = new Common.Entities.Deal() { Number = rnd.Next(7000, 900000), OrderNumber = order.Number, Code = order.Code, Time = dateTime.ToString("HH:mm"), Date = dateTime.ToString("dd:MM:yyyy"), Operation = order.OrderOperation.ToString(), Account = order.Account, Price = price, Count = order.Count, Volume = price * order.Count, Class = order.Class }; unit.DealRepository.Create(deal); MoneyLimit money = unit.MoneyLimitRepository.Query <MoneyLimit>(m => m.Type == "T2").Single(); if (order.OrderOperation == OrderOperationEnum.Buy) { money.Available -= order.Count * price; } if (order.OrderOperation == OrderOperationEnum.Sell) { money.Available += order.Count * price; } return(deal); }
public void ApplyStop(UnitOfWork unit, StopOrder order, Settings settings) { bool apply = false; decimal applyPrice = 0; decimal price = tradeModel.GetPrice(unit, order.Code, settings.TestDateTime); var transaction = unit.TransactionRepository.Query <Common.Entities.Transaction>(t => t.OrderNumber == order.Number).Single(); _strategy.CalcProfit(transaction, order, price); decimal?lossProfit = _strategy.GetLossProfit(transaction, price); //отступ от max 1,0% if (lossProfit.HasValue && (lossProfit.Value / price) * 100 > settings.OFFSET) { apply = true; } if (_strategy.StopLimit(order, price)) { apply = true; } if (apply) { Random rnd = new Random(); order.OrderState = OrderStateEnum.Executed; Common.Entities.Order new_order = new Common.Entities.Order() { Number = rnd.Next(7000, 900000), Code = order.Code, Time = settings.TestDateTime.ToString("HH:mm"), OrderOperation = order.OrderOperation, Account = order.Account, Price = applyPrice, Count = order.Count, OrderState = OrderStateEnum.IsActive, Class = order.Class, Client = order.Client, Comment = order.Client }; order.OrderNumber = new_order.Number; unit.OrderRepository.Create(new_order); } }
public Common.Entities.Order GetOrder() { Common.Entities.Order order = new Common.Entities.Order { Id = Id, ShortDescription = ShortDescription, FullDescription = FullDescription, City = City, ContractPrice = ContractPrice, Price = Price, Deadline = Deadline, CreateDate = CreateDate, NameProvider = NameProvider, ClientProfileId = ClientProfileId, ProviderProfileId = ProviderProfileId, Galery = Images, ServiceId = ServiceId, OrderStatus = OrderStatus }; return(order); }
public OrderViewModel(Common.Entities.Order order) { Id = order.Id; City = order.City; ShortDescription = order.ShortDescription; FullDescription = order.FullDescription; NameProvider = order.NameProvider; ContractPrice = order.ContractPrice; Deadline = order.Deadline; Price = order.Price; CreateDate = order.CreateDate; ClientProfileId = order.ClientProfileId; ProviderProfileId = order.ProviderProfileId; ServiceId = order.ServiceId; ServiceModel = new ServiceViewModel(order.Service); Feedbacks = new FeedbacksCollectionViewModel(order.Feedbacks); Images = order.Galery; OrderStatus = order.OrderStatus; }