OnTimestamp and time of a trade

Custom indicators, trading strategies, data export and recording and more...
zcsoka
Posts: 290
Joined: Thu Dec 19, 2019 7:50 pm
Has thanked: 2 times
Been thanked: 28 times

OnTimestamp and time of a trade

Post by zcsoka » Mon Mar 09, 2020 10:01 am

Greetings,

Is there a way to get the trade time on the onTrade event? 
When is the onTimestamp called? I am trying implement both interval and time stamp based resets for an indicator. The interval based works fine, but the onTimestamp has a funny behaviour:

calling:

public void onTimestamp(long t) {
LocalDateTime ts = LocalDateTime.ofInstant(Instant.ofEpochSecond(t / 1_000_000_000L), TimeZone.getDefault().toZoneId());

the timestamp during a replay shows the real time and not the replay time. 
Could you please let me know how I could grab the time of the trade or grab a time stamp during the replay to be able to reset based on timestamps keeping in mind that the onInterval is not available?

Many thanks in advance,

Kind Regards

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: OnTimestamp and time of a trade

Post by Andry API support » Thu Mar 12, 2020 9:51 am

Hi zcsoka,
onTimestamp is called any time a new event comes (depth, trade, order, whatever).
To catch an event time just store the t value and read it when you need to.
the timestamp during a replay shows the real time and not the replay time  I am not sure I get it right, could you pls provide some more details. onTimestamp method must give timestamps of events happening on the screen. For example, I have just replayed a January feed and what I have in my console is:

Code: Select all

 
20200312 09:49:52.602(UTC) INFO: Time is 2020-01-02T06:52:15
20200312 09:49:54.889(UTC) INFO: Time is 2020-01-02T06:52:19
20200312 09:49:54.982(UTC) INFO: Time is 2020-01-02T06:52:20
Code example: 

Code: Select all

public class ReplayTimeListener implements CustomModule, TradeDataListener, TimeListener {
    private long t;

    @Override
    public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
    }

    @Override
    public void stop() {
    }

    @Override
    public void onTrade(double price, int size, TradeInfo tradeInfo) {
        LocalDateTime ts = LocalDateTime.ofInstant(Instant.ofEpochSecond(t / 1_000_000_000L), TimeZone.getDefault().toZoneId());
        Log.info("Time is "  + ts.toString());
    }

    @Override
    public void onTimestamp(long t) {
        this.t = t;
    }
    
}

zcsoka
Posts: 290
Joined: Thu Dec 19, 2019 7:50 pm
Has thanked: 2 times
Been thanked: 28 times

Re: OnTimestamp and time of a trade

Post by zcsoka » Tue Mar 17, 2020 2:00 pm

Hi AndreyR,

Many thanks for your answer, sorry for the late reaction, I missed the notification. I found out, that on the Mac the replay timestamps are not correct, independent of the location of the replay the time stamp always ends with the las time stamp of the replay file. For example: Replay file's last time stamp is 17:21:01. I play my file till 07:21:00. I add my indicator. The indicator catches up and drawn till 07:21, but the printed time stamp is 17:21:01.
I will check it on my Windows machine as well.

Kind Regards,

Zoltan

Svyatoslav
Site Admin
Posts: 278
Joined: Mon Jun 11, 2018 11:44 am
Has thanked: 2 times
Been thanked: 31 times

Re: OnTimestamp and time of a trade

Post by Svyatoslav » Tue Mar 17, 2020 4:33 pm

Which interfaces are you implementing? Sounds like you have implemented HistoricalDataListener but not HistoricalModeListener, so Bookmap tries to take shortcut and precompute your indicator on all the data. But maybe I misunderstood the problem. Would it be possible to post a short code example showing the issue?

Post Reply