softwarespartan / IB4m

Interactive Brokers API for Matlab
GNU General Public License v2.0
62 stars 21 forks source link

price condition #87

Open ciaoitaly opened 4 years ago

ciaoitaly commented 4 years ago

Hi Abel,

I am not sure you received a message from post I did yesterday on an old issue so I am doing a new issue to make sure you get it. I am trying to place an order using pricecondition and I get following error message 1 133 Submit new order failed

Can you please help me to identify what doesn't work? Thanks so much !!!

id = 1; session = TWS.Session.getInstance(); [buf,lh] = TWS.initBufferForEvent(TWS.Events.EXECUTIONDETAILS); session.eClientSocket.eConnect('',7123,25); contract = com.ib.client.Contract(); contract.localSymbol('NGH0');contract.secType('FUT'); contract.exchange('NYMEX');contract.currency('USD'); order = com.ib.client.Order(); order.account('U12345678'); order.orderType('LMT');order.lmtPrice(1.9); order.action('BUY');order.totalQuantity(1);

order.conditionsCancelOrder(true); type = com.ib.client.OrderConditionType.Price(); priceCondition = com.ib.client.OrderCondition.create(type);

priceCondition.conId(id); %same as order id and contract id without conditions priceCondition.exchange('NYMEX'); priceCondition.price(1.9); priceCondition.conjunctionConnection(false); %only one price condition priceCondition.triggerMethod(2); %last priceCondition.isMore(true); order.conditions.add(priceCondition);

% place the order with contract and order specifications session.eClientSocket.placeOrder(id,contract,order); pause(1);

ciaoitaly commented 4 years ago

Hi Abel, can you pretty please help me? I can't find a solution, been trying nonstop.

Despair2000 commented 4 years ago

I have never worked with this kind of conditional orders but I'm pretty sure that setting priceCondition.conId requires the conid for the security you want to use to trigger the condition. Setting it to 1 like in your code will not work.

ciaoitaly commented 4 years ago

Thanks Despair2000, it is not that. I request id through Matlab using orderid(ib) so the id number is not 1. Sorry about that, any other ideas where my issue could be ?

Despair2000 commented 4 years ago

But you do not need the order Id but the conId of the contract.

kevinhedgefund commented 4 years ago

priceCondition.conId(id); conid is for underlying vehicle of the price condition. My code works fine with price conditions.