1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2026-06-03 21:00:26 +00:00

Fix bugs in MarketData and CoinGecko handlers

- Change logging.error to logging.debug for response headers in MarketData.get()
- Fix MarketData.status() to check its own API instead of CoinGecko uptime monitor
- Fix f-string bug in cg_Crypto.cap_reply (market cap was not interpolated)
- Add exponential backoff with max 3 retries for CoinGecko 429 errors
- Fix formatting issues in cg_Crypto (quote consistency, spacing)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Anson Biggs
2026-02-21 16:52:42 -05:00
parent 018613e896
commit b8f2f6998a
2 changed files with 31 additions and 28 deletions
+9 -15
View File
@@ -74,7 +74,7 @@ class MarketData:
resp = r.get(url, params=params, timeout=timeout, headers=headers)
logging.error(resp.headers.items())
logging.debug(resp.headers.items())
# Make sure API returned a proper status code
try:
@@ -133,27 +133,21 @@ class MarketData:
self.charts = {}
def status(self) -> str:
# TODO: At the moment this API is poorly documented, this function likely needs to be revisited later.
"""Check MarketData.app API status by making a test request."""
try:
# Test the API with a simple request
status = r.get(
"https://stats.uptimerobot.com/api/getMonitorList/6Kv3zIow0A",
"https://api.marketdata.app/v1/stocks/quotes/AAPL/",
timeout=5,
)
status.raise_for_status()
return f"MarketData.app API is responding OK with status {status.status_code} in {status.elapsed.total_seconds():.2f} seconds."
except r.HTTPError:
return f"API returned an HTTP error code {status.status_code} in {status.elapsed.total_seconds()} seconds."
return f"MarketData.app API returned an HTTP error code {status.status_code} in {status.elapsed.total_seconds():.2f} seconds."
except r.Timeout:
return "API timed out before it was able to give status. This is likely due to a surge in usage or a complete outage."
statusJSON = status.json()
if statusJSON["status"] == "ok":
return (
f"CoinGecko API responded that it was OK with a {status.status_code} in {status.elapsed.total_seconds()} seconds."
)
else:
return f"MarketData.app is currently reporting the following status: {statusJSON['status']}"
return "MarketData.app API timed out before it could respond. This is likely due to a surge in usage or a complete outage."
except Exception as e:
return f"MarketData.app API check failed: {str(e)}"
def price_reply(self, symbol: Stock) -> str:
"""Returns price movement of Stock for the last market day, or after hours.