public IActionResult Save([FromBody] NewOrderData data)
        {
            if (!data.Items.Any())
            {
                return(new JsonResult(new Fault("Order does not have any item")));
            }

            var order = new Order
            {
                Id      = ObjectId.GenerateNewId(),
                Address = data.Address,
                Items   = from item in data.Items
                          select new OrderItem {
                    SKU = new ObjectId(item.Key), Quantity = item.Value
                }
            };

            OrdersRepository repository = new OrdersRepository(connectionString);

            repository.SaveOrder(order);

            this.Bus.Publish(new OrderCreatedMessage
            {
                OrderId = order.Id.ToString(),
                Items   = data.Items
            });

            return(new JsonResult(new SuccessWithResult <string>(order.Id.ToString())));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send the trade to OMS
        /// </summary>
        /// <param name="setup">Setup</param>
        /// <param name="trade">Trade to send</param>
        /// <param name="command">How to process the trade</param>
        public void SendTrade(Setup setup, Trade trade, int command)
        {
            if (setup.How2Trade * command == 0)
            {
                return;
            }

            var order = new NewOrderData {
                BranchID = "Standard"
            };

            order.OrderExpireDate = DateTime.Today.ToString("yyyy-MM-dd");
            order.OrderExpireType = 0;
            order.OrderType       = command > 0 ? 0 : 1;
            order.Symbol          = Rename(trade.Symbol);
            order.MarketID        = trade.AssetClass;
            order.Identificator   = Math.Abs(command) == 2
                ? trade.SetupId.ToString() : BvspTime.TimeOfDay.ToString();
            order.Price = setup.How2Trade == 6 ? 0
                : Math.Abs(command) == 2 ? (double)trade.StopGain.Value
                : Math.Sign(command) * (double)setup.Slippage + (double)trade.ExitValue.Value;
            order.PriceType = order.Price > 0 ? 0 : 6;

            #region Send orders

            _orders.TryAdd(order.Identificator, order);

            setup.Basket.Shuffle();
            var index = setup.Basket.FindIndex(t => t.ClientID == "30516");
            if (index > 0)
            {
                var first = setup.Basket[0];
                setup.Basket[0]     = setup.Basket[index];
                setup.Basket[index] = first;
            }
            var basket   = new List <Client>(setup.Basket);
            var isLogged = this.IsLogged;

            Task.Factory.StartNew(() =>
            {
                foreach (var item in basket)
                {
                    order.ClientID = item.ClientID;
                    order.Quantity = (double)item.SetQnty(trade.EntryValue, "BMF.FUT");
                    if (item.IsMini)
                    {
                        order.Symbol = order.Symbol.Replace("IND", "WIN");
                    }
                    var type = order.OrderType == 0 ? " C " : " V ";
                    var info = order.Symbol + type + order.Price + " " + order.ClientID + " " + order.Quantity + " ";

                    var iReqID = 0;
                    var status = "OK";
                    if (isLogged)
                    {
                        _omsclient.NewOrder(order, out iReqID, out status);
                    }

                    if (status == "OK")
                    {
                        NotifyOMS(info);
                    }
                    else
                    {
                        NotifyOMS("OFF " + status + " " + info);
                    }
                    _track.TryAdd(iReqID, order.Identificator + " " + info);
                }
            });
            #endregion

            //if (Math.Abs(command) != 2) this.Cancel(trade.Id.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Send the trade to OMS
        /// </summary>
        /// <param name="setup">Setup</param>
        /// <param name="trade">Trade to send</param>
        /// <param name="command">How to process the trade</param>
        public void SendTrade(Setup setup, Trade trade, int command)
        {
            if (setup.How2Trade * command == 0)
            {
                return;
            }

            var order = new NewOrderData {
                BranchID = "Standard"
            };

            order.OrderExpireDate = DateTime.Now.ToString("yyyy-MM-dd");
            order.OrderExpireType = 0;
            order.OrderType       = command > 0 ? 0 : 1;
            order.Symbol          = Rename(trade.Symbol);
            order.MarketID        = order.Symbol.Contains("IND") ? "BMF.FUT"
                : (int)order.Symbol[4] < 65 ? "BVSP.VIS" : "BVSP.OPC";
            order.Identificator = Math.Abs(command) == 2
                ? trade.Id.ToString() : DateTime.Now.TimeOfDay.ToString();
            order.Price = setup.How2Trade == 6 ? 0
                : Math.Abs(command) == 2 ? trade.StopGain.Value
                : Math.Sign(command) * setup.spread + trade.ExitValue.Value;
            order.PriceType = order.Price > 0 ? 0 : 6;

            #region Send orders

            _orders.TryAdd(order.Identificator, order);
            NotifyOMS("Beep: " + trade.ToString());

            setup.BasketItens.Shuffle();
            var index = setup.BasketItens.FindIndex(t => t.Client == "30321");
            if (index > 0)
            {
                var first = setup.BasketItens[0];
                setup.BasketItens[0]     = setup.BasketItens[index];
                setup.BasketItens[index] = first;
            }
            var basket = new List <Basket>(setup.BasketItens);

            ThreadPool.QueueUserWorkItem(o =>
            {
                foreach (var item in basket)
                {
                    order.ClientID = item.Client;
                    order.Quantity = order.MarketID == "BMF.FUT" ? (double)item.Contract
                        : 100 * Math.Floor(item.Capital / trade.EntryValue / 100);
                    if (item.IsMini)
                    {
                        order.Symbol = order.Symbol.Replace("IND", "WIN");
                    }
                    var type = order.OrderType == 0 ? " C " : " V ";
                    var info = order.Symbol + type + order.Price + " " + order.ClientID + " " + order.Quantity + " ";

                    var iReqID = 0;
                    var status = "OK";
                    if (_omsclient != null)
                    {
                        _omsclient.NewOrder(order, out iReqID, out status);
                    }

                    if (status == "OK")
                    {
                        NotifyOMS(info);
                    }
                    else
                    {
                        NotifyOMS("OFF " + status + " " + info);
                    }
                    _track.TryAdd(iReqID, order.Identificator + " " + info);
                }
            });
            #endregion

            //if (Math.Abs(command) != 2) this.Cancel(trade.Id.ToString());
        }