HOME FORUMS BROKERS SOFTWARE BOOKS CONTACT US
Elite Trader Your Account  •  Become a Member  •  Help  •  Search    
    Forums ›› Technically Speaking ›› Order Execution ›› help! Can't get limit orders to work  


Post A Reply
    
lymn
 

Registered: Aug 2012
Posts: 3

 

08-30-12 04:55 PM

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;
}

    Edit/Delete Quote Complain
2rosy
 

Registered: May 2012
Posts: 336

 

08-31-12 02:36 AM

where is dev and price coming from?

    Edit/Delete Quote Complain
lymn
 

Registered: Aug 2012
Posts: 3

 

08-31-12 04:04 AM

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

    Edit/Delete Quote Complain
2rosy
 

Registered: May 2012
Posts: 336

 

08-31-12 01:07 PM


Quote from 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



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

    Edit/Delete Quote Complain
lymn
 

Registered: Aug 2012
Posts: 3

 

09-14-12 03:21 AM

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

    Edit/Delete Quote Complain
    
Post A Reply


Receive an email whenever a new post is added to this thread by subscribing to it.
 
Rate This Thread:

Forum Jump:
 

 

   Conduct Rules  -  Privacy Policy  -  Day Trader -  Day Trader Forum -  Best Trading Software -  Sitemap Copyright © 2013, Elite Trader. All rights reserved.    
 
WHILE YOU'RE HERE, TAKE A MINUTE TO VISIT SOME OF OUR SPONSORS:
Advantage Futures
Futures Brokerage & Clearing
AMP Global Clearing
Futures and FX Trading
Bright Trading
Professional Equities Trading
CTS
Futures Trading Software
DaytradingBias.com
Professional Trading Analytics
ECHOtrade
Professional Trading Firm
eSignal
Trading Software Provider
FXCM
Forex Trading Services
Global Futures
Futures, Options & FX Trading
Interactive Brokers
Pro Gateway to World Markets
JC Trading Group
Direct Access Trading
MB Trading
Direct Access Trading
MultiCharts
Trading Software Provider
NinjaTrader
Trading Software Provider
OANDA
Currency Trading
optionshouse
Option Trading & Education
Rithmic
Futures Trade Execution Platform
SpeedTrader
Direct Access Trading
SpreadProfessor
Spread Trading Instruction
thinkorswim by TD Ameritrade
Direct Access TradingAdvertisement
TradersStudio
System Building & Backtesting
Trading Technologies
Trading Software Provider
Trend Following
Trading Systems Provider