@@ -70,13 +70,16 @@ def process_ticker(ticker, mongo_client):
70
70
71
71
current_price = None
72
72
retries = 0
73
- while current_price is None and retries <= 3 :
73
+ while current_price is None :
74
74
try :
75
75
current_price = get_latest_price (ticker )
76
76
except Exception as fetch_error :
77
77
logging .warning (f"Error fetching price for { ticker } . Retrying... { fetch_error } " )
78
78
time .sleep (10 )
79
79
retries += 1
80
+ if retries == 3 :
81
+ logging .error (f"Error fetching price for { ticker } . Skipping." )
82
+ return
80
83
81
84
indicator_tb = mongo_client .IndicatorsDatabase
82
85
indicator_collection = indicator_tb .Indicators
@@ -267,30 +270,34 @@ def update_portfolio_values(client):
267
270
portfolio_value = strategy_doc ["amount_cash" ]
268
271
269
272
for ticker , holding in strategy_doc ["holdings" ].items ():
270
- # The current price can be gotten through a cache system maybe
271
- # if polygon api is getting clogged - but that hasn't happened yet
272
- # Also implement in C++ or C instead of python
273
- # Get the current price of the ticker from the Polygon API
274
- # Use a cache system to store the latest prices
275
- # If the cache is empty, fetch the latest price from the Polygon API
276
- # Cache should be updated every 60 seconds
277
-
278
- current_price = None
279
- retries = 0
280
- while current_price is None and retries <= 3 :
273
+ # The current price can be gotten through a cache system maybe
274
+ # if polygon api is getting clogged - but that hasn't happened yet
275
+ # Also implement in C++ or C instead of python
276
+ # Get the current price of the ticker from the Polygon API
277
+ # Use a cache system to store the latest prices
278
+ # If the cache is empty, fetch the latest price from the Polygon API
279
+ # Cache should be updated every 60 seconds
280
+ current_price = None
281
+ retries = 0
282
+ while current_price is None :
281
283
try :
282
284
# get latest price shouldn't cache - we should also do a delay
283
285
current_price = get_latest_price (ticker )
284
286
except :
285
287
print (f"Error fetching price for { ticker } . Retrying..." )
286
288
time .sleep (120 )
287
289
retries += 1
290
+ if retries == 3 :
291
+ print (f"Error fetching price for { ticker } . Skipping." )
292
+ break
288
293
# Will sleep 120 seconds before retrying to get latest price
289
- print (f"Current price of { ticker } : { current_price } " )
290
- # Calculate the value of the holding
291
- holding_value = holding ["quantity" ] * current_price
292
- # Add the holding value to the portfolio value
293
- portfolio_value += holding_value
294
+ print (f"Current price of { ticker } : { current_price } " )
295
+ if current_price is None :
296
+ continue
297
+ # Calculate the value of the holding
298
+ holding_value = holding ["quantity" ] * current_price
299
+ # Add the holding value to the portfolio value
300
+ portfolio_value += holding_value
294
301
295
302
# Update the portfolio value in the strategy document
296
303
holdings_collection .update_one ({"strategy" : strategy_doc ["strategy" ]}, {"$set" : {"portfolio_value" : portfolio_value }}, upsert = True )
0 commit comments