Skip to content

Commit

Permalink
Release 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sstrickx committed Feb 15, 2016
2 parents 982815d + 52dedd6 commit 1687cf0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 17 deletions.
Binary file removed dist/YahooFinanceAPI-2.0.1.zip
Binary file not shown.
Binary file added dist/YahooFinanceAPI-2.1.0.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.yahoofinance-api</groupId>
<artifactId>YahooFinanceAPI</artifactId>
<version>2.0.1</version>
<version>2.1.0</version>
<packaging>jar</packaging>
<name>YahooFinanceAPI</name>
<description>This library provides some methods that should make it easy
Expand Down
21 changes: 14 additions & 7 deletions src/yahoofinance/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public static BigDecimal getBigDecimal(String data) {
}
result = new BigDecimal(data).multiply(multiplier);
} catch (NumberFormatException e) {
YahooFinance.logger.log(Level.INFO, "Failed to parse: " + data, e);
YahooFinance.logger.log(Level.WARNING, "Failed to parse: " + data);
YahooFinance.logger.log(Level.FINEST, "Failed to parse: " + data, e);
}
return result;
}
Expand Down Expand Up @@ -108,7 +109,8 @@ public static double getDouble(String data) {
}
result = Double.parseDouble(data) * multiplier;
} catch (NumberFormatException e) {
YahooFinance.logger.log(Level.INFO, "Failed to parse: " + data, e);
YahooFinance.logger.log(Level.WARNING, "Failed to parse: " + data);
YahooFinance.logger.log(Level.FINEST, "Failed to parse: " + data, e);
}
return result;
}
Expand All @@ -122,7 +124,8 @@ public static int getInt(String data) {
data = Utils.cleanNumberString(data);
result = Integer.parseInt(data);
} catch (NumberFormatException e) {
YahooFinance.logger.log(Level.INFO, "Failed to parse: " + data, e);
YahooFinance.logger.log(Level.WARNING, "Failed to parse: " + data);
YahooFinance.logger.log(Level.FINEST, "Failed to parse: " + data, e);
}
return result;
}
Expand All @@ -136,7 +139,8 @@ public static long getLong(String data) {
data = Utils.cleanNumberString(data);
result = Long.parseLong(data);
} catch (NumberFormatException e) {
YahooFinance.logger.log(Level.INFO, "Failed to parse: " + data, e);
YahooFinance.logger.log(Level.WARNING, "Failed to parse: " + data);
YahooFinance.logger.log(Level.FINEST, "Failed to parse: " + data, e);
}
return result;
}
Expand Down Expand Up @@ -201,7 +205,8 @@ public static Calendar parseDividendDate(String date) {

return parsedDate;
} catch (ParseException ex) {
YahooFinance.logger.log(Level.SEVERE, ex.getMessage(), ex);
YahooFinance.logger.log(Level.WARNING, "Failed to parse dividend date: " + date);
YahooFinance.logger.log(Level.FINEST, "Failed to parse dividend date: " + date, ex);
return null;
}
}
Expand All @@ -227,7 +232,8 @@ public static Calendar parseDateTime(String date, String time, TimeZone timeZone
return c;
}
} catch (ParseException ex) {
YahooFinance.logger.log(Level.SEVERE, ex.getMessage(), ex);
YahooFinance.logger.log(Level.WARNING, "Failed to parse datetime: " + datetime);
YahooFinance.logger.log(Level.FINEST, "Failed to parse datetime: " + datetime, ex);
}
return null;
}
Expand All @@ -242,7 +248,8 @@ public static Calendar parseHistDate(String date) {
return c;
}
} catch (ParseException ex) {
YahooFinance.logger.log(Level.SEVERE, ex.getMessage(), ex);
YahooFinance.logger.log(Level.WARNING, "Failed to parse hist date: " + date);
YahooFinance.logger.log(Level.FINEST, "Failed to parse hist date: " + date, ex);
}
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions src/yahoofinance/YahooFinance.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
* all of the required information in the least amount of
* requests possible towards Yahoo Finance.
* <p>
* You can change the default timeout of 10s for requests to Yahoo Finance by
* setting the yahoofinance.connection.timeout system property.
* <p>
* Please be aware that the data received from Yahoo Finance is not always
* complete for every single stock. Stocks on the American stock exchanges
* usually have a lot more data available than stocks on other exchanges.
Expand All @@ -46,6 +49,9 @@ public class YahooFinance {
public static final String QUOTES_CSV_DELIMITER = ",";
public static final String TIMEZONE = "America/New_York";

public static final int CONNECTION_TIMEOUT =
Integer.parseInt(System.getProperty("yahoofinance.connection.timeout", "10000"));

public static final Logger logger = Logger.getLogger(YahooFinance.class.getName());

/**
Expand Down
37 changes: 28 additions & 9 deletions src/yahoofinance/histquotes/HistQuotesRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ public HistQuotesRequest(String symbol) {
}

public HistQuotesRequest(String symbol, Interval interval) {
this.symbol = symbol;
this.interval = interval;

this.from = DEFAULT_FROM;
this.to = DEFAULT_TO;
this(symbol, DEFAULT_FROM, DEFAULT_TO, interval);
}

public HistQuotesRequest(String symbol, Calendar from, Calendar to) {
Expand All @@ -54,8 +50,8 @@ public HistQuotesRequest(String symbol, Calendar from, Calendar to) {

public HistQuotesRequest(String symbol, Calendar from, Calendar to, Interval interval) {
this.symbol = symbol;
this.from = from;
this.to = to;
this.from = this.cleanHistCalendar(from);
this.to = this.cleanHistCalendar(to);
this.interval = interval;
}

Expand All @@ -66,13 +62,34 @@ public HistQuotesRequest(String symbol, Date from, Date to) {
public HistQuotesRequest(String symbol, Date from, Date to, Interval interval) {
this(symbol, interval);
this.from.setTime(from);
this.to.setTime(to);
this.to.setTime(from);
this.cleanHistCalendar(this.from);
this.cleanHistCalendar(this.to);
}

/**
* Put everything smaller than days at 0
* @param cal calendar to be cleaned
*/
private Calendar cleanHistCalendar(Calendar cal) {
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.HOUR, 0);
return cal;
}

