We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 49ee6f3 commit c44a757Copy full SHA for c44a757
stock_alerter/stock.py
@@ -1,18 +1,21 @@
1
+import bisect
2
+
3
4
class Stock:
5
def __init__(self, symbol):
6
self.symbol = symbol
7
self.price_history = []
8
9
@property
10
def price(self):
- return self.price_history[-1] \
11
+ return self.price_history[-1][1] \
12
if self.price_history else None
13
14
def update(self, timestamp, price):
15
if price < 0:
16
raise ValueError("price should not be negative")
- self.price_history.append(price)
17
+ bisect.insort_left(self.price_history, (timestamp, price))
18
19
def is_increasing_trend(self):
- return self.price_history[-3] < \
- 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