Skip to content

Commit 15b0fea

Browse files
committed
implented hardfix for ctas price history error
1 parent d151995 commit 15b0fea

File tree

2 files changed

+28
-30
lines changed

2 files changed

+28
-30
lines changed

ranking_client.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ def process_ticker(ticker, mongo_client):
7070

7171
current_price = None
7272
retries = 0
73-
while current_price is None and retries <= 3:
73+
while current_price is None:
7474
try:
7575
current_price = get_latest_price(ticker)
7676
except Exception as fetch_error:
7777
logging.warning(f"Error fetching price for {ticker}. Retrying... {fetch_error}")
7878
time.sleep(10)
7979
retries += 1
80+
if retries == 3:
81+
logging.error(f"Error fetching price for {ticker}. Skipping.")
82+
return
8083

8184
indicator_tb = mongo_client.IndicatorsDatabase
8285
indicator_collection = indicator_tb.Indicators
@@ -267,30 +270,34 @@ def update_portfolio_values(client):
267270
portfolio_value = strategy_doc["amount_cash"]
268271

269272
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:
281283
try:
282284
# get latest price shouldn't cache - we should also do a delay
283285
current_price = get_latest_price(ticker)
284286
except:
285287
print(f"Error fetching price for {ticker}. Retrying...")
286288
time.sleep(120)
287289
retries += 1
290+
if retries == 3:
291+
print(f"Error fetching price for {ticker}. Skipping.")
292+
break
288293
# 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
294301

295302
# Update the portfolio value in the strategy document
296303
holdings_collection.update_one({"strategy": strategy_doc["strategy"]}, {"$set": {"portfolio_value": portfolio_value}}, upsert=True)

trading_client.py

+4-13
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,17 @@ def process_ticker(ticker, client, trading_client, data_client, mongo_client, st
9090
try:
9191
decisions_and_quantities = []
9292
current_price = None
93-
<<<<<<< HEAD
94-
count = 0
95-
while current_price is None:
96-
=======
9793
retries = 0
98-
while current_price is None and retries <= 3:
99-
>>>>>>> 7405e36910fffc98319dcd8dd3570b7d0c276822
94+
while current_price is None:
10095
try:
10196
current_price = get_latest_price(ticker)
10297
except Exception as fetch_error:
103-
count+=1
10498
logging.warning(f"Error fetching price for {ticker}. Retrying... {fetch_error}")
105-
time.sleep(10)
106-
<<<<<<< HEAD
107-
if count == 3:
99+
time.sleep(5)
100+
retries+=1
101+
if retries == 3:
108102
logging.error(f"Failed to fetch price for {ticker}. Exiting process_ticker function.")
109103
return
110-
=======
111-
retries += 1
112-
>>>>>>> 7405e36910fffc98319dcd8dd3570b7d0c276822
113104
print(f"Current price of {ticker}: {current_price}")
114105

115106
asset_collection = mongo_client.trades.assets_quantities

0 commit comments

Comments
 (0)