help! Can't get limit orders to work

Discussion in 'Order Execution' started by lymn, Aug 30, 2012.

  1. lymn


    Market orders go through just fine, but when I place a limit order the TWS doesn't repsond. The relevant code is I just forgetting some silly little thing??

    public void run() {
    try {
    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;
    while (!nextIDupdated && waitCount < MAX_WAIT_COUNT) {
    sleep(WAIT_TIME); // Pause for 1 second
    eClientSocket.placeOrder(nextID, contract, order);
    } catch (Throwable t) {
    } finally {
    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;
  2. 2rosy


    where is dev and price coming from?
  3. lymn


    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
  4. 2rosy


    what happens if you get rid of price and dev and just hard code some number for testing purposes?
  5. lymn


    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