Synthetixio / simulation

Agent-based model of the proposed stablecoin.
24 stars 18 forks source link

Orderbook data structure #29

Closed 0xdomrom closed 6 years ago

0xdomrom commented 6 years ago

From small tests it seems that the orderbook bid/ask sorted lists are a bottleneck for the running of the model. An optimisation I would suggest would be changing the data structure to a sorted dictionary, that caches the total quantity at any given price.

i.e. SortedDict.keys = SortedList([Decimal(1), ...]) SortedDict.dict = {Decimal(1) : (total_quantity, SortedList([Ask, Ask, ...]), ...} Where the SortedList of asks is sorted by time

There could also be two separate dicts for total quantity and the sorted asks

0xdomrom commented 6 years ago

Also, in line with this, the orderbook history should be separated by model.time for future analysis/trading strategies and candlesticks

0xdomrom commented 6 years ago

Looking at the use cases of having a sortedDict over a SortedList for bids/asks, the only benefit would be the cached quantity, so having two separate structures, one being the bid/ask sortedList, and a sortedDict for the cached quantities seems like the way to go

0xdomrom commented 6 years ago

I feel like most of this was covered in #30