Пример #1
0
 /**
  * This method is mainly to cancel replace an order. We find the original order in the books, then
  * we renew its information. then we push it back to the financial.book as a new order.
  */
 public String cxrOrder(OrderCxRImpl changeOrder) {
   // get the id of the cancel replace order
   String orderID = changeOrder.getOrderId();
   // find the order in the financial.book
   NewOrderImpl renewOrder = lookUpOrder(orderID);
   // renew the order, then push it back into the financial.book as a new order
   String orderSymbol = renewOrder.getSymbol();
   if (renewOrder != null && changeOrder.getSize() != 0) {
     // renew the size of the order
     renewOrder.size = changeOrder.getSize();
     // renew the price of the order
     renewOrder.limitPrice = changeOrder.getLimitPrice();
     // get the bidbook and askbook of that certain symbol
     Hashtable<Double, LinkedList<NewOrderImpl>> tempbid =
         new Hashtable<Double, LinkedList<NewOrderImpl>>();
     Hashtable<Double, LinkedList<NewOrderImpl>> tempask =
         new Hashtable<Double, LinkedList<NewOrderImpl>>();
     if (bid.containsKey(orderSymbol)) {
       tempbid = bid.get(orderSymbol);
     }
     if (ask.containsKey(orderSymbol)) {
       tempask = ask.get(orderSymbol);
     }
     // add the changed order back to the books.
     addNewOrder(renewOrder, orderSymbol, tempbid, tempask);
   }
   // return the symbol of the cancel and replace order.
   return orderSymbol;
 }
Пример #2
0
 /**
  * This result method is to get all things done by using the method build above. It get all the
  * orders and deal with them. Every time right after one oder has been solved, it will print out
  * the best bid price and ask price for the name that the message belonged to.
  */
 public static void result(Iterator<Message> myiter, Boolean flag) {
   // get a new book
   book book = new book();
   // this recursion will not end until the mylist is empty.
   while (myiter.hasNext()) {
     // if the next item in mylist is a new Order.
     Object mymessage = myiter.next();
     // be prepared to get the certain bidbook and askbook
     Hashtable<Double, LinkedList<NewOrderImpl>> tempbid =
         new Hashtable<Double, LinkedList<NewOrderImpl>>();
     Hashtable<Double, LinkedList<NewOrderImpl>> tempask =
         new Hashtable<Double, LinkedList<NewOrderImpl>>();
     // if the next item is a new order
     if (mymessage instanceof NewOrderImpl) {
       // make the order a NewOrderImpl
       NewOrderImpl myneworder = (NewOrderImpl) mymessage;
       // get the symbol of the order
       String mysymbol = myneworder.getSymbol();
       // if the bidbook of the symbol is already built, fetch the bidbook
       if (bid.containsKey(mysymbol)) {
         tempbid = bid.get(mysymbol);
       }
       // if the askbook of the symbol is already build, fetch the askbook
       if (ask.containsKey(mysymbol)) {
         tempask = ask.get(mysymbol);
       }
       // add the new order into the books.
       book.addNewOrder(myneworder, mysymbol, tempbid, tempask);
       // if the flag is true, print out the information
       if (flag) {
         // if there is no bid orders in that bidbook, return Double.MIN_VALUE, and print out that
         // there is no bid orders.
         if (book.getHighestBid(tempbid) == Double.MIN_VALUE)
           System.out.println(mysymbol + " Best Bid Price:  no bid orders");
         // else print out the best bid price
         else System.out.println(mysymbol + " Best Bid Price:  " + book.getHighestBid(tempbid));
         // if there is no ask orders in that askbook, return Double.MAX_VALUE, and print out that
         // there is no ask orders.
         if (book.getLowestAsk(tempask) == Double.MAX_VALUE)
           System.out.println(mysymbol + " Best Ask Price:  no ask orders");
         // else print out the best ask price
         else System.out.println(mysymbol + " Best Ask Price:  " + book.getLowestAsk(tempask));
       }
     }
     // if the next item in mylist is a Order CxR.
     else if (mymessage instanceof OrderCxRImpl) {
       // make the item a OrderCxRImpl, then use the cxrOrder method to deal the order, and get its
       // symbol
       String mysymbol = book.cxrOrder((OrderCxRImpl) mymessage);
       // fetch the bidbook and askbook of that symbol
       tempbid = bid.get(mysymbol);
       tempask = ask.get(mysymbol);
       // if the flag is true, print out the information
       if (flag) {
         // if there is no bid orders in that bidbook, return Double.MIN_VALUE, and print out that
         // there is no bid orders.
         if (book.getHighestBid(tempbid) == Double.MIN_VALUE)
           System.out.println(mysymbol + " Best Bid Price:  no bid orders");
         // else print out the best bid price
         else System.out.println(mysymbol + " Best Bid Price:  " + book.getHighestBid(tempbid));
         // if there is no ask orders in that askbook, return Double.MAX_VALUE, and print out that
         // there is no ask orders.
         if (book.getLowestAsk(tempask) == Double.MAX_VALUE)
           System.out.println(mysymbol + " Best Ask Price:  no ask orders");
         // else print out the best ask price
         else System.out.println(mysymbol + " Best Ask Price:  " + book.getLowestAsk(tempask));
       }
     }
   }
 }