示例#1
0
        public void processExecution(ExecutionMessage message)
        {
            IAppOrderManager orderManager = appStgManager.getAppOrderManager();

            String[] stgNames = appStgManager.getStgNames();
            if (!appStgManager.getAppOrderManager().AppOrderStore.ContainsKey(message.Execution.OrderId))
            {
                return;
            }
            if (!orderManager.isExecutionProcessed(message.Execution.ExecId))
            {
                AppExecution execution  = orderManager.updateAppOrderExecution(message);
                IAppOrder    order      = orderManager.AppOrderStore[message.Execution.OrderId];
                AppOrder     cloneOrder = (AppOrder)order.Clone();
                if (AppObjectUtil.isOrderClosed(cloneOrder))
                {
                    orderManager.closeOpenAppOrder(order.StrategyIndex, order);
                }
                orderManager.updatePosition(order.StrategyIndex, execution);
                String      stgName     = stgNames[order.StrategyIndex];
                AppPosition stgPosition = orderManager.StoreStgPositions[stgName];
                log.Info("Total PnL : " + stgPosition.TotalPnL);
                orderManager.markExeProcessed(message.Execution.ExecId);

                //***New for send order executed email***
                IAppEventManager appEventManager = appStgManager.getAppEventManager();
                appEventManager.putOrderExeEvents(message, stgName);

                /*TSAppExecution execution = appForm.StrategyManager.updateAppOrderExecution(message);
                 * TSAppOrder order = appForm.StrategyManager.AppOrderStore[message.Execution.OrderId];
                 * TSAppOrder cloneOrder = (TSAppOrder)order.Clone();
                 * if (StrategyManager.isOrderClosed(cloneOrder))
                 * {
                 *  appForm.StrategyManager.closeOpenAppOrder(order.StrategyIndex, order);
                 *  //appForm.StrategyManager.removeOpenAppOrder(order.StrategyIndex, order);
                 *  //appForm.StrategyManager.addClosedAppOrder(order.StrategyIndex, order);
                 * }
                 * appForm.StrategyManager.updatePosition(order.StrategyIndex, execution);
                 * String stgName = appForm.StrategyManager.StgNames[order.StrategyIndex];
                 * AppPosition stgPosition = appForm.StrategyManager.StoreStgPositions[stgName];
                 * log.Info("Total PnL : " + stgPosition.TotalPnL);
                 * //log.Info("Total PnL : " + appForm.StrategyManager.StgPositions[order.StrategyIndex].TotalPnL);
                 * appForm.StrategyManager.markExeProcessed(message.Execution.ExecId);*/
            }
            log.Info("Order Executed");
            log.Info("*********************************************");
        }
        public void test_updatePosition()
        {
            List <IAppExecution> lstExecution = createExecution_for_updatePosition();
            IAppStrategyManager  stgManager   = getStgManager();
            IAppOrderManager     orderManager = new AppOrderManager(stgManager);
            int stgIndex = 2;
            int numExe   = 5;

            int[]    accBuyQ      = new int[numExe];
            int[]    accSellQ     = new int[numExe];
            int[]    netQ         = new int[numExe];
            double[] accBuyMoney  = new double[numExe];
            double[] accSellMoney = new double[numExe];
            double[] totalPnL     = new double[numExe];

            accBuyQ[0]      = 0;
            accSellQ[0]     = 6;
            netQ[0]         = -6;
            accBuyMoney[0]  = 0;
            accSellMoney[0] = 6 * 22100;
            totalPnL[0]     = 0;

            accBuyQ[1]      = 3;
            accSellQ[1]     = 6;
            netQ[1]         = -3;
            accBuyMoney[1]  = 3 * 22000;
            accSellMoney[1] = 6 * 22100;
            totalPnL[1]     = 0;

            accBuyQ[2]      = 6;
            accSellQ[2]     = accSellQ[1];
            netQ[2]         = 0;
            accBuyMoney[2]  = accBuyMoney[1] + 3 * 21900;
            accSellMoney[2] = accSellMoney[1];
            totalPnL[2]     = 6 * 22100 - (3 * 22000 + 3 * 21900);

            accBuyQ[3]      = 7;
            accSellQ[3]     = accSellQ[2];
            netQ[3]         = 1;
            accBuyMoney[3]  = accBuyMoney[2] + 23000;
            accSellMoney[3] = accSellMoney[2];
            totalPnL[3]     = totalPnL[2];

            accBuyQ[4]      = accBuyQ[3];
            accSellQ[4]     = 7;
            netQ[4]         = 0;
            accBuyMoney[4]  = accBuyMoney[3];
            accSellMoney[4] = accSellMoney[3] + 23500;
            totalPnL[4]     = totalPnL[3] + (23500 - 23000);

            orderManager.updatePosition(stgIndex, lstExecution[0]);
            String[]    stgNames = stgManager.getStgNames();
            String      stgName  = stgNames[stgIndex];
            AppPosition position = orderManager.StoreStgPositions[stgName];

            Assert.AreEqual(accSellQ[0], position.AccSellQ);
            Assert.AreEqual(accSellMoney[0], position.AccSellMoney);
            Assert.AreEqual(netQ[0], position.NetQ);

            orderManager.updatePosition(stgIndex, lstExecution[1]);
            Assert.AreEqual(accBuyQ[1], position.AccBuyQ);
            Assert.AreEqual(accBuyMoney[1], position.AccBuyMoney);
            Assert.AreEqual(netQ[1], position.NetQ);
            Assert.AreEqual(totalPnL[1], position.TotalPnL);

            orderManager.updatePosition(stgIndex, lstExecution[2]);
            Assert.AreEqual(accBuyQ[2], position.AccBuyQ);
            Assert.AreEqual(accBuyMoney[2], position.AccBuyMoney);
            Assert.AreEqual(netQ[2], position.NetQ);
            Assert.AreEqual(totalPnL[2], position.TotalPnL);

            orderManager.updatePosition(stgIndex, lstExecution[3]);
            Assert.AreEqual(accBuyQ[3], position.AccBuyQ);
            Assert.AreEqual(accBuyMoney[3], position.AccBuyMoney);
            Assert.AreEqual(netQ[3], position.NetQ);
            Assert.AreEqual(totalPnL[3], position.TotalPnL);

            orderManager.updatePosition(stgIndex, lstExecution[4]);
            Assert.AreEqual(accSellQ[4], position.AccSellQ);
            Assert.AreEqual(accSellMoney[4], position.AccSellMoney);
            Assert.AreEqual(netQ[4], position.NetQ);
            Assert.AreEqual(totalPnL[4], position.TotalPnL);
        }