Fix: Incorrect Currency Assignment for Stock Prices (#1623) #1798

Merged
saphp merged 1 commits from fix/stock-currency-assignment into main 2025-02-05 03:27:00 +08:00
saphp commented 2025-02-05 02:45:03 +08:00 (Migrated from github.com)

Fixes #1623

Issue Description

Stocks from non-USD markets (such as Saudi and Indian stock exchanges) were incorrectly assigned USD as their currency, which distorted portfolio calculations. The issue was due to the application extracting the currency from the prices array instead of the main response object.

Root Cause

The application was fetching stock price data from Synth Finance's "Open/Close Prices" API, but it incorrectly attempted to extract the currency from within each price entry under prices[], even though the API returns the correct currency in the main object under currency. This caused the system to default to "USD" when currency information was missing at the price level.

Solution

  • Updated the currency assignment logic to fetch it from the main response object (body.dig("currency")) instead of from the price entry.
  • Ensured that the currency field is correctly set for all fetched stock prices.

Impact

Fixes incorrect currency assignment for stock prices in non-USD markets.
Prevents miscalculations of portfolio value due to incorrect currency conversion.
Ensures compatibility with Synth Finance’s API response structure.

Testing

  • Verified that stocks from Saudi and Indian markets now display correct currency values.
  • Confirmed that existing USD-based stocks remain unaffected.
Fixes #1623 ### **Issue Description** Stocks from non-USD markets (such as Saudi and Indian stock exchanges) were incorrectly assigned USD as their currency, which distorted portfolio calculations. The issue was due to the application extracting the currency from the `prices` array instead of the main response object. ### **Root Cause** The application was fetching stock price data from Synth Finance's **"Open/Close Prices"** API, but it incorrectly attempted to extract the currency from within each price entry under `prices[]`, even though the API returns the correct currency in the main object under `currency`. This caused the system to default to "USD" when currency information was missing at the price level. ### **Solution** - Updated the currency assignment logic to fetch it from the main response object (`body.dig("currency")`) instead of from the price entry. - Ensured that the currency field is correctly set for all fetched stock prices. ### **Impact** ✅ Fixes incorrect currency assignment for stock prices in non-USD markets. ✅ Prevents miscalculations of portfolio value due to incorrect currency conversion. ✅ Ensures compatibility with Synth Finance’s API response structure. ### **Testing** - Verified that stocks from Saudi and Indian markets now display correct currency values. - Confirmed that existing USD-based stocks remain unaffected.
zachgoll (Migrated from github.com) approved these changes 2025-02-05 03:22:16 +08:00
zachgoll (Migrated from github.com) left a comment

Awesome, fix makes sense! Thanks for the explanation and testing.

Awesome, fix makes sense! Thanks for the explanation and testing.
Sign in to join this conversation.