FuturesContractBuilder implements IContractBuilder<FuturesTicker> { public Contract buildContract(FuturesTicker ticker) { Contract contract = new Contract(); contract.m_currency = ticker.getCurrency(); contract.m_exchange = ticker.getExchange().getExchangeName(); contract.m_secType = IbUtils.getSecurityType(ticker.getInstrumentType()); contract.m_symbol = IbUtils.translateToIbFuturesSymbol( ticker.getSymbol() ); contract.m_expiry = IbUtils.getExpiryString(ticker.getExpiryMonth(), ticker.getExpiryYear()); ILocalSymbolBuilder localSymbolBuilder = LocalSymbolBuilderFactory.getLocalSymbolBuilder(ticker.getExchange()); contract.m_localSymbol = localSymbolBuilder.buildLocalSymbol(ticker.getSymbol(), ticker.getExpiryMonth(), ticker.getExpiryYear()); BigDecimal multiplier = IbUtils.getIbMultiplier(ticker); if (multiplier != null) { contract.m_multiplier = multiplier.toString(); } return contract; }  Contract buildContract(FuturesTicker ticker);  }
@Test public void testBuildContract_NoMultiplier() { FuturesTicker ticker = new FuturesTicker(); ticker.setCurrency("USD"); ticker.setExchange(Exchange.GLOBEX); ticker.setSymbol("HG"); ticker.setExpiryMonth(6); ticker.setExpiryYear(2015); Contract expected = new Contract(); expected.m_currency = "USD"; expected.m_exchange = Exchange.GLOBEX.getExchangeName(); expected.m_secType = "FUT"; expected.m_symbol = "HG"; expected.m_expiry = "201506"; expected.m_localSymbol = "HGM5"; assertEquals(expected, builder.buildContract(ticker) ); }
@Test public void testBuildContract_NoMultiplier_Grains() { FuturesTicker ticker = new FuturesTicker(); ticker.setCurrency("USD"); ticker.setExchange(Exchange.ECBOT); ticker.setSymbol("ZW"); ticker.setExpiryMonth(6); ticker.setExpiryYear(2015); Contract expected = new Contract(); expected.m_currency = "USD"; expected.m_exchange = Exchange.ECBOT.getExchangeName(); expected.m_secType = "FUT"; expected.m_symbol = "ZW"; expected.m_expiry = "201506"; expected.m_multiplier = "5000"; expected.m_localSymbol = "ZW JUN 15"; assertEquals(expected, builder.buildContract(ticker) ); }
@Test public void testBuildContract_WithMultiplier() { FuturesTicker ticker = new FuturesTicker(); ticker.setCurrency("USD"); ticker.setExchange(Exchange.ECBOT); ticker.setSymbol("ZW"); ticker.setExpiryMonth(6); ticker.setExpiryYear(2015); ticker.setContractMultiplier(new BigDecimal(50)); Contract expected = new Contract(); expected.m_currency = "USD"; expected.m_exchange = Exchange.ECBOT.getExchangeName(); expected.m_secType = "FUT"; expected.m_symbol = "ZW"; expected.m_expiry = "201506"; expected.m_multiplier = "5000"; expected.m_localSymbol = "ZW JUN 15"; assertEquals(expected, builder.buildContract(ticker) ); }