Esempio n. 1
0
        public void push(OrderCmd aCmd)
        {
            Order order;

            if (orders.ContainsKey(aCmd.orderInfo.orderId))
            {
                // order alreday exist
                logger.Info("push:orderIdExist:" + aCmd.orderInfo.orderId);
                order = orders[aCmd.orderInfo.orderId];
                //orderid, account, symbol, and position can not change
                if (aCmd.closed)
                {
                    order.closingOrder("OrderCmd");
                }
                else
                {
                    updateOrder(order, aCmd);
                }
            }
            else
            {
                logger.Info("push:nreOrderId:" + aCmd.orderInfo.orderId);
                // create new order
                OrderTrackingInfo orderTrackingInfo = new OrderTrackingInfo(OrderState.WaitingSubmit);
                orderTrackingInfo.orderId = aCmd.orderInfo.orderId;

                order = new Order(aCmd.orderInfo, orderTrackingInfo, aCmd.orderBehaviorParameters);
                addOrder(order);
                updateOrder(order, aCmd);
                order.active();
                order.fireOrder("NewOrderCmdRecieved");
            }
        }
Esempio n. 2
0
        private bool orderCmdValidation(OrderCmd aCmd)
        {
            bool isOrderExist = OrderManager.Instance.isOrderIDExist(aCmd.orderInfo.orderId);

            if (isOrderExist)
            {
                return(true);
            }
            else
            {
                if (Math.Abs(aCmd.orderInfo.position) != 1)
                {
                    return(false);
                }

                if (!AccountClass.AccountManager.Instance.isValidAccount(aCmd.orderInfo.account))
                {
                    return(false);
                }

                if (!SymbolClass.SymbolManager.Instance.isValidSymbol(aCmd.orderInfo.abbrName))
                {
                    return(false);
                }
                return(true);
            }
        }
Esempio n. 3
0
 private void updateOrder(Order order, OrderCmd aCmd)
 {
     // set hardstop
     if (aCmd.orderBehaviorParameters.hardstop > 0)
     {
         order.invokeHardstop(aCmd.orderBehaviorParameters.hardstop);
         logger.Info("updateOrder (orderId = " + order.getOrderID() + ") : invokeHardstop : " + aCmd.orderBehaviorParameters.hardstop);
     }
     // set daytrade
     if (aCmd.orderBehaviorParameters.daytrade)
     {
         order.invokeDayTrade();
         logger.Info("updateOrder (orderId = " + order.getOrderID() + ") : invokeDayTrade");
     }
     // set profit take
     if (aCmd.orderBehaviorParameters.profittakepercent > 0)
     {
         order.invokeProfitTake(aCmd.orderBehaviorParameters.profittakepercent);
         logger.Info("updateOrder (orderId = " + order.getOrderID() + ") : invokeProfitTake : " + aCmd.orderBehaviorParameters.profittakepercent);
     }
     // set profit protect
     if (aCmd.orderBehaviorParameters.protectiontrigger > 0 & aCmd.orderBehaviorParameters.protection > 0)
     {
         order.invokeProtector(aCmd.orderBehaviorParameters.protectiontrigger, aCmd.orderBehaviorParameters.protection);
         logger.Info("updateOrder (orderId = " + order.getOrderID() + ") : invokeProtector : " +
                     aCmd.orderBehaviorParameters.protectiontrigger + "/" + aCmd.orderBehaviorParameters.protection);
     }
 }
Esempio n. 4
0
        private void onOrderMsg(string channel, string value)
        {
            if (String.Compare(channel, channelnames[0]) != 0)
            {
                return;
            }

            logger.Info("onOrderMsg : placeOrder message recieved = " + value);

            OrderCmd orderCmd = new OrderCmd();

            string[] items = value.Split(';');

            #region
            foreach (string item in items)
            {
                string[] lArr = item.Split('=');
                if (lArr.Length == 2)
                {
                    string key = lArr[0].ToLower().Trim();
                    switch (key)
                    {
                    case "orderid":
                        orderCmd.orderInfo.orderId = Convert.ToInt32(lArr[1]);
                        orderCmd.orderBehaviorParameters.orderId = orderCmd.orderInfo.orderId;
                        break;

                    case "account":
                        orderCmd.orderInfo.account = lArr[1].Trim();
                        break;

                    case "symbol":
                        orderCmd.orderInfo.abbrName = lArr[1].ToLower().Trim();
                        break;

                    case "position":
                        orderCmd.orderInfo.position = Convert.ToInt32(lArr[1]);
                        break;

                    case "daytrade":
                        orderCmd.orderBehaviorParameters.daytrade = Convert.ToBoolean(lArr[1]);
                        break;

                    case "closed":
                        orderCmd.closed = Convert.ToBoolean(lArr[1]);
                        break;

                    case "profittakepercent":
                        orderCmd.orderBehaviorParameters.profittakepercent = Convert.ToDouble(lArr[1]);
                        break;

                    case "protectiontrigger":
                        orderCmd.orderBehaviorParameters.protectiontrigger = Convert.ToDouble(lArr[1]);
                        break;

                    case "protection":
                        orderCmd.orderBehaviorParameters.protection = Convert.ToDouble(lArr[1]);
                        break;

                    case "hardstop":
                        orderCmd.orderBehaviorParameters.hardstop = Convert.ToDouble(lArr[1]);
                        break;

                    default:
                        break;
                    }
                }
            }

            #endregion

            if (orderCmdValidation(orderCmd))
            {
                logger.Info("onOrderMsg ==> " + orderCmd.getInfo());
                //check touchance active or not

                if (TCMonitor.TouchanceMonitor.Instance.isTouchanceExist())
                {
                    OrderManager.Instance.push(orderCmd);
                }
                else
                {
                    logger.Info("Touchance is not running in this machine, command ignored.");
                }
            }
        }