Hi,
Below is the Java method I use to connect to the TWS API. I am still in the process of building my trading system and so I have the need to run my main method, which calls this requestMarketData, via IntelliJ. Once I confirm whatever my recent change was worked or didnt work, I then stop the main method.
Ideally, while I am already logged into TWS, I would simply just run my main method again to connect to the API and test another change. Instead, I need to close TWS, reopen it, login, then run my code. Is there a way to handle this??
public void requestMarketData(String ticker) {
Contract contract = contract(ticker);
int tickId = 1;
client.eConnect(BROKER_CONNECTION_IP, BROKER_CONNECTION_PORT, 0);
client.reqMarketDataType(MARKET_DATA_TYPE);
client.reqMktData(tickId, contract, TICK_STRING,
false /* Snapshot */, false /* Regulatory Snapshot */, null /* MktDataOptions */);
reader = new EReader(client, signal);
reader.start();
new Thread(() -> {
while (client.isConnected()) {
signal.waitForSignal();
try {
reader.processMsgs();
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
}
}).start();
if (!isConnected) return;
client.eDisconnect();
}