public Contract getContract() { Contract c = new Contract(); c.m_conId = m_conid; c.m_symbol = m_symbol; c.m_secType = m_secType.toString(); c.m_expiry = m_expiry; c.m_strike = m_strike; c.m_right = m_right.getApiString(); c.m_multiplier = m_multiplier; c.m_exchange = m_exchange; c.m_currency = m_currency; c.m_localSymbol = m_localSymbol; c.m_tradingClass = m_tradingClass; c.m_primaryExch = m_primaryExch; c.m_secIdType = m_secIdType.getApiString(); c.m_secId = m_secId; if (m_underComp != null) { c.m_underComp = new UnderComp(); c.m_underComp.m_conId = m_underComp.conid(); c.m_underComp.m_delta = m_underComp.delta(); c.m_underComp.m_price = m_underComp.price(); } c.m_comboLegs = new Vector<ComboLeg>(); for (NewComboLeg leg : m_comboLegs) { c.m_comboLegs.add(leg.getComboLeg()); } return c; }
// This places orders and listens to orders status public void run() { try { // Make connection, wait for nextOrderId connectToTWS(); while (nextOrderId == -1) snooze(1000); puts("\nFind Contract Definitions for GOOG option"); Contract con1 = new Contract(); con1.m_symbol = "GOOG"; con1.m_secType = "OPT"; con1.m_expiry = "201301"; con1.m_strike = 500.0; con1.m_right = "C"; con1.m_multiplier = "100"; con1.m_exchange = "SMART"; con1.m_currency = "USD"; client.reqContractDetails(110, con1); puts("Request sent"); snooze(4000); puts("\nFind Contract Definitions for APPLE stock"); Contract aapl = new Contract(); aapl.m_symbol = "AAPL"; aapl.m_secType = "STK"; client.reqContractDetails(111, aapl); puts("Request sent"); snooze(4000); puts("\nSee? No reply..."); snooze(4000); } catch (Exception e) { e.printStackTrace(); } finally { disconnectFromTWS(); } }
void onOk() { m_rc = false; try { // set id m_id = Integer.parseInt(m_Id.getText()); // set contract fields m_contract.m_conId = ParseInt(m_conId.getText(), 0); m_contract.m_symbol = m_symbol.getText(); m_contract.m_secType = m_secType.getText(); m_contract.m_expiry = m_expiry.getText(); m_contract.m_strike = ParseDouble(m_strike.getText(), 0.0); m_contract.m_right = m_right.getText(); m_contract.m_multiplier = m_multiplier.getText(); m_contract.m_exchange = m_exchange.getText(); m_contract.m_primaryExch = m_primaryExch.getText(); m_contract.m_currency = m_currency.getText(); m_contract.m_localSymbol = m_localSymbol.getText(); m_contract.m_tradingClass = m_tradingClass.getText(); try { int includeExpired = Integer.parseInt(m_includeExpired.getText()); m_contract.m_includeExpired = (includeExpired == 1); } catch (NumberFormatException ex) { m_contract.m_includeExpired = false; } m_contract.m_secIdType = m_secIdType.getText(); m_contract.m_secId = m_secId.getText(); // set order fields m_order.m_action = m_action.getText(); m_order.m_totalQuantity = Integer.parseInt(m_totalQuantity.getText()); m_order.m_orderType = m_orderType.getText(); m_order.m_lmtPrice = parseStringToMaxDouble(m_lmtPrice.getText()); m_order.m_auxPrice = parseStringToMaxDouble(m_auxPrice.getText()); m_order.m_goodAfterTime = m_goodAfterTime.getText(); m_order.m_goodTillDate = m_goodTillDate.getText(); m_order.m_faGroup = m_faGroup; m_order.m_faProfile = m_faProfile; m_order.m_faMethod = m_faMethod; m_order.m_faPercentage = m_faPercentage; // set historical data fields m_backfillEndTime = m_BackfillEndTime.getText(); m_backfillDuration = m_BackfillDuration.getText(); m_barSizeSetting = m_BarSizeSetting.getText(); m_useRTH = Integer.parseInt(m_UseRTH.getText()); m_whatToShow = m_WhatToShow.getText(); m_formatDate = Integer.parseInt(m_FormatDate.getText()); m_exerciseAction = Integer.parseInt(m_exerciseActionTextField.getText()); m_exerciseQuantity = Integer.parseInt(m_exerciseQuantityTextField.getText()); m_override = Integer.parseInt(m_overrideTextField.getText()); ; // set market depth rows m_marketDepthRows = Integer.parseInt(m_marketDepthRowTextField.getText()); m_genericTicks = m_genericTicksTextField.getText(); m_snapshotMktData = m_snapshotMktDataTextField.isSelected(); m_marketDataType = m_marketDataTypeCombo.getSelectedIndex() + 1; } catch (Exception e) { Main.inform(this, "Error - " + e); return; } m_rc = true; setVisible(false); }