Exemplo n.º 1
0
        private bool PlaceOrder(LimeFIXProvider target, SymbolInfo symbol, OrderType type,
                                int size, double price, out LogicalOrder logicalOrder, out CreateOrChangeOrderDefault priceOrder)
        {
            logicalOrder = Factory.Engine.LogicalOrder(symbol);
            logicalOrder.TradeDirection = TradeDirection.Entry;
            logicalOrder.Type           = type;
            logicalOrder.Price          = price;
            logicalOrder.Position       = size;

            priceOrder = new CreateOrChangeOrderDefault(OrderAction.Create, symbol, logicalOrder, OrderSide.Buy, logicalOrder.Position, logicalOrder.Price);

            return(target.OnCreateBrokerOrder(priceOrder));
        }
Exemplo n.º 2
0
        public void OrderPlaceChangeAndCancel(int changes)
        {
            log.Info("Starting Test OrderPlaceChangeAndCancel");
            int startCount = client.OrderStore.Count();

            LogicalOrder logicalOrder;
            CreateOrChangeOrderDefault priceOrder;
            bool ok = PlaceOrder(client, MSFT, OrderType.BuyLimit, 100, 35, out logicalOrder, out priceOrder);

            if (!ok)
            {
                log.ErrorFormat("Test Aborted: Failed to place order {0}", priceOrder);

                return;
            }

            if (!WaitOn(() => client.OrderStore.Count() == startCount, 30, "Order not placed"))
            {
                int couont = client.OrderStore.Count();
                return;
            }

            for (int i = 0; i < changes; i++)
            {
                Thread.Sleep(1000);

                log.InfoFormat("Start orders {0}, current Orders {1}", startCount,
                               client.OrderStore.Count());

                var changeOrder = new CreateOrChangeOrderDefault(OrderAction.Change, MSFT, logicalOrder,
                                                                 OrderSide.Buy, 100, logicalOrder.Price + 1);
                changeOrder.OriginalOrder = priceOrder;
                ok = client.OnChangeBrokerOrder(changeOrder);
                if (!ok)
                {
                    log.ErrorFormat("Test Aborted: Failed to change order {0}", priceOrder);

                    return;
                }
            }
            Thread.Sleep(1000);

            var orderList = client.OrderStore.GetOrdersList(c => c.Symbol == MSFT);

            foreach (var order in orderList)
            {
                log.InfoFormat("Cancel Order {0}", order);
                order.OriginalOrder = order;
                client.OnCancelBrokerOrder(order);
            }

            WaitOn(() => client.OrderStore.Count() > 0, 30, "Orders not canceled");

            if (client.OrderStore.Count() > 0)
            {
                log.Error("Failed to cancel all orders");
                foreach (var order in client.OrderStore.GetOrders(c => c.Symbol == MSFT))
                {
                    log.ErrorFormat("Cancel failed for Order {0}", order);
                }
            }
            else
            {
                log.Info("All orders canceled");
            }

            log.Info("Completed Test OrderPlaceChangeAndCancel");
        }
Exemplo n.º 3
0
        public void OrderPlaceAndCancel()
        {
            log.Info("Starting Test OrderPlaceAndCancel");
            int startCount = client.OrderStore.Count();

            var logicalOrder = Factory.Engine.LogicalOrder(MSFT);

            logicalOrder.TradeDirection = TradeDirection.Entry;
            logicalOrder.Type           = OrderType.BuyLimit;
            logicalOrder.Price          = 35;
            logicalOrder.Position       = 100;

            var priceOrder = new CreateOrChangeOrderDefault(OrderAction.Create, MSFT, logicalOrder, OrderSide.Buy, logicalOrder.Position, logicalOrder.Price);

            bool ok = client.OnCreateBrokerOrder(priceOrder);

            if (!ok)
            {
                log.ErrorFormat("Test Aborted: Failed to place order {0}", priceOrder);

                return;
            }

            if (!WaitOn(() => client.OrderStore.Count() == startCount, 30, "Order not placed"))
            {
                return;
            }


            log.InfoFormat("Start orders {0}, current Orders {1}", startCount,
                           client.OrderStore.Count());


            var orderList = client.OrderStore.GetOrdersList(c => c.Symbol == MSFT);

            foreach (var order in orderList)
            {
                log.InfoFormat("Cancel Order {0}", order);
                if (order.OriginalOrder == null)
                {
                    order.OriginalOrder = order;
                }
                client.OnCancelBrokerOrder(order);
            }

            WaitOn(() => client.OrderStore.Count() > 0, 30, "Orders not canceled");

            if (client.OrderStore.Count() > 0)
            {
                log.Error("Failed to cancel all orders");
                foreach (var order in client.OrderStore.GetOrders(c => c.Symbol == MSFT))
                {
                    log.ErrorFormat("Cancel failed for Order {0}", order);
                }
            }
            else
            {
                log.Info("All orders canceled");
            }
            log.Info("Completed Test OrderPlaceAndCancel");
        }