コード例 #1
0
ファイル: TesterManager.cs プロジェクト: Rizjiy/RMarketMVC
        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;
        }
コード例 #2
0
ファイル: TesterManager.cs プロジェクト: Rizjiy/RMarketMVC
        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;
        }
コード例 #3
0
ファイル: EmulManager.cs プロジェクト: Rizjiy/RMarketMVC
        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;
        }