Beispiel #1
0
 private static OnInstructionResponse OrderSuccessCallback(OrderTracker orderTracker)
 {
     return(instructionId =>
     {
         Console.WriteLine("order placed with instruction id " + instructionId);
         orderTracker.OrderState = OrderState.Working;
     });
 }
Beispiel #2
0
        private void CancelOrder(OrderTracker orderTracker)
        {
            long originalInstructionId = orderTracker.InstructionId;

            if (originalInstructionId != -1)
            {
                orderTracker.CancelInstructionId = NextInstructionId();
                CancelOrderRequest cancelOrderRequest = new CancelOrderRequest(orderTracker.CancelInstructionId,
                                                                               _instrumentId,
                                                                               originalInstructionId);
                _session.CancelOrder(cancelOrderRequest,
                                     instructionId =>
                                     Console.WriteLine("instruction id " + orderTracker.CancelInstructionId +
                                                       " sent to cancel order " + originalInstructionId),
                                     FailureCallback("Cancel order with cancelOrderInstructionId: " +
                                                     orderTracker.CancelInstructionId));
            }
        }
Beispiel #3
0
        private void HandlePriceChange(List <PricePoint> prices, OrderTracker orderTracker, decimal quantity,
                                       decimal priceDelta)
        {
            decimal mostRecentOrderPrice = orderTracker.Price;

            if (prices.Count == 0)
            {
                //if there's no best price, we can't decide what price to place, so exit
                return;
            }
            PricePoint bestPriceInTheMarket = prices[0];

            // Make sure we have a best bid price, and it's not the same as the order we just placed
            // and place similar to the ask price change.
            if (mostRecentOrderPrice == 0 || mostRecentOrderPrice != bestPriceInTheMarket.Price)
            {
                switch (orderTracker.OrderState)
                {
                // Place an order inside the spread if there isn't one currently in the market
                case OrderState.None:
                    orderTracker.Price = bestPriceInTheMarket.Price + priceDelta;

                    orderTracker.InstructionId = NextInstructionId();
                    LimitOrderSpecification order =
                        new LimitOrderSpecification(orderTracker.InstructionId, _instrumentId, orderTracker.Price,
                                                    quantity, TimeInForce.GoodForDay);

                    _session.PlaceLimitOrder(order,
                                             OrderSuccessCallback(orderTracker),
                                             FailureCallback("Place order failed for instruction ID " +
                                                             orderTracker.InstructionId));
                    break;

                // Cancel a working order on a price change.
                case OrderState.Working:
                    CancelOrder(orderTracker);
                    break;
                }
            }
        }
        private void HandlePriceChange(List<PricePoint> prices, OrderTracker orderTracker, decimal quantity,
                                       decimal priceDelta)
        {
            decimal mostRecentOrderPrice = orderTracker.Price;
            if (prices.Count == 0)
            {
                //if there's no best price, we can't decide what price to place, so exit
                return;
            }
            PricePoint bestPriceInTheMarket = prices[0];

            // Make sure we have a best bid price, and it's not the same as the order we just placed
            // and place similar to the ask price change.
            if (mostRecentOrderPrice == 0 || mostRecentOrderPrice != bestPriceInTheMarket.Price)
            {
                switch (orderTracker.OrderState)
                {
                    // Place an order inside the spread if there isn't one currently in the market
                    case OrderState.None:
                        orderTracker.Price = bestPriceInTheMarket.Price + priceDelta;

                        orderTracker.InstructionId = NextInstructionId();
                        LimitOrderSpecification order =
                            new LimitOrderSpecification(orderTracker.InstructionId, _instrumentId, orderTracker.Price,
                                                        quantity, TimeInForce.GoodForDay);

                        _session.PlaceLimitOrder(order,
                                                 OrderSuccessCallback(orderTracker),
                                                 FailureCallback("Place order failed for instruction ID " +
                                                                 orderTracker.InstructionId));
                        break;

                    // Cancel a working order on a price change.
                    case OrderState.Working:
                        CancelOrder(orderTracker);
                        break;
                }
            }
        }
        private void CancelOrder(OrderTracker orderTracker)
        {
            long originalInstructionId = orderTracker.InstructionId;

            if (originalInstructionId != -1)
            {
                orderTracker.CancelInstructionId = NextInstructionId();
                CancelOrderRequest cancelOrderRequest = new CancelOrderRequest(orderTracker.CancelInstructionId,
                                                                               _instrumentId,
                                                                               originalInstructionId);
                _session.CancelOrder(cancelOrderRequest,
                                     instructionId =>
                                     Console.WriteLine("instruction id " + orderTracker.CancelInstructionId +
                                                       " sent to cancel order " + originalInstructionId),
                                     FailureCallback("Cancel order with cancelOrderInstructionId: " +
                                                     orderTracker.CancelInstructionId));
            }
        }
 private static OnInstructionResponse OrderSuccessCallback(OrderTracker orderTracker)
 {
     return instructionId =>
                {
                    Console.WriteLine("order placed with instruction id " + instructionId);
                    orderTracker.OrderState = OrderState.Working;
                };
 }