|
Attention! Read the forum rules carefully before posting a topic.
Submit JForex API bug reports in this forum only. Submit Converter issues in Converter Issues. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
IStrategy.onTick(...) != IHistory.readTicks(...) |
John11
|
Post subject: IStrategy.onTick(...) != IHistory.readTicks(...) |
Post rating: 0
|
Posted: Wed 23 Apr, 2014, 17:42
|
|
User rating: 3
Joined: Fri 11 Oct, 2013, 13:49 Posts: 34
|
Hello,
IStrategy.onTick:
2014-04-11 00:58:57.505,1.38906,1.38908 2014-04-11 00:58:58.823,1.38906,1.38908 2014-04-11 00:58:59.674,1.38905,1.38908
IHistory.readTicks:
2014-04-11 00:58:57.505,1.38906,1.38908 2014-04-11 00:58:58.274,1.38905,1.38908 2014-04-11 00:58:58.823,1.38906,1.38908 2014-04-11 00:58:59.674,1.38905,1.38908
it's different (onTick: 2014-04-11 00:58:58.274 not found) please help
|
|
|
|
|
hebasto
|
Post subject: Re: IStrategy.onTick(...) != IHistory.readTicks(...) |
Post rating: 1
|
Posted: Wed 23 Apr, 2014, 18:42
|
|
User rating: 96
Joined: Mon 09 Sep, 2013, 07:09 Posts: 287 Location: Ukraine, SHostka
|
|
|
|
|
John11
|
Post subject: Re: IStrategy.onTick(...) != IHistory.readTicks(...) |
Post rating: 0
|
Posted: Wed 23 Apr, 2014, 19:38
|
|
User rating: 3
Joined: Fri 11 Oct, 2013, 13:49 Posts: 34
|
hebasto wrote: thanks, but can You explain why tick not found in IHistory.readTicks? EUR/USD IStrategy.onTick: 2014-04-11 01:01:21.896 IHistory.readTicks: not found ------------- IHistory.readTicks: 2014-04-11 01:01:00.050,1.38911,1.38915 2014-04-11 01:01:13.858,1.38911,1.38915 2014-04-11 01:01:14.844,1.38911,1.38915 2014-04-11 01:01:22.877,1.38911,1.38915 2014-04-11 01:01:23.432,1.38913,1.38915 2014-04-11 01:01:43.546,1.38912,1.38915 2014-04-11 01:01:51.539,1.38912,1.38916 hebasto wrote: i'm using only live
|
|
|
|
|
API Support
|
Post subject: Re: IStrategy.onTick(...) != IHistory.readTicks(...) |
Post rating: 0
|
Posted: Wed 30 Apr, 2014, 09:38
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Could you please provide more information about the case? Are you running other strategies at the same time? How many instruments have you subscribed? We tested with the following strategy in LIVE for a couple hours and we could not reproduce what you are reporting: package jforex.data;
import java.io.PrintStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.TreeMap;
import com.dukascopy.api.Configurable; import com.dukascopy.api.IAccount; import com.dukascopy.api.IBar; import com.dukascopy.api.IConsole; import com.dukascopy.api.IContext; import com.dukascopy.api.IHistory; import com.dukascopy.api.IMessage; import com.dukascopy.api.IStrategy; import com.dukascopy.api.ITick; import com.dukascopy.api.Instrument; import com.dukascopy.api.JFException; import com.dukascopy.api.LoadingDataListener; import com.dukascopy.api.LoadingProgressListener; import com.dukascopy.api.OfferSide; import com.dukascopy.api.Period; import com.dukascopy.api.util.DateUtils;
public class TicksHistVsLiveMap implements IStrategy { @Configurable("") public Period period = Period.TEN_SECS; @Configurable("") public Instrument instrument = Instrument.EURUSD; @Configurable("log ticks") public boolean log = false; private TreeMap<Long, ITick> liveTicks; private IHistory history; private IConsole console; @Override public void onStart(IContext context) throws JFException { history = context.getHistory(); console = context.getConsole();
}
@Override public void onTick(Instrument instrument, ITick tick) throws JFException { if(this.instrument != instrument || liveTicks == null){ return; } liveTicks.put(tick.getTime(), tick); }
@Override public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if(this.instrument != instrument || this.period != period){ return; } //should happen only on the first bar - start collecting live ticks if(liveTicks == null){ liveTicks = new TreeMap<Long, ITick>(); return; //since we have not collected any live ticks yet } if(liveTicks.size() > 1000){ console.getInfo().println("Clear live tick map"); liveTicks = new TreeMap<Long, ITick>(); return; } long from = bidBar.getTime(); long to = bidBar.getTime() + period.getInterval(); List<TickInfo> histTicks = TickInfo.getInfos(history.getTicks(instrument, bidBar.getTime(), bidBar.getTime() + period.getInterval())); compareWithReadTicks(from, to, new ArrayList<TickInfo>(histTicks)); List<TickInfo> liveTicksChunk = TickInfo.getInfos(liveTicks.subMap(from, true, to, true).values());
compareTickLists( histTicks,"getTicks", liveTicksChunk, "live licks", from, to); } private void compareWithReadTicks(final long from, final long to, final List<TickInfo> histTicks) throws JFException { final List<TickInfo> readTicks = new ArrayList<TickInfo>(); history.readTicks(instrument, from, to,
new LoadingDataListener() { @Override public void newTick(Instrument instrument, long time, double ask, double bid, double askVol, double bidVol) { readTicks.add(new TickInfo(ask, bid, time)); }
@Override public void newBar(Instrument instrument, Period period, OfferSide side, long time, double open, double close, double low, double high, double vol) { // no bars expected } }, new LoadingProgressListener() {
@Override public void dataLoaded(long start, long end, long currentPosition, String information) { }
@Override public void loadingFinished(boolean allDataLoaded, long start, long end, long currentPosition) { compareTickLists( histTicks,"getTicks", readTicks, "readTicks", from, to); }
@Override public boolean stopJob() { return false; } });
} private void compareTickLists(List<TickInfo> list1, String info1, List<TickInfo> list2, String info2, long from, long to){ if(!list1.equals(list2)){ console.getErr().format("%s != %s", info1, info2).println(); logAllTicks(console.getErr(), list1,info1, list2, info2, from, to); List<TickInfo> temp = new ArrayList<TickInfo>(list2); list2.removeAll(list1); list1.removeAll(temp); console.getErr().format("%1$s not in %2$s:\n %3$s \n %2$s not in %1$s:\n %4$s", info1, info2, list1, list2).println(); } else if(log){ logAllTicks(console.getOut(),list1,info1, list2, info2, from, to); } } private void logAllTicks(PrintStream ps, List<?> list1, String info1, List<?> list2, String info2, long from, long to){ ps.format("%s <- %s %s\n %s <- %s %s\n %s - %s", list1, list1.size(), info1, list2, list2.size(), info2, DateUtils.format(from), DateUtils.format(to)).println(); }
@Override public void onMessage(IMessage message) throws JFException {}
@Override public void onAccount(IAccount account) throws JFException {}
@Override public void onStop() throws JFException {}
}
/** * Convenience class for tick data comparisons and more concise logging */ class TickInfo { private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss:SSS"); static { TIME_FORMAT.setTimeZone(DateUtils.GMT_TIME_ZONE); } private final double ask; private final double bid; private final long time; TickInfo(ITick tick){ ask = tick.getAsk(); bid = tick.getBid(); time = tick.getTime(); } TickInfo(double ask, double bid, long time){ this.ask = ask; this.bid = bid; this.time = time; } static List<TickInfo> getInfos(Collection<ITick> ticks){ List<TickInfo> list = new ArrayList<TickInfo>(); for(ITick t : ticks){ list.add(new TickInfo(t)); } return list; } @Override public String toString(){ return String.format("%s %s %s", TIME_FORMAT.format(time), bid, ask); }
@Override public int hashCode() { final int prime = 31; int result = 1; long temp; temp = Double.doubleToLongBits(ask); result = prime * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(bid); result = prime * result + (int) (temp ^ (temp >>> 32)); result = prime * result + (int) (time ^ (time >>> 32)); return result; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; TickInfo other = (TickInfo) obj; if (Double.doubleToLongBits(ask) != Double.doubleToLongBits(other.ask)) return false; if (Double.doubleToLongBits(bid) != Double.doubleToLongBits(other.bid)) return false; if (time != other.time) return false; return true; } }
Attachments: |
TicksHistVsLiveMap.java [7.37 KiB]
Downloaded 100 times
|
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on
this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control
on their content. Anyone accessing this webpage and downloading or otherwise making use of any document,
data or information found on this webpage shall do it on his/her own risks without any recourse against
Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from
the use and/or reliance on any document, data or information found on this webpage.
|
|
|
|
|
|
John11
|
Post subject: Re: IStrategy.onTick(...) != IHistory.readTicks(...) |
Post rating: 0
|
Posted: Wed 30 Apr, 2014, 11:42
|
|
User rating: 3
Joined: Fri 11 Oct, 2013, 13:49 Posts: 34
|
thanks for reply, currently it's not big problem because i'm going to remove tick if (tick.getTime() > tickPrev.getTime() && tick.getBid() == tickPrev.getBid() && tick.getAsk() == tickPrev.getAsk()), when i find not exist tick with different bid/ask i will send You test code, thanks
|
|
|
|
|
|
Pages: [
1
]
|
|
|
|
|