Beispiel #1
0
  @Test
  public void testGetDefaultTagList() {
    List<TagValue> expected = new ArrayList<>();
    expected.add(new TagValue("XYZ", "XYZ"));

    assertEquals(expected, IbUtils.getDefaultTagList());
  }
Beispiel #2
0
  @Test
  public void testGetContractMultiplier_NullMultiplier() {
    FuturesTicker ticker = new FuturesTicker();
    ticker.setSymbol("HG");

    assertNull(IbUtils.getIbMultiplier(ticker));
  }
Beispiel #3
0
  @Test
  public void testGetDefaultTagVector() {
    Vector<TagValue> expected = new Vector<>();
    expected.add(new TagValue("XYZ", "XYZ"));

    assertEquals(expected, IbUtils.getDefaultTagVector());
  }
Beispiel #4
0
  @Test
  public void testGetContractMultiplier() {
    FuturesTicker ticker = new FuturesTicker();
    ticker.setSymbol("ZC");
    ticker.setContractMultiplier(new BigDecimal(50.0));

    assertEquals(new BigDecimal(5000.0), IbUtils.getIbMultiplier(ticker));

    ticker.setSymbol("ZS");
    assertEquals(new BigDecimal(5000.0), IbUtils.getIbMultiplier(ticker));

    ticker.setSymbol("ZW");
    assertEquals(new BigDecimal(5000.0), IbUtils.getIbMultiplier(ticker));

    ticker.setSymbol("HG");
    assertEquals(new BigDecimal(50.0), IbUtils.getIbMultiplier(ticker));
  }
Beispiel #5
0
 @Test
 public void testGetOrderStatus() {
   assertEquals(OrderStatus.Status.NEW, IbUtils.getOrderStatus("PendingSubmit"));
   assertEquals(OrderStatus.Status.PENDING_CANCEL, IbUtils.getOrderStatus("PendingCancel"));
   assertEquals(OrderStatus.Status.NEW, IbUtils.getOrderStatus("PreSubmitted"));
   assertEquals(OrderStatus.Status.NEW, IbUtils.getOrderStatus("Submitted"));
   assertEquals(OrderStatus.Status.CANCELED, IbUtils.getOrderStatus("Cancelled"));
   assertEquals(OrderStatus.Status.FILLED, IbUtils.getOrderStatus("Filled"));
   assertEquals(OrderStatus.Status.CANCELED, IbUtils.getOrderStatus("Inactive"));
   assertEquals(OrderStatus.Status.UNKNOWN, IbUtils.getOrderStatus("foo"));
 }
Beispiel #6
0
 @Test
 public void testGetQuoteType() {
   assertEquals(QuoteType.BID, IbUtils.getQuoteType(1));
   assertEquals(QuoteType.ASK, IbUtils.getQuoteType(2));
   assertEquals(QuoteType.LAST, IbUtils.getQuoteType(4));
   assertEquals(QuoteType.CLOSE, IbUtils.getQuoteType(9));
   assertEquals(QuoteType.OPEN, IbUtils.getQuoteType(14));
   assertEquals(QuoteType.VOLUME, IbUtils.getQuoteType(8));
   assertEquals(QuoteType.UNKNOWN, IbUtils.getQuoteType(99));
 }
Beispiel #7
0
 @Test
 public void testTranslateFuturesSymbol() {
   assertEquals("CAD", IbUtils.translateToIbFuturesSymbol("6C"));
   assertEquals("EUR", IbUtils.translateToIbFuturesSymbol("6E"));
   assertEquals("JPY", IbUtils.translateToIbFuturesSymbol("6J"));
   assertEquals("CHF", IbUtils.translateToIbFuturesSymbol("6S"));
   assertEquals("GBP", IbUtils.translateToIbFuturesSymbol("6B"));
   assertEquals("GBP", IbUtils.translateToIbFuturesSymbol("GBP"));
 }
Beispiel #8
0
  @Test
  public void testGetTif() {
    TradeOrder.Duration[] values = TradeOrder.Duration.values();
    for (TradeOrder.Duration value : values) {
      assertNotNull(IbUtils.getTif(value));
    }

    assertEquals("DAY", IbUtils.getTif(TradeOrder.Duration.DAY));
    assertEquals("GTC", IbUtils.getTif(TradeOrder.Duration.GOOD_UNTIL_CANCELED));
    assertEquals("IOC", IbUtils.getTif(TradeOrder.Duration.FILL_OR_KILL));
    assertEquals("GTD", IbUtils.getTif(TradeOrder.Duration.GOOD_UTNIL_TIME));
    assertEquals("OPG", IbUtils.getTif(TradeOrder.Duration.MARKET_ON_OPEN));
    assertEquals("DAY", IbUtils.getTif(null));
  }
Beispiel #9
0
  @Test
  public void testGetSecurityType() {
    InstrumentType[] values = InstrumentType.values();
    for (InstrumentType value : values) {
      assertNotNull(IbUtils.getSecurityType(value));
    }

    assertEquals("STK", IbUtils.getSecurityType(InstrumentType.STOCK));
    assertEquals("OPT", IbUtils.getSecurityType(InstrumentType.OPTION));
    assertEquals("CASH", IbUtils.getSecurityType(InstrumentType.FOREX));
    assertEquals("FUT", IbUtils.getSecurityType(InstrumentType.FUTURES));
    assertEquals("IND", IbUtils.getSecurityType(InstrumentType.INDEX));
    assertEquals("BAG", IbUtils.getSecurityType(InstrumentType.COMBO));
  }
Beispiel #10
0
  @Test
  public void testGetAction() {
    TradeDirection[] values = TradeDirection.values();
    for (TradeDirection value : values) {
      assertNotNull(IbUtils.getAction(value));
    }

    assertEquals("BUY", IbUtils.getAction(TradeDirection.BUY));
    assertEquals("SELL", IbUtils.getAction(TradeDirection.SELL));
    assertEquals("SELL", IbUtils.getAction(TradeDirection.SELL_SHORT));
    assertEquals("BUY", IbUtils.getAction(TradeDirection.BUY_TO_COVER));
    try {
      IbUtils.getAction(null);
      fail();
    } catch (IllegalStateException ex) {
      // this should happen
    }
  }
Beispiel #11
0
  @Test
  public void testGetOrderType() {

    // First make sure we have a mapping for all types.
    TradeOrder.Type[] values = TradeOrder.Type.values();
    for (TradeOrder.Type value : values) {
      assertNotNull(IbUtils.getOrderType(value));
    }

    assertEquals("MKT", IbUtils.getOrderType(TradeOrder.Type.MARKET));
    assertEquals("LMT", IbUtils.getOrderType(TradeOrder.Type.LIMIT));
    assertEquals("STP", IbUtils.getOrderType(TradeOrder.Type.STOP));
    assertEquals("MKT", IbUtils.getOrderType(TradeOrder.Type.MARKET_ON_OPEN));
    assertEquals("MOC", IbUtils.getOrderType(TradeOrder.Type.MARKET_ON_CLOSE));

    try {
      IbUtils.getOrderType(null);
      fail();
    } catch (IllegalStateException ex) {
      // this should happen
    }
  }