Example #1
0
 public void PlaceLimitOrder(LimitOrderSpecification limitOrderSpecification, OnInstructionResponse instructionCallback, OnFailure failureCallback)
 {
     OrderResponseHandler handler = new OrderResponseHandler();
     SendRequest(limitOrderSpecification, handler, delegate() { instructionCallback(handler.InstructionId); }, failureCallback);
 }
        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;
                }
            }
        }