public int OrderClose(Order order) { int res = 0; order.DateClose = Instr.Candles[0].DateOpen; order.DateCloseUTC = DateTime.UtcNow; order.PriceClose = Instr.Candles[0].ClosePrice; order.Profit = order.Volume * (order.PriceClose - order.PriceOpen) * ((order.OrderType == OrderType.Sell) ? (-1) : 1); Portf.Balance = Portf.Balance + order.PriceClose * order.Volume; return res; }
public Order OrderSend(string tickerCode, OrderType orderType, int volume, decimal stoploss = 0, decimal takeprofit = 0, DateTime? expirationDate = null, string comment = "") { Order order = new Order(); order.TickerCode = tickerCode; order.OrderType = orderType; order.Volume = volume; order.StopLoss = stoploss; order.TakeProfit = takeprofit; order.ExpirationDate = expirationDate; order.DateOpen = Instr.Candles[0].DateOpen; order.DateOpenUTC = DateTime.UtcNow; order.PriceOpen = Instr.Candles[0].ClosePrice + Portf.Slippage * ((order.OrderType == OrderType.Sell) ? (-1) : 1); decimal oldBalance = Portf.Balance; Portf.Balance = Math.Round(Portf.Balance - order.PriceOpen * order.Volume * (100 - Portf.Rent) / 100, 2); if (Portf.Balance < 0) { Portf.Balance = oldBalance; return null; } Strategy.Orders.Insert(0, order); return order; }
public int OrderClose(Order order) { int res = 0; order.DateClose = Instr.Candles[0].DateOpen; order.DateCloseUTC = DateTime.UtcNow; order.PriceClose = Instr.Candles[0].ClosePrice; order.Profit = order.Volume * (order.PriceClose - order.PriceOpen) * ((order.OrderType == OrderType.Sell) ? (-1) : 1); //TODO:Потокобезопасно Portf.Balance = Portf.Balance + order.PriceClose * order.Volume; orderRepository.Save(order); return res; }