|
Attention! Read the forum rules carefully before posting a topic.
Try to find an answer in Wiki before asking a question. Submit programming questions in this forum only. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
history.getLastTick throws Exception although Instrument is subscribed |
yoursong
|
Post subject: history.getLastTick throws Exception although Instrument is subscribed |
Post rating: 0
|
Posted: Wed 01 Feb, 2012, 17:17
|
|
User rating: 0
Joined: Fri 19 Aug, 2011, 20:29 Posts: 45 Location: Germany,
|
Latest API in live:
According to javadoc history.getLastTick only throws an Exception if the instrument being requested is not active. Is active something different than subscribed?
main.java .... //subscribe to the instruments Set<Instrument> instruments = new HashSet<Instrument>(); instruments.add(Instrument.EURUSD); LOGGER.info("Subscribing instruments..."); client.setSubscribedInstruments(instruments); ....
strategy.java onStart():
for (Instrument in : context.getSubscribedInstruments()) { console.getOut().println("subscribed to: "+in.toString()); }
log output: "subscribed to: EUR/USD"
Code in question (called at end of onStart in Strategy):
long last_tick=history.getLastTick(Instrument.EURUSD).getTime();
2012-02-01 17:10:38.902 ERROR DCClientImpl$DefaultStrategyExceptionHandler - Exception thrown while running onStart method: null java.lang.NullPointerException
Desktop live platform the same code works.
|
|
|
|
 |
yoursong
|
Post subject: Re: history.getLastTick throws Exception although Instrument is subscribed |
Post rating: 0
|
Posted: Wed 01 Feb, 2012, 17:31
|
|
User rating: 0
Joined: Fri 19 Aug, 2011, 20:29 Posts: 45 Location: Germany,
|
Could it be that lasttick / general history based methods can only be called after the platform has received its first tick(s)?
e.g. those methods cannot be called in the standalone api in onStart() since there have been no ticks / history connection created?
This would also explain why this code works on the desktop platform since the platform / feed itself has already been running before the strategy and received ticks.
|
|
|
|
 |
yoursong
|
Post subject: Re: history.getLastTick throws Exception although Instrument is subscribed |
Post rating: 0
|
Posted: Wed 01 Feb, 2012, 17:52
|
|
User rating: 0
Joined: Fri 19 Aug, 2011, 20:29 Posts: 45 Location: Germany,
|
The code works in onBar() in standalone too. It should be updated in documentation (i couldn't find any reference to this case) that some history methods only work once first ticks/bars/whatever have been received in standalone.
|
|
|
|
 |
yoursong
|
Post subject: Re: history.getLastTick throws Exception although Instrument is subscribed |
Post rating: 0
|
Posted: Wed 01 Feb, 2012, 19:21
|
|
User rating: 0
Joined: Fri 19 Aug, 2011, 20:29 Posts: 45 Location: Germany,
|
Workaround:
Put your history stuff at the end of onStart and call sleep before it:
Thread.sleep(30000);
Alternatively you could probably loop getLastTick with try/catch until it doesnt throw an exception.
|
|
|
|
 |
API Support
|
Post subject: Re: history.getLastTick throws Exception although Instrument is subscribed |
Post rating: 0
|
Posted: Thu 02 Feb, 2012, 10:30
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
|
|
|
 |
yoursong
|
Post subject: Re: history.getLastTick throws Exception although Instrument is subscribed |
Post rating: 0
|
Posted: Fri 03 Feb, 2012, 14:39
|
|
User rating: 0
Joined: Fri 19 Aug, 2011, 20:29 Posts: 45 Location: Germany,
|
According to context.getSubscribedInstruments() the Instrument is already subscribed. I still have to sleep for some time before i can call the mentioned methods.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|