public List<HistoricalQuote> getResult() throws IOException {

List<HistoricalQuote> result = new ArrayList<HistoricalQuote>();


if(this.from.equals(this.to) || this.from.after(this.to)) {
YahooFinance.logger.log(Level.WARNING, "Unable to retrieve historical quotes. "
+ "From-date should be at least 1 day before to-date. From: "
+ this.from.getTime() + ", to: " + this.to.getTime());
return result;
}

Map<String, String> params = new LinkedHashMap<String, String>();
params.put("s", this.symbol);

Expand All @@ -95,6 +112,8 @@ public List<HistoricalQuote> getResult() throws IOException {

URL request = new URL(url);
URLConnection connection = request.openConnection();
connection.setConnectTimeout(YahooFinance.CONNECTION_TIMEOUT);
connection.setReadTimeout(YahooFinance.CONNECTION_TIMEOUT);
InputStreamReader is = new InputStreamReader(connection.getInputStream());
BufferedReader br = new BufferedReader(is);
br.readLine(); // skip the first line
Expand Down
2 changes: 2 additions & 0 deletions src/yahoofinance/quotes/QuotesRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public List<T> getResult() throws IOException {

URL request = new URL(url);
URLConnection connection = request.openConnection();
connection.setConnectTimeout(YahooFinance.CONNECTION_TIMEOUT);
connection.setReadTimeout(YahooFinance.CONNECTION_TIMEOUT);
InputStreamReader is = new InputStreamReader(connection.getInputStream());
BufferedReader br = new BufferedReader(is);

Expand Down

0 comments on commit 1687cf0

Please sign in to comment.