Skip to content

Commit

Permalink
Refactored market identifier codes into separate properties file
Browse files Browse the repository at this point in the history
Issue: #3373
  • Loading branch information
buchen committed Jun 4, 2023
1 parent 341a5ee commit 1c2e88a
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> getAllMarketIdentifierCodes()
{
List<String> answer = new ArrayList<>();

Enumeration<String> keys = BUNDLE.getKeys();
while (keys.hasMoreElements())
{
String key = keys.nextElement();
answer.add(key);
}

Collections.sort(answer);

return answer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -187,12 +186,10 @@ public List<Exchange> getExchanges(Security security, List<Exception> errors)

List<MarketInfo> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -246,36 +246,30 @@ public final List<Exchange> getExchanges(Security subject, List<Exception> 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<String> exchangeKeys = ExchangeLabels.getAllExchangeKeys("mic-ISO-10383."); //$NON-NLS-1$
List<String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -315,10 +314,10 @@ public final List<Exchange> getExchanges(Security subject, List<Exception> error
// available for Yahoo search provider.

List<SecurityProperty> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion portfolio-app/releng/translation-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<filename>exchange-labels</filename>
<excludes>
<string>leeway.*</string>
<string>mic-ISO-10383.*</string>
</excludes>
</artifact>
<artifact>
Expand Down

0 comments on commit 1c2e88a

Please sign in to comment.