The personal finance app for everyone (by everyone)
Ruby
feat(yahoo_finance): add Indonesia Stock Exchange (XIDX) support (#3000)
Faldy Ikhwan Fadila792047b82ea8
diff --git a/app/models/provider/yahoo_finance.rb b/app/models/provider/yahoo_finance.rbindex b4a4fdbdb3..a4aa8addb4 100644--- a/app/models/provider/yahoo_finance.rb+++ b/app/models/provider/yahoo_finance.rb@@ -570,7 +570,8 @@ class Provider::YahooFinance < ProviderEXCHANGE_CONFIG = {"XNSE" => { yahoo_suffix: ".NS", default_currency: "INR", dual_list_group: :india, preference_rank: 0 },"XBOM" => { yahoo_suffix: ".BO", default_currency: "INR", dual_list_group: :india, preference_rank: 1 },- "XBOG" => { yahoo_suffix: ".CL", default_currency: "COP" }+ "XBOG" => { yahoo_suffix: ".CL", default_currency: "COP" },+ "XIDX" => { yahoo_suffix: ".JK", default_currency: "IDR" }}.freeze# Yahoo Finance sometimes returns currencies in minor units (pence, cents)@@ -1056,6 +1057,8 @@ class Provider::YahooFinance < Provider"MX"when /JSE|JOHANNESBURG/"ZA"+ when /JAKARTA|IDX/+ "ID"elsenilend@@ -1108,6 +1111,8 @@ class Provider::YahooFinance < Provider"XBOM" # BSE (Bombay Stock Exchange)when "BVC""XBOG" # Colombian Securities Exchange+ when "JKT"+ "XIDX" # Indonesia Stock Exchange (IDX)elseexchange_code.upcaseenddiff --git a/test/models/provider/yahoo_finance_test.rb b/test/models/provider/yahoo_finance_test.rbindex 5d361b9163..fab174fadd 100644--- a/test/models/provider/yahoo_finance_test.rb+++ b/test/models/provider/yahoo_finance_test.rb@@ -745,6 +745,11 @@ class Provider::YahooFinanceTest < ActiveSupport::TestCaseassert_nil @provider.send(:map_exchange_mic, "")end+ test "map_exchange_mic returns XIDX for JKT" do+ assert_equal "XIDX", @provider.send(:map_exchange_mic, "JKT")+ assert_equal "XIDX", @provider.send(:map_exchange_mic, "jkt")+ end+test "map_security_type returns correct types" doassert_equal "common stock", @provider.send(:map_security_type, "equity")assert_equal "etf", @provider.send(:map_security_type, "etf")@@ -823,6 +828,11 @@ class Provider::YahooFinanceTest < ActiveSupport::TestCaseassert_equal "IN", @provider.send(:map_country_code, "MUMBAI")end+ test "map_country_code returns ID for Indonesian exchanges" do+ assert_equal "ID", @provider.send(:map_country_code, "JAKARTA")+ assert_equal "ID", @provider.send(:map_country_code, "IDX")+ end+# ================================# normalize_symbol Tests# ================================@@ -831,11 +841,13 @@ class Provider::YahooFinanceTest < ActiveSupport::TestCaseassert_equal "RELIANCE.NS", @provider.send(:normalize_symbol, "RELIANCE", "XNSE")assert_equal "INFY.NS", @provider.send(:normalize_symbol, "INFY", "XNSE")assert_equal "500325.BO", @provider.send(:normalize_symbol, "500325", "XBOM")+ assert_equal "BBCA.JK", @provider.send(:normalize_symbol, "BBCA", "XIDX")endtest "normalize_symbol does not double-suffix already suffixed symbols" doassert_equal "RELIANCE.NS", @provider.send(:normalize_symbol, "RELIANCE.NS", "XNSE")assert_equal "500325.BO", @provider.send(:normalize_symbol, "500325.BO", "XBOM")+ assert_equal "BBCA.JK", @provider.send(:normalize_symbol, "BBCA.JK", "XIDX")endtest "normalize_symbol leaves unconfigured MIC symbols unchanged" do@@ -856,6 +868,7 @@ class Provider::YahooFinanceTest < ActiveSupport::TestCasetest "default_currency_for_exchange returns configured currency for known Yahoo exchange names" doassert_equal "INR", @provider.send(:default_currency_for_exchange, "NSE")assert_equal "INR", @provider.send(:default_currency_for_exchange, "BSE")+ assert_equal "IDR", @provider.send(:default_currency_for_exchange, "JKT")endtest "default_currency_for_exchange returns nil for unknown exchanges" do