Reading out OrderBookMbo

Custom indicators, trading strategies, data export and recording and more...
Jan123
Posts: 18
Joined: Tue Apr 20, 2021 2:28 pm
Has thanked: 19 times
Been thanked: 3 times

Reading out OrderBookMbo

Post by Jan123 » Mon Jun 21, 2021 11:50 am

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. 

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

Re: Reading out OrderBookMbo

Post by Andry API support » Mon Jun 21, 2021 2:29 pm

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.

Jan123
Posts: 18
Joined: Tue Apr 20, 2021 2:28 pm
Has thanked: 19 times
Been thanked: 3 times

Re: Reading out OrderBookMbo

Post by Jan123 » Tue Jun 22, 2021 4:38 am

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)?

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

Re: Reading out OrderBookMbo

Post by Andry API support » Tue Jun 22, 2021 9:37 am

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 2546 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 2546 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.

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

Re: Reading out OrderBookMbo

Post by Andry API support » Tue Jun 22, 2021 1:14 pm

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)

Post Reply