update docs, add comments

This commit is contained in:
Alexandru Pisarenco
2021-04-19 23:07:42 +02:00
parent 186f4f11be
commit bf2789eef3
2 changed files with 14 additions and 4 deletions

View File

@@ -38,17 +38,23 @@ class MemStorage:
now = monotonic()
q: deque[Quote] = self.__time_ordered_queues[isin]
ol: List[float] = self.__value_ordered_lists[isin]
while now - q[0].time > 600:
# Delete everything that's older than 5 minutes
while now - q[0].time > 300:
item = q.popleft()
index = bisect.bisect_left(ol, item.price)
ol.pop(index)
# Add current record at the end of the queue
q.append(Quote(now, price))
# Search where to add, and add into the ordered price list
insert_at = bisect.bisect_left(ol, price)
ol.insert(insert_at, price)
# Fast computation to check if instrument is "hot"
min_val = ol[0]
max_val = ol[-1]
is_hot = (max_val - min_val) / min_val > 0.1
# Figure out if we need to mark it as hot (and notify), or unmark it
if is_hot and isin not in self.__hot_stuff:
self.__hot_stuff.add(isin)
self.notify_hot(isin)