public AppStrategyManager(IIBTradeAppBridge appForm)
        {
            appMDManager          = new AppMDManager(appForm);
            appEventManager       = new AppEventManager(this);
            appOrderManager       = new AppOrderManager(this);
            appMaintenanceManager = new AppMainteanceManager(this);
            appMaintenanceManager.startManager();
            ParentUI = appForm;
            //OrderRepositry = new ConcurrentDictionary<string, OrderRecord>();
            activeStgNamesMap = new ConcurrentDictionary <String, String>();
            storeStg          = new Dictionary <string, IStrategy>();
            storeStg.Add(AppConstant.STG1_SHORT_NAME, new StrategyRandom1(AppConstant.STG1_SHORT_NAME, 0));
            storeStg.Add(AppConstant.STG2_SHORT_NAME, new StrategyRBreakerReverse1(AppConstant.STG2_SHORT_NAME, 1));
            storeStg.Add(AppConstant.STG3_SHORT_NAME, new StrategyRBreakerTrend1(AppConstant.STG3_SHORT_NAME, 2));
            storeStg.Add(AppConstant.STG4_SHORT_NAME, new StrategyRandom4(AppConstant.STG4_SHORT_NAME, 3));

            /*
             * storeStg.Add(AppConstant.STG5_SHORT_NAME, new StrategyStastic1(AppConstant.STG5_SHORT_NAME, 4));
             * storeStg.Add(AppConstant.STG6_SHORT_NAME, new StrategyRBreaker1(AppConstant.STG6_SHORT_NAME, 5));
             * storeStg.Add(AppConstant.STG7_SHORT_NAME, new StrategyRBreakerTrend2(AppConstant.STG7_SHORT_NAME, 6));
             */
            StoreCancelToken = new ConcurrentDictionary <string, CancellationTokenSource>();
            TimeDiffServer   = long.MaxValue;
            appEventManager.startGenerateTimeEvents();
        }
Exemple #2
0
        public void handleDailyReset(AppTimeEvent timeEvent)
        {
            ConcurrentDictionary <String, String> stgNamesMap = stgManager.getActiveStgNamesMap();

            stgNamesMap.Keys.ToArray();
            IAppEventManager eventManager = stgManager.getAppEventManager();

            foreach (String name in stgNamesMap.Keys)
            {
                eventManager.storeEventQueue[name].Add(new AppDailyResetEvent());
            }
            stgManager.dailyReset();
        }
Exemple #3
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 injectAppEventManager(IAppEventManager eventManager)
 {
     this.appEventManager = eventManager;
 }
        public override void UpdateUI(IBMessage message)
        {
            IAppMDManager     appMDMManager   = appStrategyManager.getAppMDManager();
            IAppEventManager  appEventManager = appStrategyManager.getAppEventManager();
            MarketDataMessage dataMessage     = (MarketDataMessage)message;

            checkToAddRow(dataMessage.RequestId);
            DataGridView grid = (DataGridView)uiControl;

            if (grid.Rows.Count >= dataMessage.RequestId - TICK_ID_BASE)
            {
                if (message is TickPriceMessage)
                {
                    TickPriceMessage priceMessage = (TickPriceMessage)message;
                    switch (dataMessage.Field)
                    {
                    case 1:
                    {
                        //BID
                        appEventManager.putTickPriceEvents(priceMessage, dataMessage);
                        //stgManager.handleTickMessage(message);
                        grid[BID_PRICE_INDEX, GetIndex(dataMessage.RequestId)].Value = priceMessage.Price;
                        break;
                    }

                    case 2:
                    {
                        //ASK
                        appEventManager.putTickPriceEvents(priceMessage, dataMessage);
                        //stgManager.handleTickMessage(message);
                        grid[ASK_PRICE_INDEX, GetIndex(dataMessage.RequestId)].Value = priceMessage.Price;
                        break;
                    }

                    case 4:
                    {
                        //LAST
                        appEventManager.putTickPriceEvents(priceMessage, dataMessage);
                        //stgManager.handleTickMessage(message);
                        grid[LAST_PRICE_INDEX, GetIndex(dataMessage.RequestId)].Value = priceMessage.Price;
                        break;
                    }

                    case 6:
                    {
                        //HIGH
                        grid[HIGH_PRICE_INDEX, GetIndex(dataMessage.RequestId)].Value = priceMessage.Price;
                        break;
                    }

                    case 7:
                    {
                        //LOW
                        grid[LOW_PRICE_INDEX, GetIndex(dataMessage.RequestId)].Value = priceMessage.Price;
                        break;
                    }

                    case 9:
                    {
                        //CLOSE
                        grid[CLOSE_PRICE_INDEX, GetIndex(dataMessage.RequestId)].Value = priceMessage.Price;
                        break;
                    }
                    }
                }
                else if (dataMessage is TickSizeMessage)
                {
                    TickSizeMessage sizeMessage = (TickSizeMessage)message;
                    switch (dataMessage.Field)
                    {
                    case 0:
                    {
                        //BID SIZE
                        grid[BID_SIZE_INDEX, GetIndex(dataMessage.RequestId)].Value = sizeMessage.Size;
                        break;
                    }

                    case 3:
                    {
                        //ASK SIZE
                        grid[ASK_SIZE_INDEX, GetIndex(dataMessage.RequestId)].Value = sizeMessage.Size;
                        break;
                    }

                    case 5:
                    {
                        //LAST SIZE

                        grid[LAST_SIZE_INDEX, GetIndex(dataMessage.RequestId)].Value = sizeMessage.Size;
                        break;
                    }

                    case 8:
                    {
                        //VOLUME
                        //stgManager.handleTickMessage(message);
                        grid[VOLUME_SIZE_INDEX, GetIndex(dataMessage.RequestId)].Value = sizeMessage.Size;
                        break;
                    }
                    }
                }
            }
        }