Market orders go through just fine, but when I place a limit order the TWS doesn't repsond. The relevant code is below...am I just forgetting some silly little thing?? public void run() { try { connectToTWS(); Contract contract = createContract(symbol, "STK", "SMART", "USD"); Order order = createOrder(action, shares, "LMT"); if (action.equals("BUY")) { order.m_lmtPrice = price*(1+dev); } if (action.equals("SELL")) { order.m_lmtPrice = price*(1-dev); } nextIDupdated = false; int waitCount = 0; eClientSocket.reqIds(1); while (!nextIDupdated && waitCount < MAX_WAIT_COUNT) { sleep(WAIT_TIME); // Pause for 1 second waitCount++; } eClientSocket.placeOrder(nextID, contract, order); } catch (Throwable t) { System.out.println(t.getMessage()); } finally { disconnectFromTWS(); } } protected Order createOrder(String action, int quantity, String orderType) { Order order = new Order(); order.m_action = action; order.m_totalQuantity = quantity; order.m_orderType = orderType; order.m_overridePercentageConstraints= true; return order; } protected Contract createContract(String symbol, String securityType, String exchange, String currency) { return createContract(symbol, securityType, exchange, currency, null, null, 0.0); } protected Contract createContract(String symbol, String securityType, String exchange, String currency, String expiry, String right, double strike) { Contract contract = new Contract(); contract.m_symbol = symbol; contract.m_secType = securityType; contract.m_exchange = exchange; contract.m_currency = currency; if (expiry != null) { contract.m_expiry = expiry; } if (strike != 0.0) { contract.m_strike = strike; } if (right != null) { contract.m_right = right; } return contract; }
The method run is part of a class and those values are floats that that are passed in when the class is instantiated as an object. Basically, price is the price of the stock when I decided to buy or sell it and dev is a percentage of the price that I'm willing to budge. If I replace "LMT" with "MKT" everything works, but I might get screwed over if the price moves a great deal in a short amount of time
I just figured it out with your help! If you send TWS a limit price that has more than 2 digits after the decimal it rejects the order