From 1c2e88a085134bfcc832c550a8c34d7fba380ff5 Mon Sep 17 00:00:00 2001 From: Andreas Buchen Date: Sun, 4 Jun 2023 17:01:00 +0200 Subject: [PATCH] Refactored market identifier codes into separate properties file Issue: #3373 --- .../online/impl/MarketIdentifierCodes.java | 51 ++++++++++++ .../online/impl/PortfolioReportQuoteFeed.java | 11 +-- .../online/impl/TwelveDataQuoteFeed.java | 20 ++--- .../online/impl/YahooFinanceQuoteFeed.java | 5 +- .../online/impl/exchange-labels.properties | 79 ------------------- .../impl/market-identifier-codes.properties | 76 ++++++++++++++++++ portfolio-app/releng/translation-config.xml | 1 - 7 files changed, 140 insertions(+), 103 deletions(-) create mode 100644 name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/MarketIdentifierCodes.java create mode 100644 name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/market-identifier-codes.properties diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/MarketIdentifierCodes.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/MarketIdentifierCodes.java new file mode 100644 index 0000000000..dc147e0dc3 --- /dev/null +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/MarketIdentifierCodes.java @@ -0,0 +1,51 @@ +package name.abuchen.portfolio.online.impl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Returns the labels based on the ISO 10383 market identifier code. + * + * @see https://www.iso20022.org/market-identifier-codes + */ +public class MarketIdentifierCodes +{ + private static final String BUNDLE_NAME = "name.abuchen.portfolio.online.impl.market-identifier-codes"; //$NON-NLS-1$ + private static final ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private MarketIdentifierCodes() + { + } + + public static String getLabel(String marketIdentifierCode) + { + try + { + return BUNDLE.getString(marketIdentifierCode); + } + catch (MissingResourceException e) + { + return marketIdentifierCode; + } + } + + public static List getAllMarketIdentifierCodes() + { + List answer = new ArrayList<>(); + + Enumeration keys = BUNDLE.getKeys(); + while (keys.hasMoreElements()) + { + String key = keys.nextElement(); + answer.add(key); + } + + Collections.sort(answer); + + return answer; + } +} diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/PortfolioReportQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/PortfolioReportQuoteFeed.java index 6aba773ebe..a1cda67fe8 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/PortfolioReportQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/PortfolioReportQuoteFeed.java @@ -8,7 +8,6 @@ import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -187,12 +186,10 @@ public List getExchanges(Security security, List errors) List marketInfos = JClient.GSON.fromJson(markets.get(), collectionType); - return marketInfos - .stream().map( - m -> new Exchange(m.getMarketCode(), - MessageFormat.format(Messages.LabelXwithCurrencyY, - m.getMarketCode(), m.getCurrencyCode()))) - .collect(Collectors.toList()); + return marketInfos.stream() + .map(m -> new Exchange(m.getMarketCode(), MessageFormat.format(Messages.LabelXwithCurrencyY, + MarketIdentifierCodes.getLabel(m.getMarketCode()), m.getCurrencyCode()))) + .toList(); } } diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/TwelveDataQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/TwelveDataQuoteFeed.java index 64a94c04e7..9fb01bd05f 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/TwelveDataQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/TwelveDataQuoteFeed.java @@ -246,36 +246,30 @@ public final List getExchanges(Security subject, List error // Extract the exchange from the ticker symbol, if present int p = tickerSymbol.indexOf('.'); - String securityExchange = p >= 0 ? tickerSymbol.substring(p + 1).toUpperCase() : null; + final String securityExchange = p >= 0 ? tickerSymbol.substring(p + 1).toUpperCase() : null; // Extract the symbol from the ticker symbol without the stock market // information - String symbol = p >= 0 ? tickerSymbol.substring(0, p).trim().toUpperCase() : tickerSymbol.trim().toUpperCase(); + final String symbol = p >= 0 ? tickerSymbol.substring(0, p).trim().toUpperCase() + : tickerSymbol.trim().toUpperCase(); if (!symbol.isEmpty()) { // Get a list of all exchange keys - List exchangeKeys = ExchangeLabels.getAllExchangeKeys("mic-ISO-10383."); //$NON-NLS-1$ + List exchangeKeys = MarketIdentifierCodes.getAllMarketIdentifierCodes(); // If a security exchange is specified and it's not present in the // exchange keys, add the symbol to the answer list if (securityExchange != null && !exchangeKeys.contains(securityExchange)) - answer.add(createExchange(symbol + "." + securityExchange)); //$NON-NLS-1$ + answer.add(new Exchange(tickerSymbol, tickerSymbol)); - exchangeKeys.forEach(e -> answer.add(createExchange(symbol + "." + e))); //$NON-NLS-1$ + exchangeKeys.forEach(e -> answer.add(new Exchange(symbol + "." + e, //$NON-NLS-1$ + MarketIdentifierCodes.getLabel(e)))); } return answer; } - private Exchange createExchange(String symbol) - { - int e = symbol.indexOf('.'); - String exchange = e >= 0 ? symbol.substring(e) : ".default"; //$NON-NLS-1$ - String label = ExchangeLabels.getString("mic-ISO-10383" + exchange); //$NON-NLS-1$ - return new Exchange(symbol, label); - } - private long asPrice(Object number) { if (number == null) diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/YahooFinanceQuoteFeed.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/YahooFinanceQuoteFeed.java index a54ff06f42..232dd0c293 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/YahooFinanceQuoteFeed.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/YahooFinanceQuoteFeed.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -315,10 +314,10 @@ public final List getExchanges(Security subject, List error // available for Yahoo search provider. List markets = subject.getProperties() - .filter(p -> p.getType() == SecurityProperty.Type.MARKET).collect(Collectors.toList()); + .filter(p -> p.getType() == SecurityProperty.Type.MARKET).toList(); markets.stream().map(p -> { - Exchange exchange = new Exchange(p.getValue(), ExchangeLabels.getString("portfolio-report." + p.getName())); //$NON-NLS-1$ + Exchange exchange = new Exchange(p.getValue(), MarketIdentifierCodes.getLabel(p.getName())); if ("XFRA".equals(p.getName())) //$NON-NLS-1$ exchange.setId(exchange.getId() + ".F"); //$NON-NLS-1$ return exchange; diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/exchange-labels.properties b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/exchange-labels.properties index a9f8091f62..398a5979ff 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/exchange-labels.properties +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/exchange-labels.properties @@ -4,9 +4,6 @@ # https://de.hilfe.yahoo.com/kb/SLN2310.html # https://help.yahoo.com/kb/SLN2310.html #---------------------------------------------------------------- -# mic-ISO-10383.XXXX --> Market identifier codes ISO-10383 -# https://www.iso20022.org/market-identifier-codes -#---------------------------------------------------------------- leeway.AS = Euronext Amsterdam leeway.AT = Athens Exchange @@ -88,82 +85,6 @@ leeway.XNSA = Nigerian Stock Exchange leeway.XZIM = Zimbabwe Stock Exchange leeway.ZSE = Zagreb Stock Exchange -mic-ISO-10383.ALXL = Euronext Lisbon -mic-ISO-10383.ASEX = Athens Stock Exchange -mic-ISO-10383.BMEX = Madrid Stock Exchange -mic-ISO-10383.BVCA = Caracas Stock Exchange -mic-ISO-10383.BVMF = Brazil Stock Exchange -mic-ISO-10383.DSMD = Qatar Stock Exchange -mic-ISO-10383.MISX = Moscow Exchange -mic-ISO-10383.NEOE = NEO Exchange - NEO-L (Market by Order) -mic-ISO-10383.XADS = Abu Dhabi Securities Exchange -mic-ISO-10383.XAMS = Euronext Amsterdam -mic-ISO-10383.XBER = Berlin Stock Exchange -mic-ISO-10383.XBKK = The Stock Exchange of Thailand -mic-ISO-10383.XBOG = Columbia Stock Exchange -mic-ISO-10383.XBOM = Bombay Stock Exchange -mic-ISO-10383.XBOT = Botswana Stock Exchange -mic-ISO-10383.XBRU = Euronext Brussels -mic-ISO-10383.XBSE = Bucharest Stock Exchange -mic-ISO-10383.XBUD = Budapest Stock Exchange -mic-ISO-10383.XBUE = Buenos Aires Stock Exchange -mic-ISO-10383.XCAI = Egyptian Exchange -mic-ISO-10383.XCNQ = Canadian Securities Exchange -mic-ISO-10383.XCOL = Colombo Stock Exchange -mic-ISO-10383.XCSE = Copenhagen Stock Exchange -mic-ISO-10383.XDUB = Euronext Dublin -mic-ISO-10383.XDUS = D\u00FCsseldorf Stock Exchange -mic-ISO-10383.XETR = Deutsche B\u00F6rse Xetra -mic-ISO-10383.XFRA = Frankfurt Stock Exchange -mic-ISO-10383.XHAM = Hamburg Stock Exchange -mic-ISO-10383.XHAN = Hannover Stock Exchange -mic-ISO-10383.XHEL = Helsinki Stock Exchange -mic-ISO-10383.XHKG = Hong Kong Stock Exchange -mic-ISO-10383.XIDX = Indonesia Stock Exchange -mic-ISO-10383.XIST = Borsa Istanbul -mic-ISO-10383.XJAM = Jamaica Stock Exchange -mic-ISO-10383.XJPX = Tokyo Stock Exchange -mic-ISO-10383.XJSE = Johannesburg Stock Exchange -mic-ISO-10383.XKAR = Pakistan Stock Exchange -mic-ISO-10383.XKLS = Malaysia Stock Exchange -mic-ISO-10383.XKRX = Korea Exchange -mic-ISO-10383.XKUW = Boursa Kuwait -mic-ISO-10383.XLIM = Lima Stock Exchange -mic-ISO-10383.XLIT = Vilnius Stock Exchange -mic-ISO-10383.XLON = London Stock Exchange -mic-ISO-10383.XMEX = Mexican Stock Exchange -mic-ISO-10383.XMIL = Italian Stock Exchange -mic-ISO-10383.XMUN = Munich Stock Exchange -mic-ISO-10383.XNAS = NASDAQ Exchange -mic-ISO-10383.XNGS = NASDAQ/NGS (Global Select Market) -mic-ISO-10383.XNSE = National Stock Exchange of India -mic-ISO-10383.XNYS = New York Stock Exchange -mic-ISO-10383.XNZE = New Zealand\u2019s Exchange -mic-ISO-10383.XOSL = Oslo Stock Exchange -mic-ISO-10383.XPAR = Euronext Paris -mic-ISO-10383.XPHS = Philippine Stock Exchange -mic-ISO-10383.XPRA = Prague Stock Exchange -mic-ISO-10383.XRIS = Riga Stock Exchange -mic-ISO-10383.XSAU = Saudi Stock Exchange -mic-ISO-10383.XSES = Singapore Exchange -mic-ISO-10383.XSGO = Santiago Stock Exchange -mic-ISO-10383.XSHE = Shenzhen Stock Exchange -mic-ISO-10383.XSHG = Shanghai Stock Exchange -mic-ISO-10383.XSTO = Stockholm Stock Exchange -mic-ISO-10383.XSTU = Stuttgart Stock Exchange -mic-ISO-10383.XSWX = SIX Swiss Exchange -mic-ISO-10383.XTAE = Tel-Aviv Stock Exchange -mic-ISO-10383.XTAI = Taiwan Stock Exchange -mic-ISO-10383.XTAL = Tallinn Stock Exchange -mic-ISO-10383.XTSE = Toronto Stock Exchange -mic-ISO-10383.XTSX = TSX Venture Exchange -mic-ISO-10383.XWAR = Poland Stock Exchange -mic-ISO-10383.XWBO = Vienna Stock Exchange - -portfolio-report.XFRA = Frankfurt -portfolio-report.XNAS = NASDAQ -portfolio-report.XNYS = New York - yahoo.AS = Euronext Amsterdam yahoo.AT = Athens Stock Exchange (ATHEX) yahoo.AX = Australian Stock Exchange (ASX) diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/market-identifier-codes.properties b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/market-identifier-codes.properties new file mode 100644 index 0000000000..d4b6ee8aa4 --- /dev/null +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/online/impl/market-identifier-codes.properties @@ -0,0 +1,76 @@ +#---------------------------------------------------------------- +# XXXX --> Market identifier codes ISO-10383 +# https://www.iso20022.org/market-identifier-codes +#---------------------------------------------------------------- + +ALXL = Euronext Lisbon +ASEX = Athens Stock Exchange +BMEX = Madrid Stock Exchange +BVCA = Caracas Stock Exchange +BVMF = Brazil Stock Exchange +DSMD = Qatar Stock Exchange +MISX = Moscow Exchange +NEOE = NEO Exchange - NEO-L (Market by Order) +XADS = Abu Dhabi Securities Exchange +XAMS = Euronext Amsterdam +XBER = Berlin Stock Exchange +XBKK = The Stock Exchange of Thailand +XBOG = Columbia Stock Exchange +XBOM = Bombay Stock Exchange +XBOT = Botswana Stock Exchange +XBRU = Euronext Brussels +XBSE = Bucharest Stock Exchange +XBUD = Budapest Stock Exchange +XBUE = Buenos Aires Stock Exchange +XCAI = Egyptian Exchange +XCNQ = Canadian Securities Exchange +XCOL = Colombo Stock Exchange +XCSE = Copenhagen Stock Exchange +XDUB = Euronext Dublin +XDUS = D\u00FCsseldorf Stock Exchange +XETR = Deutsche B\u00F6rse Xetra +XFRA = Frankfurt Stock Exchange +XHAM = Hamburg Stock Exchange +XHAN = Hannover Stock Exchange +XHEL = Helsinki Stock Exchange +XHKG = Hong Kong Stock Exchange +XIDX = Indonesia Stock Exchange +XIST = Borsa Istanbul +XJAM = Jamaica Stock Exchange +XJPX = Tokyo Stock Exchange +XJSE = Johannesburg Stock Exchange +XKAR = Pakistan Stock Exchange +XKLS = Malaysia Stock Exchange +XKRX = Korea Exchange +XKUW = Boursa Kuwait +XLIM = Lima Stock Exchange +XLIT = Vilnius Stock Exchange +XLON = London Stock Exchange +XMEX = Mexican Stock Exchange +XMIL = Italian Stock Exchange +XMUN = Munich Stock Exchange +XNAS = NASDAQ Exchange +XNGS = NASDAQ/NGS (Global Select Market) +XNSE = National Stock Exchange of India +XNYS = New York Stock Exchange +XNZE = New Zealand\u2019s Exchange +XOSL = Oslo Stock Exchange +XPAR = Euronext Paris +XPHS = Philippine Stock Exchange +XPRA = Prague Stock Exchange +XRIS = Riga Stock Exchange +XSAU = Saudi Stock Exchange +XSES = Singapore Exchange +XSGO = Santiago Stock Exchange +XSHE = Shenzhen Stock Exchange +XSHG = Shanghai Stock Exchange +XSTO = Stockholm Stock Exchange +XSTU = Stuttgart Stock Exchange +XSWX = SIX Swiss Exchange +XTAE = Tel-Aviv Stock Exchange +XTAI = Taiwan Stock Exchange +XTAL = Tallinn Stock Exchange +XTSE = Toronto Stock Exchange +XTSX = TSX Venture Exchange +XWAR = Poland Stock Exchange +XWBO = Vienna Stock Exchange diff --git a/portfolio-app/releng/translation-config.xml b/portfolio-app/releng/translation-config.xml index d0010698d3..4449db3346 100644 --- a/portfolio-app/releng/translation-config.xml +++ b/portfolio-app/releng/translation-config.xml @@ -36,7 +36,6 @@ exchange-labels leeway.* - mic-ISO-10383.*