public void PerfectMatchTest()
        {
            FIFOTradeMatcher matcher = new FIFOTradeMatcher();
            List<Trade> matches = new List<Trade>();

            Equity p = new Equity("Google","GOOG");
            Order order1 = new Order(p, 10, Order.Side.BUY);
            Order order2 = new Order(p, 10, Order.Side.SELL);

            Fill fill1 = new Fill();
            fill1.price = 100;
            fill1.qty = 10;
            fill1.originalOrder = order1;

            Fill fill2 = new Fill();
            fill2.price = 100;
            fill2.qty = 10;
            fill2.originalOrder = order2;

            List<Fill> fills = new List<Fill>();
            fills.Add(fill1);
            fills.Add(fill2);

            matches = matcher.match(fills);

            Assert.IsTrue(matches.Count == 1 && fills.Count == 0);
        }
Esempio n. 2
0
        static void Main()
        {
            //Initialize Position Manager
            FIFOTradeMatcher matcher = new FIFOTradeMatcher();
            PositionManager posMgr = new PositionManager(matcher);

            //Initialize Risk Engine
            SimplePositionLimtRiskFilter riskFilter = new SimplePositionLimtRiskFilter(posMgr);

            //Initialize Broker Managers
            brokers = new List<BrokerManager>();

            //Register to get a call back when this broker is ready to receive orders
            IBBrokerManager ibManager = new IBBrokerManager(riskFilter);
            ibManager.AcceptingOrders += new BrokerReadyEventHandler(readyToAcceptOrders);
            brokers.Add(ibManager);
            
            posMgr.addBrokers(brokers);

            ibManager.connect();

            //Create Main Window
            log.Info("Creating UI components");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //MainWindow win = new MainWindow(controller);
            MainWindow win = new MainWindow();

            //Create UI Controller
            UIController controller = new UIController(brokers, posMgr, win);

            Application.Run(win);
        }
        public void LopsidedMatchTest()
        {
            FIFOTradeMatcher matcher = new FIFOTradeMatcher();
            List<Trade> matches = new List<Trade>();

            Equity p = new Equity("Google", "GOOG");
            Order order1 = new Order(p, 10, Order.Side.BUY);
            Order order2 = new Order(p, 5, Order.Side.SELL);
            Order order3 = new Order(p, 25, Order.Side.BUY);
            Order order4 = new Order(p, 7, Order.Side.SELL);
            Order order5 = new Order(p, 12, Order.Side.SELL);

            Fill fill1 = new Fill();
            fill1.price = 100;
            fill1.qty = 10;
            fill1.originalOrder = order1;

            Fill fill2 = new Fill();
            fill2.price = 100;
            fill2.qty = 5;
            fill2.originalOrder = order2;

            Fill fill3 = new Fill();
            fill3.price = 100;
            fill3.qty = 20;
            fill3.originalOrder = order3;

            Fill fill4 = new Fill();
            fill4.price = 100;
            fill4.qty = 6;
            fill4.originalOrder = order4;

            Fill fill5 = new Fill();
            fill5.price = 100;
            fill5.qty = 12;
            fill5.originalOrder = order5;

            List<Fill> fills = new List<Fill>();
            fills.Add(fill1);
            fills.Add(fill2);
            fills.Add(fill3);
            fills.Add(fill4);
            fills.Add(fill5); 

            matches = matcher.match(fills);

            Assert.IsTrue(matches.Count == 1 && fills.Count == 3);
        }