Accessing the Order-book at indicator initialisation

Custom indicators, trading strategies, data export and recording and more...
TraderCG
Posts: 5
Joined: Fri Sep 21, 2018 7:43 am

Accessing the Order-book at indicator initialisation

Post by TraderCG » Thu Jan 31, 2019 12:26 pm

I would like to access the total Order-book without waiting for onDepth() to update each level as done in the OrderBookBase class. My question: is there a way of doing this with the layer1 API? My goal is to be able to detect all of the high-volume nodes within a certain percentile (such as shown by the heatmap) at the time of indicator initialization. Any help will be much appreciated.

Tags:

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

Re: Accessing the Order-book at indicator initialisation

Post by Svyatoslav » Thu Jan 31, 2019 2:19 pm

Hi,
While current simplified API doesn't provide a ready OrderBook inside initialize it allows you to implement SnapshotEndListener interface. The state of the order book at that point (assuming you apply all onDepth calls to it) will be exactly what you would get inside initialize if it would be there (at least that's how it should work in theory). There will be no significant delay, as snapshot should be passed immediately after loading your module.

TraderCG
Posts: 5
Joined: Fri Sep 21, 2018 7:43 am

Re: Accessing the Order-book at indicator initialisation

Post by TraderCG » Fri Feb 01, 2019 4:08 am

@Svyatoslav thank you for your answer. Having the snapshot passed immediately after loading the module will work just as good. Sorry for my misunderstanding of the SnapshotEndListener interface (the Javadoc I have does not have any description for this - do I need to update?). I had experimented with it previously, but now that you have given your answer I think I better understand its function. Could you confirm that I have understood correctly that on loading the module, the SnaphotEndListener interface will iterate through each level in the Order Book with the onDepth() being called for each iteration, which means that the OrderBookBase class updates both bid and ask TreeMaps for this class so as to give the full Order Book. After all of the iterations, then onSnapshotEnd() -> snapshotCompleted = true and onDepth() continues to keep the TreeMaps in sync with the Order Book. Thanks again for your help.
Chris G

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

Re: Accessing the Order-book at indicator initialisation

Post by Svyatoslav » Fri Feb 01, 2019 9:26 am

Hi,
The only thing I'd like to correct in what you said is that after module is loaded you get current order book stats via onDepth calls anyway - regardless of if you have SnapshotEndListener - the only thing this listener does is telling you "hey, this is the end of a snapshot, everything past this point will be realtime data".

TraderCG
Posts: 5
Joined: Fri Sep 21, 2018 7:43 am

Re: Accessing the Order-book at indicator initialisation

Post by TraderCG » Sun Feb 03, 2019 5:30 am

@Svyatoslav. Thanks for your help with this. With your explanation, I fully understand now.
Great work by the Bookmap team with this API.
Chris G

Post Reply