Esempio n. 1
0
        public void MarketOrder(SignalInfo signal, IExpert adv)
        {
            try
            {
                if (adv == null)
                {
                    return;
                }
                // decimal priceInOrder = Math.Round(tool.LastPrice + tool.Step * 5, tool.PriceAccuracy);
                // decimal priceInOrder = 0;// Math.Round(tool.LastPrice, tool.PriceAccuracy);
                int qty = (int)adv.Volume();

                var portfolio = Portfolios.Where(x => x.Name == adv.AccountName()).FirstOrDefault();
                if (!Trader.RegisteredPortfolios.Contains(portfolio))
                {
                    Trader.RegisterPortfolio(portfolio);
                }

                Order order = new Order();
                order.Type = OrderTypes.Market;
                var securities = Securities.Where(x => x.Code == adv.Symbol());
                if (securities != null && securities.Count() > 0)
                {
                    order.Security = securities.FirstOrDefault();
                }
                else
                {
                    order.Security      = new Security();
                    order.Security.Code = adv.Symbol();
                    order.Security.Id   = adv.Symbol() + "@FORTS";
                }

                order.Comment   = adv.Comment();
                order.Portfolio = portfolio;

                if (!Trader.RegisteredSecurities.Contains(order.Security))
                {
                    Trader.RegisterSecurity(order.Security);
                    Trader.RegisterTrades(order.Security);
                }

                order.Volume    = qty;
                order.Direction = signal.Value == 0 ? Sides.Buy : Sides.Sell;

                Log(
                    $"Expert <{adv.AccountName()}> On {adv.Symbol()} {order.Direction.ToString()} Register order: lots=" +
                    qty);
                Trader.RegisterOrder(order);
            }
            catch (Exception e)
            {
                Log($"Expert <{adv.AccountName()}> Error registering order: " + e);
            }
        }