I have a sorted dictionary (here the bids of an order book) with the following form, where the items in the parentheses are {price: amount} and sorted.
bids = SortedDict({0.0005: 11.0, 0.006: 10.0, 0.01: 28.6, 0.0105: 21.8, 0.012: 25.1})
I also know my own quotes, which are:
own_bids = [{0.006: 10.0}, {0.012: 5.1}]
My goal is to exclude my own orders from the order book. The result should look like:
SortedDict({0.0005: 11.0, 0.01: 28.6, 0.0105: 21.8, 0.012: 20})
I have tried to delete them by looping through my own orders and deleting the elements if quantity is 0. But it increased the run time by 12x so I am wondering if there is no simple operation to do this. Is there a fast method to do this in python?
If I understand you correctly, you want to substract
own_bidsfrombidsand filter the zero values out:Prints:
EDIT: Without the walrus operator (
:=):