reqMktData() and tickPrice () issue

I want to get the last sold tick price ( option 4 of tickPrice() callback function but it does not seem to work ..please help!!! THANKS

( once you see the code the question is why callPrice() call back is not executed automatically when last price is there?

------------------skeleton code and execution results:


private float symbolLastPrice = 0;

private boolean finishedTickPrice = false;


Contract con1 = new Contract();

con1.m_symbol = "TNA"
con1.m_secType = "STK";
con1.m_currency = "USD";
con1.m_exchange = "SMART";

int tickerId = 5888;

debug("Ready to call getMktdata for: " + symb[jj]);

TWSSocket.reqMktData(tickerId, con1, "", true);

/*

Loop to check if call back tickPrice() has the value
if tickPrice is executed then finishedTickPrice will be
true which will end the loop
*/


while (!finishedTickPrice) {
debug(" in while loop Time: " + currentTime());
PL.justSleepDangit(1000); // just sleep and waiting
}

debug("The tick value is: " + symbolLastPrice);


----------------------- tickPrice() code -------------------------

public void tickPrice(int tickerId, int field, double price, int canAutoExecute) {
finishedTickPrice = true;
if (field == 4) {
symbolLastPrice = (float)price;
debug("Wow I have the price, symbolLastPrice is : " + symbolLastPrice);
}
}


---------------- RESULTS with the while loop

vacctPL.log: Ready to call getMktdata for: TNA

vacctPL.log: in while loop Time: 17:21
vacctPL.log: in while loop Time: 17:21
vacctPL.log: in while loop Time: 17:21
vacctPL.log: in while loop Time: 17:21
vacctPL.log: in while loop Time: 17:21
vacctPL.log: in while loop Time: 17:21
vacctPL.log: in while loop Time: 17:21
vacctPL.log: in while loop Time: 17:21

I had to kill it...

---------------- RESULTS without the while loop

vacctPL.log: Ready to call getMktdata for: TNA

vacctPL.log: Wow I have the price, symbolLastPrice is : 44.14
 
get rid of this


while (!finishedTickPrice) {
debug(" in while loop Time: " + currentTime());
PL.justSleepDangit(1000); // just sleep and waiting
}
 
This while check would not hurt if used correctly with some timeout feature. If all works fine tickPrice() should set inishedTickPrice = true;

It was my mistake which I correctly later:

Hope this is helpful to someone someday:

Message is NEVER NEVER stack EClientSocket Method:

in my program - My wrong call flow was:

reqExecution ( which does callout to execDetails & execDetailsEnd)
within execDetailsEnd I called reqMktData which calls tickPrice(). ** That is a mistake

so I corrected by:

reqExecution ( which called execDetails and execDetailsEnd)
Once execDetailsEnd () finished THEN I called reqMktData and it works great with the while loop.

I added some additional logic so while will exit after some time - so my program in not hung.

Thanks for your help.
 
Back
Top