From af9bf84d0a302adf55c6e7e085fd97a136c85c10 Mon Sep 17 00:00:00 2001 From: Eden Kirin Date: Thu, 25 Dec 2025 20:02:47 +0100 Subject: [PATCH] Latest fix --- .gitignore | 1 - Makefile | 3 + backend/main.go | 78 ++-- static/index.html | 934 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 989 insertions(+), 27 deletions(-) create mode 100644 static/index.html diff --git a/.gitignore b/.gitignore index 5aafc97..db6ec11 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,5 @@ Thumbs.db *.csv # Static build artifacts -static/ dist/ build/ diff --git a/Makefile b/Makefile index d4abf63..5cc892e 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,5 @@ +build: + @docker compose up --build -d + run: @docker compose up diff --git a/backend/main.go b/backend/main.go index a97fef1..002c61a 100644 --- a/backend/main.go +++ b/backend/main.go @@ -67,42 +67,68 @@ func fetchExchangeRate() (float64, error) { func fetchStockPrice(ticker string) (float64, error) { client := &http.Client{Timeout: 10 * time.Second} - // Try Yahoo Finance API - url := fmt.Sprintf("https://query1.finance.yahoo.com/v8/finance/chart/%s?interval=1d&range=1d", ticker) - req, err := http.NewRequest("GET", url, nil) - if err != nil { - return 0, err + // Try different ticker formats for European stocks + tickersToTry := []string{ticker} + + // If ticker doesn't have exchange suffix, try adding common ones + if !strings.Contains(ticker, ".") { + tickersToTry = append(tickersToTry, + ticker+".L", // London Stock Exchange + ticker+".AS", // Amsterdam + ticker+".PA", // Paris + ticker+".DE", // XETRA (Germany) + ticker+".MI", // Milan + ) } - req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36") + var lastErr error + for _, tryTicker := range tickersToTry { + // Try Yahoo Finance API + url := fmt.Sprintf("https://query1.finance.yahoo.com/v8/finance/chart/%s?interval=1d&range=1d", tryTicker) + req, err := http.NewRequest("GET", url, nil) + if err != nil { + lastErr = err + continue + } - resp, err := client.Do(req) - if err != nil { - return 0, fmt.Errorf("failed to fetch from Yahoo: %w", err) - } - defer resp.Body.Close() + req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36") - body, err := io.ReadAll(resp.Body) - if err != nil { - return 0, fmt.Errorf("failed to read response: %w", err) - } + resp, err := client.Do(req) + if err != nil { + lastErr = fmt.Errorf("failed to fetch from Yahoo: %w", err) + continue + } + defer resp.Body.Close() - var chartData YahooChartResponse - if err := json.Unmarshal(body, &chartData); err != nil { - return 0, fmt.Errorf("failed to decode Yahoo response: %w", err) - } + body, err := io.ReadAll(resp.Body) + if err != nil { + lastErr = fmt.Errorf("failed to read response: %w", err) + continue + } - if chartData.Chart.Error != nil { - return 0, fmt.Errorf("Yahoo API error: %s", chartData.Chart.Error.Description) - } + var chartData YahooChartResponse + if err := json.Unmarshal(body, &chartData); err != nil { + lastErr = fmt.Errorf("failed to decode Yahoo response: %w", err) + continue + } - if len(chartData.Chart.Result) > 0 { - price := chartData.Chart.Result[0].Meta.RegularMarketPrice - if price > 0 { - return price, nil + if chartData.Chart.Error != nil { + lastErr = fmt.Errorf("Yahoo API error: %s", chartData.Chart.Error.Description) + continue + } + + if len(chartData.Chart.Result) > 0 { + price := chartData.Chart.Result[0].Meta.RegularMarketPrice + if price > 0 { + log.Printf("Successfully fetched price for %s (tried as %s): $%.2f", ticker, tryTicker, price) + return price, nil + } } } + if lastErr != nil { + return 0, fmt.Errorf("price not found after trying all formats: %w", lastErr) + } return 0, fmt.Errorf("price not found in response") } diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..00d0457 --- /dev/null +++ b/static/index.html @@ -0,0 +1,934 @@ + + + + + + Stock Tax Analyzer + + + + + + +
+ + + +