Skip to content

Conversation

@Gitmaxd
Copy link

@Gitmaxd Gitmaxd commented May 4, 2025

Fix Stock Price Tool for Non-Trading Days

Problem

The Stock Price tool fails with the error "Failed to fetch prices" when used on weekends, holidays, or when current market data is not yet available. This happens because:

  1. The tool always attempts to fetch data for the current date
  2. The API returns a 404 error when no data is available for the requested date
  3. The error handling doesn't provide fallback options

Solution

This PR improves the getPricesForTicker function to handle non-trading days gracefully by:

  1. Using the price snapshot API to determine the latest available market data date
  2. Using that date instead of the current date for all data requests
  3. Implementing a fallback to use the most recent day from thirty-day data when one-day data is unavailable
  4. Adding better error handling with detailed error messages
  5. Improving logging for easier debugging

Testing

The fix was tested by:

  • Creating a test script to verify API behavior
  • Confirming the snapshot API returns the latest available data
  • Verifying that the thirty-day historical data endpoint works properly
  • Testing the full application to ensure the Stock Price tool works correctly on non-trading days

Documentation

A detailed explanation of the changes is included in stock-price-tool-fix.md.

Gitmaxd added 2 commits May 4, 2025 12:26
Improved the getPricesForTicker function to handle weekends, holidays, and other non-trading days gracefully by:
- Using price snapshot API to determine latest available market data
- Implementing fallback to most recent data when current day data is unavailable
- Adding better error handling and detailed error messages
- Improving logging for easier debugging

This fix ensures the stock price tool works reliably regardless of when users access the application.
Removed console.log statement from stockbroker tools for better code quality
@Gitmaxd
Copy link
Author

Gitmaxd commented May 5, 2025

I noticed there was a console.log statement in my code that should be removed for production. I've added a commit to remove it and improve code quality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant