Пример #1
0
 @Test()
 public void testDummyTraderCreation() {
   DummyTrader trader = new DummyTrader(marketFeed);
   trader.connect();
   assertEquals(trader.isConnected(), true);
   assertEquals(trader.getOpenOrder(symbol, OrderType.MARKET), null);
   assertEquals(trader.getOpenOrders().size(), 0);
   assertEquals(trader.getOpenOrders(symbol, null).size(), 0);
   assertEquals(trader.getPortfolio().getPositions().size(), 0);
   assertEquals(trader.getPortfolio().getPosition(symbol).getQuantity(), 0);
 }
Пример #2
0
  @Test()
  public void testDummyTraderPlaceOrder() {
    DummyTrader trader = new DummyTrader(marketFeed);
    trader.connect();

    final boolean[] listenerCalled = new boolean[4];
    trader.addOrderListener(
        new OrderListener() {
          @Override
          public void onOrderPlaced(OpenOrder openOrder) {
            assertEquals(openOrder.getOrderId(), 1);
            listenerCalled[0] = true;
          }

          @Override
          public void onOrderFilled(OpenOrder openOrder, Position position) {
            assertEquals(openOrder.getOrderId(), 1);
            assertEquals(position.getQuantity(), 1);
            listenerCalled[1] = true;
          }

          @Override
          public void onOrderFailed(OpenOrder openOrder) {}

          @Override
          public void onOrderCancelled(OpenOrder openOrder) {}
        });

    OpenOrder openOrder = trader.placeOrder(symbol, OrderType.MARKET, 1, -1.0, -1.0, "test");
    assertEquals(trader.getOpenOrder(symbol, OrderType.MARKET) != null, true);
    assertEquals(trader.getOpenOrders().size(), 1);
    assertEquals(trader.getOpenOrders(symbol, OrderType.MARKET).size(), 1);
    assertEquals(openOrder.getAction(), OrderAction.BUY);
    assertEquals(openOrder.getType(), OrderType.MARKET);
    assertEquals(openOrder.getAvgFillPrice(), Double.NaN);
    assertEquals(openOrder.getCommission(), Double.NaN);
    assertEquals(openOrder.getLastFillPrice(), Double.NaN);
    assertEquals(openOrder.getOrderDate(), date);
    assertEquals(openOrder.getOrderId(), 1);
    assertEquals(openOrder.getPrice(), -1.0);
    assertEquals(openOrder.getStopPrice(), -1.0);
    assertEquals(openOrder.getTrailStopOffset(), -1.0);
    assertEquals(openOrder.getQuantity(), 1);
    assertEquals(openOrder.getQuantityFilled(), 0);
    assertEquals(openOrder.getReference(), "test");
    assertEquals(listenerCalled[0], true);

    Util.callMethod(trader, "processOpenOrders", date);

    assertEquals(listenerCalled[1], true);
  }