Package com.activequant.domainmodel.trade.order

Examples of com.activequant.domainmodel.trade.order.LimitOrder


  }
 
  void weedOutForeignOrders(){
    Iterator<LimitOrder> it = buySide.iterator();
    while(it.hasNext()){
      LimitOrder lo = it.next();
      if(lo.getOrderId()==null)it.remove();
    }
    it = sellSide.iterator();
    while(it.hasNext()){
      LimitOrder lo = it.next();
      if(lo.getOrderId()==null)it.remove();
    }
   
  }
View Full Code Here


     */
    @Override
    public IOrderTracker prepareOrder(Order order) throws UnsupportedOrderType, IncompleteOrderInstructions {
        if (!(order instanceof LimitOrder))
            throw new UnsupportedOrderType("Order type not supported by exchange: " + order);
        LimitOrder limitOrder = (LimitOrder) order;
        if(limitOrder.getQuantity()<=0.0)
            throw new IncompleteOrderInstructions("Invalid quantity given: " + limitOrder.getQuantity());
        if(limitOrder.getLimitPrice() == null)
            throw new IncompleteOrderInstructions("No limit price given.");
        if(limitOrder.getLimitPrice() <= 0.0)
            throw new IncompleteOrderInstructions("Invalid negative limit price given.");
        VirtualOrderTracker tracker = new VirtualOrderTracker(limitOrder);
        return tracker;
    }
View Full Code Here

            ofe.setFillPrice(price);
            ((VirtualOrderTracker) trck).getEvent().fire(ofe);

            //
            if (order instanceof LimitOrder) {
                LimitOrder lo = (LimitOrder) order;
                if (lo.getOpenQuantity() == 0) {
                    OrderTerminalEvent ote = new OrderTerminalEvent();
                    ote.setCreationTimeStamp(currentExchangeTime());
                    ((VirtualOrderTracker) trck).getEvent().fire(ote);
                    // clean up the order tracker.
                    orderTrackers.remove(trck);
View Full Code Here

            // clear out limit order book except our own orders.
            lob.weedOutForeignOrders();

            if (nbbo.getBid() != null) {

                LimitOrder bestBid = new LimitOrder();
                bestBid.setOrderSide(OrderSide.BUY);
                bestBid.setLimitPrice(nbbo.getBid());
                bestBid.setQuantity(nbbo.getBidQuantity());
                bestBid.setOpenQuantity(bestBid.getQuantity());
                lob.addOrder(bestBid);
            }

            if (nbbo.getAsk() != null) {
                LimitOrder bestAsk = new LimitOrder();
                bestAsk.setOrderSide(OrderSide.SELL);
                bestAsk.setLimitPrice(nbbo.getAsk());
                bestAsk.setQuantity(nbbo.getAskQuantity());
                bestAsk.setOpenQuantity(bestAsk.getQuantity());
                lob.addOrder(bestAsk);

            }
            // rerun a match.
            lob.match();
View Full Code Here

        List<LimitOrder> buySide = ob.buySide();
        List<LimitOrder> sellSide = ob.sellSide();

        while (buySide.size() > 0 && sellSide.size() > 0 && buySide.get(0).getLimitPrice() >= sellSide.get(0).getLimitPrice()) {

            LimitOrder buyOrder = buySide.get(0);
            LimitOrder sellOrder = sellSide.get(0);

            double difference = buyOrder.getOpenQuantity() - sellOrder.getOpenQuantity();
            double executed = 0.0;

            double relevantPrice = sellOrder.getLimitPrice();
            // determine the relevant price.
            if (buyOrder.getWorkingTimeStamp().compareTo(sellOrder.getWorkingTimeStamp()) < 0)
                relevantPrice = buyOrder.getLimitPrice();

            if (difference > 0) {
                // buy side larger.
                executed = buyOrder.getOpenQuantity() + difference;
                buyOrder.setOpenQuantity(difference);
                sellOrder.setOpenQuantity(0);
            } else if (difference < 0) {
                executed = sellOrder.getOpenQuantity() + difference;
                // sell side larger.
                buyOrder.setOpenQuantity(0);
                sellOrder.setOpenQuantity(Math.abs(difference));
            } else {
                // both fully executed.
                executed = buyOrder.getOpenQuantity();
                sellOrder.setOpenQuantity(0);
                buyOrder.setOpenQuantity(0);
            }
            //
            exchange.execution(buyOrder, relevantPrice, executed);
            exchange.execution(sellOrder, relevantPrice, executed);
            //
            if (sellOrder.getOpenQuantity() == 0)
                sellSide.remove(0);

            if (buyOrder.getOpenQuantity() == 0)
                buySide.remove(0);
View Full Code Here

 
  public void handle(StreamEvent streamEvent){
    if(Math.random()<0.05)
    {
      try {
        IOrderTracker orderTracker = exchange.prepareOrder(new LimitOrder());
        orderTracker.submit();
      } catch (UnsupportedOrderType e) {
        e.printStackTrace();
      } catch (IncompleteOrderInstructions e) {
        e.printStackTrace();
View Full Code Here

TOP

Related Classes of com.activequant.domainmodel.trade.order.LimitOrder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.