Page 1 of 1

Reading out OrderBookMbo

Posted: Mon Jun 21, 2021 11:50 am
by Jan123
Given a variable of type OrderBookMbo, how do I read out all orders at a given price level?

It doesn't seem like OrderBookMbo has a method retrieving this information in a simple way. The only method I can see is getOrder, which retrieves orders by order ID, which doesn't help. 

Re: Reading out OrderBookMbo

Posted: Mon Jun 21, 2021 2:29 pm
by Andry API support
OrderBookMbo does not support this functionality. You will actually need to make your own order book to be able to request all current order ids at a price level. This is not a hard task but please be mindful of your order book performance.

Re: Reading out OrderBookMbo

Posted: Tue Jun 22, 2021 4:38 am
by Jan123
Thank you Andrey!

How do I then get all current orders that are sitting at a price level? 

Currently my code filters out large orders at every price level and redraws the heatmap accordingly, but it doesn't happen right when i activate the plugin, but instead it happens for every level one by one when something in that level changes (which can take a while for levels much further away) because i am using onMboSend.

Strangely this first call of onMboSend behaves as if it is communicating not just the change (order being added), but as if all current orders are being added to that level, so there seems to be something else that I don't understand about the orderbook updating functions. 

How can I update all the levels right when I hit the checkmark in the plugin (activate it)?

Re: Reading out OrderBookMbo

Posted: Tue Jun 22, 2021 9:37 am
by Andry API support
How do I then get all current orders that are sitting at a price level
Currently, the only way is to design your own orderbook - a datastructure that links a collection of orders to certain price levels.
How can I update all the levels right when I hit the checkmark in the plugin (activate it)

First, you need to store the actual orderbook (your implementation) in your module.

Once you need to filter some orders out you need to
1) report the difference(diff in the image) between the desired orderbook and the actual orderbook to Bookmap. It means report removing current orders that do not match the filter to Bookmap's orderbook.
ob_diff_0.jpg
ob_diff_0.jpg (70.06 KiB) Viewed 2783 times
2) eversince, report only order updates that match the filter to Bookmap.

If your filter is disabled you need:
1) report the difference between the actual orderbook and the desired orderbook to Bookmap. It means report adding orders that did not match the filter to Bookmap (image ob_diff_1).
ob_diff_1.jpg
ob_diff_1.jpg (69.28 KiB) Viewed 2783 times
2) the filter is disabled, you must report all order updates to Bookmap.

Please note, these is a very simple scenario of one filter applied.

Re: Reading out OrderBookMbo

Posted: Tue Jun 22, 2021 1:14 pm
by Andry API support
UPDATE
Strangely this first call of onMboSend behaves as if it is communicating not just the change (order being added), but as if all current orders are being added to that level, so there seems to be something else that I don't understand about the orderbook updating functions.
First you get the orderbook snapshot, then you get activated (UserMessageLayersChainCreatedTargeted with your class as target, see DataEditorBasicExample#onUserMessage), then you get orderbook updates.
How can I update all the levels right when I hit the checkmark in the plugin (activate it)
A shorter version: Collect the snapshot. Wait for activation (UserMessageLayersChainCreatedTargeted). Now, same as in DataEditorBasicExample, send the difference between current and desired book (a longer version is in the previous post). Before getting disabled (finish) do the reverse (undo the difference between "raw" book and your version)