Exemplo n.º 1
0
  private static void doTestSet1(String stockSymbol) {
    try {
      System.out.println(
          "TS1.1) Change Market State to PREOPEN then to OPEN. ANN & REX receive PREOPEN and OPEN Market messages");
      ProductService.getInstance().setMarketState(MarketState.PREOPEN);
      ProductService.getInstance().setMarketState(MarketState.OPEN);
      System.out.println();

      System.out.println(
          "TS1.2) User "
              + u1.getUserName()
              + " cancels a non-existent order - should result in an exception");
      ProductService.getInstance().submitOrderCancel(stockSymbol, BookSide.BUY, "ABC123");
      System.out.println("Did not catch non-existent Stock error!");
    } catch (Exception ex) {
      System.out.println("Exception properly caught error: " + ex.getMessage());
      System.out.println();
    }

    try {
      System.out.println(
          "TS1.3) User "
              + u1.getUserName()
              + " cancels a non-existent quote - No exception should be thrown");
      ProductService.getInstance().submitQuoteCancel(u1.getUserName(), stockSymbol);
      System.out.println("Did not catch non-existent quote problem!!");
      System.out.println();
    } catch (Exception ex) {
      System.out.println("Caught Exception as expected: " + ex.getMessage());
      System.out.println();
    }

    try {
      System.out.println("TS1.4) Try to create a bad product - null String");
      ProductService.getInstance().createProduct(null);
      System.out.println("Did not catch bad product - null String problem!!");
      System.out.println();
    } catch (Exception ex) {
      System.out.println("Caught Exception on bad product: " + ex.getMessage());
      System.out.println();
    }

    try {
      System.out.println("TS1.5) User " + u1.getUserName() + " enters order on non-existent stock");
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  "X11",
                  PriceFactory.makeLimitPrice("$641.10"),
                  111,
                  BookSide.BUY));
      System.out.println("Did not catch non-existent Stock error!");
    } catch (Exception ex) {
      System.out.println("Caught Exception on order for bad class: " + ex.getMessage());
      System.out.println();
    }

    try {
      System.out.println("TS1.6) User " + u1.getUserName() + " enters quote on non-existent stock");
      ProductService.getInstance()
          .submitQuote(
              new Quote(
                  u1.getUserName(),
                  "X11",
                  PriceFactory.makeLimitPrice("$641.10"),
                  120,
                  PriceFactory.makeLimitPrice("$641.15"),
                  150));
      System.out.println("Did not catch non-existent Stock error!");
    } catch (Exception ex) {
      System.out.println("Caught Exception on quote for bad class: " + ex.getMessage());
      System.out.println();
    }
    System.out.println("------------------");
  }
