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();
        }
Example #2
0
        private void btn_test_buy_Click(object sender, EventArgs e)
        {
            IAppOrderManager appOrderManager = appStrategyManager.getAppOrderManager();
            Contract         contract        = GetMDContract();
            Order            order           = GetOrder("BUY", "LMT");

            //order.OrderId = ibClient.NextOrderId;
            //ibClient.NextOrderId++;
            order.OrderId = ibClient.IncreaseOrderId();
            orderManager.PlaceOrder(contract, order);
            txt_console.Text = order.OrderId.ToString();
            OrderRecord orderR = new OrderRecord();

            orderR.orderId   = order.OrderId;
            orderR.sno       = txt_sno.Text;
            orderR.orderTime = DateTime.Now;
            //orderRepositry.Add(order.OrderId.ToString(), orderR);
            appOrderManager.OrderRepositry.AddOrUpdate(order.OrderId.ToString(), orderR, (key, oldValue) => oldValue);
            List <OrderRecord> orderRecords = new List <OrderRecord>();

            orderRecords.Add(orderR);
            appStrategyManager.getAppOrderManager().OrderPersister.SaveLastRow(orderRecords);
            //if (orderId != 0)
            //    orderId = 0;
        }
Example #3
0
 public StrategyHelper(IAppStrategyManager appStgManager, String stgName, int stgIndex, SignalContext execution)
 {
     this.appStgManager   = appStgManager;
     this.appOrderManager = appStgManager.getAppOrderManager();
     this.stgName         = stgName;
     this.stgIndex        = stgIndex;
     this.execution       = execution;
 }
Example #4
0
        private void btn_stg4_stop_Click(object sender, EventArgs e)
        {
            IAppOrderManager appOrderManager = appStrategyManager.getAppOrderManager();

            String[] stgNames = appStrategyManager.getStgNames();
            appStrategyManager.stopStrategy(3);
            MessageBox.Show("Strategy Stop Submitted!");
        }
        //new dailyReset
        public void exportReport(String name)
        {
            IAppOrderManager      appOrderManager = getAppOrderManager();
            String                prefix          = AppConstant.FILE_POSITION_RESULT_PREFIX;
            String                suffix          = String.Format("{0:_yyyyMMdd}", DateTime.Now);
            PositionPersistHelper helper          = new PositionPersistHelper(prefix, suffix);

            helper.SaveRows(name, appOrderManager.StoreStgClosedOrders[name]);
        }
Example #6
0
        private void readOrderFromFiles()
        {
            IAppOrderManager   appOrderManager = appStrategyManager.getAppOrderManager();
            List <OrderRecord> orders          = OrderFileReader.getOrderRecorderFromFile(AppConstant.FILE_ORDER_REP);

            foreach (OrderRecord record in orders)
            {
                appOrderManager.OrderRepositry.AddOrUpdate(record.orderId.ToString(), record, (kye, oldValue) => oldValue);
            }
        }
Example #7
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 injectAppOrderManager(IAppOrderManager appOrderManager)
 {
     this.appOrderManager = appOrderManager;
 }