public override void ClosePosition(Instrument instrument, double price, ComponentType component, string text)
        {
            Position position = this.portfolio.Positions[instrument];

            if (position != null)
            {
                MarketOrder marketOrder;
                switch (position.Side)
                {
                case PositionSide.Long:
                    marketOrder = new MarketOrder(instrument, Side.Sell, position.Qty, text);
                    this.RegisterOrder(marketOrder);
                    marketOrder.Send();
                    return;

                case PositionSide.Short:
                    marketOrder = new MarketOrder(instrument, Side.Buy, position.Qty, text);
                    this.RegisterOrder(marketOrder);
                    marketOrder.Send();
                    return;

                default:
                    return;
                }
            }
        }
Beispiel #2
0
        public MarketOrder SendMarketOrder(Instrument instrument, Side side, double qty)
        {
            MarketOrder marketOrder = new MarketOrder(instrument, side, qty);

            this.Strategy.EB2iXBUSFK((SingleOrder)marketOrder);
            marketOrder.Send();
            return(marketOrder);
        }
Beispiel #3
0
        public MarketOrder SendMarketOrder(Instrument instrument, Side side, double qty)
        {
            MarketOrder marketOrder = new MarketOrder(instrument, side, qty);

            base.Strategy.RegisterOrder(marketOrder);
            marketOrder.Send();
            return(marketOrder);
        }
Beispiel #4
0
        private OrderInfo GetOrderInfo(SOrderParameters orderParams)
        {
            var order = new MarketOrder(orderParams);

            using var monitoredOrder = order.Monitor();
            order.Send();
            monitoredOrder.Should().Raise("OrderSent");
            return((OrderInfo)monitoredOrder.OccurredEvents[0].Parameters[0]);
        }
Beispiel #5
0
        public void TestSendNumLotsZeroDefault()
        {
            var order = new MarketOrder(new SOrderParameters());

            using var monitoredOrder = order.Monitor();
            order.Send(0);
            monitoredOrder.Should().Raise("OrderSent")
            .WithArgs <OrderInfo>(info => info.Size == 100);
        }
Beispiel #6
0
        public void TestSendCustomNumLots()
        {
            var order = new MarketOrder(
                new SOrderParameters(Contracts.CreateUserSpecified(100), EOrderAction.Buy));

            using var monitoredOrder = order.Monitor();
            order.Send(25);
            monitoredOrder.Should().Raise("OrderSent")
            .WithArgs <OrderInfo>(info => info.OrderAction == EOrderAction.Buy)
            .WithArgs <OrderInfo>(info => info.Size == 25);
        }
Beispiel #7
0
        public void TestSend()
        {
            var order = new MarketOrder(new SOrderParameters());

            using var monitoredOrder = order.Monitor();
            order.Send();
            monitoredOrder
            .Should().Raise("OrderSent")
            .WithArgs <OrderInfo>(info => info.OrderAction == EOrderAction.Buy)
            .WithArgs <OrderInfo>(info => info.Size == 100);
        }
Beispiel #8
0
        public void TestSendNumLotsDissallowNegative()
        {
            var order = new MarketOrder(new SOrderParameters());

            Assert.Throws <ArgumentOutOfRangeException>(() => order.Send(-100));
        }