Exemplo n.º 2
0
  private static void doTestSet3(String stockSymbol) {

    System.out.println(
        "TS3.1) Change Market State to Closed then PreOpen the Market State. Rex & ANN should receive one market message for each state");
    try {
      ProductService.getInstance().setMarketState(MarketState.CLOSED);
      ProductService.getInstance().setMarketState(MarketState.PREOPEN);
    } catch (Exception ex) {
      System.out.println("Set market State caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS3.2) User "
            + u2.getUserName()
            + " enters a quote, REX and ANN receive Current Market messages: ");
    try {
      ProductService.getInstance()
          .submitQuote(
              new Quote(
                  u2.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.10"),
                  120,
                  PriceFactory.makeLimitPrice("$641.15"),
                  150));
    } catch (Exception ex) {
      System.out.println("Submitting a Quote caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS3.3) User "
            + u1.getUserName()
            + " enters several BUY orders, REX and ANN receive 5 Current Market updates each: ");
    try {
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.10"),
                  111,
                  BookSide.BUY));
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.11"),
                  222,
                  BookSide.BUY));
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.12"),
                  333,
                  BookSide.BUY));
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.13"),
                  444,
                  BookSide.BUY));
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.14"),
                  555,
                  BookSide.BUY));
    } catch (Exception ex) {
      System.out.println("Submitting Orders caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS3.4) Verify Book [should be 5 BUY entries and 1 sell entry]: ");
    try {
      printOutBD(ProductService.getInstance().getBookDepth(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting book depth for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS3.5) User "
            + u2.getUserName()
            + " enters several Sell orders - no Current Market received - none of the orders improves the market: ");
    try {
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u2.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.16"),
                  111,
                  BookSide.SELL));
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u2.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.17"),
                  222,
                  BookSide.SELL));
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u2.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.18"),
                  333,
                  BookSide.SELL));
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u2.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.19"),
                  444,
                  BookSide.SELL));
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u2.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.20"),
                  555,
                  BookSide.SELL));
    } catch (Exception ex) {
      System.out.println("Submitting Orders caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS3.6) Verify Book [should be 5 BUY entries and 6 sell entries]: ");
    try {
      printOutBD(ProductService.getInstance().getBookDepth(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting book depth for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS3.7) User "
            + u1.getUserName()
            + " enters a BUY order that won't trade as market is in PREOPEN. Rex & Ann receive Current Market updates: ");
    try {
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.15"),
                  105,
                  BookSide.BUY));
    } catch (Exception ex) {
      System.out.println("Submitting an Order caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS3.8) Change Market State to OPEN State...Trade should occur.");
    System.out.println("     ANN & REX should receive OPEN Market Message");
    System.out.println(
        "     ANN & REX each receive a Fill Msg, Current Market Msg, Last Sale Msg, & Ticker Msg:");
    try {
      ProductService.getInstance().setMarketState(MarketState.OPEN);
    } catch (Exception ex) {
      System.out.println("Set market State caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS3.9) Verify Resulting Book [should be 5 buy-side entries, 6 sell-side entries]: ");
    try {
      printOutBD(ProductService.getInstance().getBookDepth(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting book depth for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS3.10) User "
            + u1.getUserName()
            + " enters a big MKT BUY order to trade with all the SELL side:");
    System.out.println(
        "        ANN receives 6 Fill Messages, a Current Market, a Last Sale & a Ticker");
    System.out.println(
        "        REX receives 1 Fill Message, a Current Market, a Last Sale & a Ticker, and a cancel for the 40 remaining MKT order quantity not traded");
    try {
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeMarketPrice(),
                  1750,
                  BookSide.BUY));
    } catch (Exception ex) {
      System.out.println("Submitting an Order caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS3.11) Verify Resulting Book [should be 5 buy-side entries, NO sell-side entries]: ");
    try {
      printOutBD(ProductService.getInstance().getBookDepth(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting book depth for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS3.12) Get Orders with Remaining Quantity: ");
    ArrayList<TradableDTO> ords;
    try {
      ords = ProductService.getInstance().getOrdersWithRemainingQty(u1.getUserName(), stockSymbol);
      for (TradableDTO dto : ords) {
        System.out.println(dto);
      }
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting  Orders With Remaining Qty: "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS3.13) Change Market State to CLOSED State. Both users should get a Market message.");
    System.out.println("        REX receives 5 Cancel Messages, and a Current Market Update.");
    System.out.println("        ANN receives 1 Cancel Message, and a Current Market Update.");
    try {
      ProductService.getInstance().setMarketState(MarketState.CLOSED);
    } catch (Exception ex) {
      System.out.println("Set market State caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS3.14) Verify Book: ");
    try {
      printOutBD(ProductService.getInstance().getBookDepth(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting book depth for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();
    System.out.println("------------------");
  }
Exemplo n.º 3
0
  private static void doTestSet4(String stockSymbol) {
    System.out.println(
        "TS4.1) Change Market State to PREOPEN then to OPEN. ANN & REX receive Market PREOPEN and OPEN messages:");
    try {
      ProductService.getInstance().setMarketState(MarketState.PREOPEN);
      ProductService.getInstance().setMarketState(MarketState.OPEN);
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when setting market state "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS4.2) User "
            + u1.getUserName()
            + " enters a BUY order, ANN & REX receive Current Market message:");
    try {
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice(64130),
                  369,
                  BookSide.BUY));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when entering order "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS4.3) User " + u2.getUserName() + " enters a SELL order.");
    System.out.println(
        "    ANN & REX receive 1 Fill Message each, as well as a Current Market, a Last Sale & a Ticker message:");
    try {
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u2.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice(64130),
                  369,
                  BookSide.SELL));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when entering order "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS4.4) User "
            + u1.getUserName()
            + " enters a MKT BUY order. REX receives cancel message because there is no market to trade with:");
    try {
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeMarketPrice(),
                  456,
                  BookSide.BUY));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when entering order "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS4.5) User "
            + u1.getUserName()
            + " enters a BUY order, ANN & REX receive Current Market message:");
    try {
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("641.1"),
                  151,
                  BookSide.BUY));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when entering order "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS4.6) User " + u2.getUserName() + " enters a SELL order to trade.");
    System.out.println(
        "    ANN & REX receive 1 Fill Message each, as well as a Current Market, a Last Sale & a Ticker message:");
    try {
      ProductService.getInstance()
          .submitOrder(
              new Order(
                  u2.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice(64110),
                  51,
                  BookSide.SELL));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when entering order "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS4.7) Change Market State to CLOSED State...Both users should get a Market message, many Cancel Messages, and a Current Market Update.");
    try {
      ProductService.getInstance().setMarketState(MarketState.CLOSED);
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when setting market state "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS4.8) Verify Book: ");
    try {
      printOutBD(ProductService.getInstance().getBookDepth(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting book depth for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();
  }
Exemplo n.º 4
0
  private static void doTestSet2(String stockSymbol) {
    System.out.println(
        "TS2.1) Check the initial Market State (should say OPEN): "
            + ProductService.getInstance().getMarketState()
            + "\n");

    System.out.println("TS2.2) Create a new Stock product in our Trading System: " + stockSymbol);
    try {
      ProductService.getInstance().createProduct(stockSymbol);
      System.out.println("Product " + stockSymbol + " successfully created!");
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when creating product "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS2.3) Query the ProductService for all Stock products (should say ["
            + stockSymbol
            + "]): "
            + ProductService.getInstance().getProductList()
            + "\n");

    System.out.println("TS2.4) Change Market State to Closed and verify the Market State");
    try {
      ProductService.getInstance().setMarketState(MarketState.CLOSED);
      System.out.println("Product State: " + ProductService.getInstance().getMarketState());
    } catch (Exception ex) {
      System.out.println("Set market State caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS2.5) Change Market State to PreOpen and verify the Market State");
    try {
      ProductService.getInstance().setMarketState(MarketState.PREOPEN);
      System.out.println("Product State: " + ProductService.getInstance().getMarketState());
    } catch (Exception ex) {
      System.out.println("Set market State caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS2.6) Change Market State to Open and verify the Market State");
    try {
      ProductService.getInstance().setMarketState(MarketState.OPEN);
      System.out.println("Product State: " + ProductService.getInstance().getMarketState());
    } catch (Exception ex) {
      System.out.println("Set market State caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS2.7) User "
            + u1.getUserName()
            + " enters a quote, REX & ANN receive Current Market updates for GOOG [120@$641.10 - 150@$641.15]: ");
    try {
      ProductService.getInstance()
          .submitQuote(
              new Quote(
                  u1.getUserName(),
                  stockSymbol,
                  PriceFactory.makeLimitPrice("$641.10"),
                  120,
                  PriceFactory.makeLimitPrice("$641.15"),
                  150));
      System.out.println("Submitting a Quote was successful!");
    } catch (Exception ex) {
      System.out.println("Submitting a Quote caused an unexpected exception: " + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS2.8) Verify Quote is in Book [Should see buy & sell side as $641.10 x 120 and : $641.15 x 150]");
    try {
      printOutBD(ProductService.getInstance().getBookDepth(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting book depth for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS2.9) Get MarketDataDTO for "
            + stockSymbol
            + "(Your format might vary but the data content should be the same)");
    try {
      System.out.println(ProductService.getInstance().getMarketData(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting market data for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println(
        "TS2.10) Cancel the Quote, REX receives BUY and SELL side cancel messages, REX & ANN receive Current Market updated:");
    try {
      ProductService.getInstance().submitQuoteCancel(u1.getUserName(), stockSymbol);
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting market data for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS2.11) Verify Quote is NOT in Book: ");
    try {
      printOutBD(ProductService.getInstance().getBookDepth(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting book depth for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println("TS2.12) Get MarketDataDTO for " + stockSymbol);
    try {
      System.out.println(ProductService.getInstance().getMarketData(stockSymbol));
    } catch (Exception ex) {
      System.out.println(
          "Unexpected Exception occurred when getting market data for "
              + stockSymbol
              + ": "
              + ex.getMessage());
    }
    System.out.println();

    System.out.println("------------------");
  }