Skip to content

Commit c44a757

Browse files
author
Siddharta Govindaraj
committed
Out of order updates passing
1 parent 49ee6f3 commit c44a757

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

stock_alerter/stock.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
import bisect
2+
3+
14
class Stock:
25
def __init__(self, symbol):
36
self.symbol = symbol
47
self.price_history = []
58

69
@property
710
def price(self):
8-
return self.price_history[-1] \
11+
return self.price_history[-1][1] \
912
if self.price_history else None
1013

1114
def update(self, timestamp, price):
1215
if price < 0:
1316
raise ValueError("price should not be negative")
14-
self.price_history.append(price)
17+
bisect.insort_left(self.price_history, (timestamp, price))
1518

1619
def is_increasing_trend(self):
17-
return self.price_history[-3] < \
18-
self.price_history[-2] < self.price_history[-1]
20+
return self.price_history[-3][1] < \
21+
self.price_history[-2][1] < self.price_history[-1][1]

0 commit comments

Comments
 (0)