Skip to content

Commit 0dc4eed

Browse files
committed
Support Google Finance for Sweden.
1 parent 042cfff commit 0dc4eed

File tree

2 files changed

+45
-26
lines changed

2 files changed

+45
-26
lines changed

src/org/yccheok/jstock/engine/Factories.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public int compare(StockServerFactory o1, StockServerFactory o2) {
192192
singaporeList.add(YahooStockServerFactory.newInstance());
193193
spainList.add(YahooStockServerFactory.newInstance());
194194
swedenList.add(YahooStockServerFactory.newInstance());
195+
swedenList.add(GoogleStockServerFactory.newInstance());
195196
switzerlandList.add(YahooStockServerFactory.newInstance());
196197
taiwanList.add(GoogleStockServerFactory.newInstance());
197198
taiwanList.add(YahooStockServerFactory.newInstance());

src/org/yccheok/jstock/engine/Utils.java

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static Stock getEmptyStock(Code code, Symbol symbol) {
9696
}
9797

9898
public static Country toCountry(Code code) {
99-
assert(countries.keySet().size() == 43);
99+
assert(countries.keySet().size() == 44);
100100

101101
String string = code.toString();
102102
int index = string.lastIndexOf(".");
@@ -428,11 +428,26 @@ public static String toGoogleFormat(Code code) {
428428
}
429429

430430
final int string_length = string.length();
431-
if (string.endsWith(".N") && string_length > ".N".length()) {
432-
return "NSE:" + string.substring(0, string_length - ".N".length());
433-
} else if (string.endsWith(".B") && string_length > ".B".length()) {
434-
return "BOM:" + string.substring(0, string_length - ".B".length());
435-
} else if (string.endsWith(".NS") && string_length > ".NS".length()) {
431+
if (string_length > 3) {
432+
String suffix = string.substring(string_length-3, string_length);
433+
String prefix = twoLetterSuffixes.get(suffix);
434+
if (prefix != null) {
435+
return prefix + string.substring(0, string_length - 3);
436+
}
437+
}
438+
439+
if (string_length > 2) {
440+
String suffix = string.substring(string_length-2, string_length);
441+
System.out.println("suffix = " + suffix);
442+
String prefix = oneLetterSuffixes.get(suffix);
443+
if (prefix != null) {
444+
return prefix + string.substring(0, string_length - 2);
445+
}
446+
}
447+
448+
if (string_length > ".NS".length() && string.endsWith(".NS")) {
449+
// Special case.
450+
436451
// Resolving Yahoo server down for India NSE stock market. Note, we
437452
// do not support Bombay stock market at this moment, due to the
438453
// difficulty in converting "TATACHEM.BO" (Yahoo Finance) to
@@ -442,27 +457,11 @@ public static String toGoogleFormat(Code code) {
442457
if (googleFormat != null) {
443458
return "NSE:" + googleFormat;
444459
}
445-
} else if (string.endsWith(".SS") && string_length > ".SS".length()) {
446-
return "SHA:" + string.substring(0, string_length - ".SS".length());
447-
} else if (string.endsWith(".SZ") && string_length > ".SZ".length()) {
448-
return "SHE:" + string.substring(0, string_length - ".SZ".length());
449-
} else if (string.endsWith(".SA") && string_length > ".SA".length()) {
450-
return "BVMF:" + string.substring(0, string_length - ".SA".length());
451-
} else if (string.endsWith(".VI") && string_length > ".VI".length()) {
452-
return "VIE:" + string.substring(0, string_length - ".VI".length());
453-
} else if (string.endsWith(".L") && string_length > ".L".length()) {
454-
return "LON:" + string.substring(0, string_length - ".L".length());
455-
} else if (string.endsWith(".SI") && string_length > ".SI".length()) {
456-
return "SGX:" + string.substring(0, string_length - ".SI".length());
457-
} else if (string.endsWith(".TW") && string_length > ".TW".length()) {
458-
return "TPE:" + string.substring(0, string_length - ".TW".length());
459-
} else if (string.endsWith(".NZ") && string_length > ".NZ".length()) {
460-
return "NZE:" + string.substring(0, string_length - ".NZ".length());
461460
}
462-
461+
463462
return string;
464463
}
465-
464+
466465
private static boolean isYahooIndexSubset(Code code) {
467466
return code.toString().startsWith("^");
468467
}
@@ -817,7 +816,23 @@ public static Set<PriceSource> getSupportedPriceSources(Country country) {
817816
private static final Map<Class<? extends StockServerFactory>, PriceSource> classToPriceSourceMap = new HashMap<Class<? extends StockServerFactory>, PriceSource>();
818817
private static final Map<String, Integer> googleUnitedStatesStockExchanges = new HashMap<String, Integer>();
819818

819+
private static final Map<String, String> oneLetterSuffixes = new HashMap<String, String>();
820+
private static final Map<String, String> twoLetterSuffixes = new HashMap<String, String>();
821+
820822
static {
823+
oneLetterSuffixes.put(".N", "NSE:");
824+
oneLetterSuffixes.put(".B", "BOM:");
825+
oneLetterSuffixes.put(".L", "LON:");
826+
827+
twoLetterSuffixes.put(".SS", "SHA:");
828+
twoLetterSuffixes.put(".SZ", "SHE:");
829+
twoLetterSuffixes.put(".SA", "BVMF:");
830+
twoLetterSuffixes.put(".VI", "VIE:");
831+
twoLetterSuffixes.put(".SI", "SGX:");
832+
twoLetterSuffixes.put(".TW", "TPE:");
833+
twoLetterSuffixes.put(".NZ", "NZE:");
834+
twoLetterSuffixes.put(".ST", "STO:");
835+
821836
countries.put("AX", Country.Australia);
822837
countries.put("VI", Country.Austria);
823838
countries.put("SA", Country.Brazil);
@@ -864,8 +879,10 @@ public static Set<PriceSource> getSupportedPriceSources(Country country) {
864879
countries.put("MC", Country.Spain);
865880
countries.put("VA", Country.Spain);
866881

867-
countries.put("SW", Country.Sweden);
868-
countries.put("VX", Country.Sweden);
882+
countries.put("ST", Country.Sweden);
883+
884+
countries.put("SW", Country.Switzerland);
885+
countries.put("VX", Country.Switzerland);
869886

870887
countries.put("TW", Country.Taiwan);
871888
countries.put("TWO", Country.Taiwan);
@@ -886,6 +903,7 @@ public static Set<PriceSource> getSupportedPriceSources(Country country) {
886903
toGoogleIndex.put("^FTSE", "INDEXFTSE:UKX");
887904
toGoogleIndex.put("^TWII", "TPE:TAIEX");
888905
toGoogleIndex.put("^NZ50", "NZE:NZ50G");
906+
toGoogleIndex.put("^OMX", "INDEXNASDAQ:OMXS30");
889907

890908
// TODO : Need revision. We no longer have primaryStockServerFactoryClasses
891909
// concept. Going to replace with PriceSource.

0 commit comments

Comments
 (0)