@@ -41,18 +41,18 @@ def __init__(self):
4141
4242 self .prices : Dict [str , float ] = {
4343 "AAPL" : 180.0 , # Apple Inc.
44- # "GOOGL": 140.0, # Alphabet Inc.
45- # "MSFT": 370.0, # Microsoft Corporation
46- # "AMZN": 145.0, # Amazon.com Inc.
47- # "TSLA": 240.0, # Tesla Inc.
44+ "GOOGL" : 140.0 , # Alphabet Inc.
45+ "MSFT" : 370.0 , # Microsoft Corporation
46+ "AMZN" : 145.0 , # Amazon.com Inc.
47+ "TSLA" : 240.0 , # Tesla Inc.
4848 }
4949 self ._desc_lock = threading .RLock ()
5050 self ._descriptions = {
5151 "AAPL" : "Apple Inc." ,
52- # "GOOGL": "Alphabet Inc.",
53- # "MSFT": "Microsoft Corporation",
54- # "AMZN": "Amazon.com Inc.",
55- # "TSLA": "Tesla Inc.",
52+ "GOOGL" : "Alphabet Inc." ,
53+ "MSFT" : "Microsoft Corporation" ,
54+ "AMZN" : "Amazon.com Inc." ,
55+ "TSLA" : "Tesla Inc." ,
5656 }
5757 self .last_prices = self .prices .copy ()
5858 self ._running = False
@@ -83,8 +83,10 @@ async def on_stopped(self):
8383
8484 logger .info ("[StockService][on_stopped] stopped" )
8585 self ._running = False
86+
8687 if hasattr (self , "_update_task" ):
8788 self ._update_task .cancel ()
89+
8890 try :
8991 await self ._update_task
9092 except asyncio .CancelledError :
@@ -104,6 +106,7 @@ async def update_prices(self):
104106 change = ((self .prices [code ] / self .last_prices [code ]) - 1 ) * 100 ,
105107 timestamp = time .time (),
106108 )
109+
107110 logger .debug (
108111 "[StockService][update_prices] price_data: %s" ,
109112 price_data ,
@@ -148,13 +151,15 @@ def remove_alert(self):
148151 @t_slot
149152 def on_price_processed (self , price_data : StockPrice ):
150153 """Receive processed stock price data from StockProcessor"""
154+
151155 logger .debug ("[StockViewModel][on_price_processed] price_data: %s" , price_data )
152156 self .current_prices [price_data .code ] = price_data
153157 self .prices_updated .emit (dict (self .current_prices ))
154158
155159 @t_slot
156160 def on_alert_triggered (self , code : str , alert_type : str , price : float ):
157161 """Receive alert trigger from StockProcessor"""
162+
158163 self .alerts .append ((code , alert_type , price ))
159164 self .alert_added .emit (code , alert_type , price )
160165
@@ -163,6 +168,7 @@ def on_alert_settings_changed(
163168 self , code : str , lower : Optional [float ], upper : Optional [float ]
164169 ):
165170 """Receive alert settings change notification from StockProcessor"""
171+
166172 if lower is None and upper is None :
167173 self .alert_settings .pop (code , None )
168174 else :
@@ -209,19 +215,22 @@ async def on_set_price_alert(
209215 self , code : str , lower : Optional [float ], upper : Optional [float ]
210216 ):
211217 """Receive price alert setting request from main thread"""
218+
212219 self .price_alerts [code ] = (lower , upper )
213220 self .alert_settings_changed .emit (code , lower , upper )
214221
215222 @t_slot
216223 async def on_remove_price_alert (self , code : str ):
217224 """Receive price alert removal request from main thread"""
225+
218226 if code in self .price_alerts :
219227 del self .price_alerts [code ]
220228 self .alert_settings_changed .emit (code , None , None )
221229
222230 @t_slot
223231 async def on_price_updated (self , price_data : StockPrice ):
224232 """Receive stock price update from StockService"""
233+
225234 logger .debug ("[StockProcessor][on_price_updated] price_data: %s" , price_data )
226235
227236 try :
@@ -232,17 +241,22 @@ async def on_price_updated(self, price_data: StockPrice):
232241
233242 async def process_price (self , price_data : StockPrice ):
234243 """Process stock price data"""
244+
235245 logger .debug ("[StockProcessor][process_price] price_data: %s" , price_data )
246+
236247 try :
237248 if price_data .code in self .price_alerts :
238249 logger .debug (
239250 "[process_price] Process price event loop: %s" ,
240251 asyncio .get_running_loop (),
241252 )
253+
242254 if price_data .code in self .price_alerts :
243255 lower , upper = self .price_alerts [price_data .code ]
256+
244257 if lower and price_data .price <= lower :
245258 self .alert_triggered .emit (price_data .code , "LOW" , price_data .price )
259+
246260 if upper and price_data .price >= upper :
247261 self .alert_triggered .emit (price_data .code , "HIGH" , price_data .price )
248262
0 commit comments