Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sstrickx committed May 17, 2022
2 parents 986d1ed + 2f6571e commit d4d7bf4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 29 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Finance Quotes API for Yahoo Finance (Java)

[![Build Status](https://travis-ci.org/sstrickx/yahoofinance-api.svg?branch=master)](https://travis-ci.org/sstrickx/yahoofinance-api)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.yahoofinance-api/YahooFinanceAPI/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.yahoofinance-api/YahooFinanceAPI)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)


[Website](http://financequotes-api.com)

Expand Down
10 changes: 5 additions & 5 deletions 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>3.16.0</version>
<version>3.17.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>YahooFinanceAPI</name>
<description>This library provides some methods that should make it easy
Expand Down Expand Up @@ -41,8 +41,8 @@
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<distributionManagement>
Expand All @@ -65,7 +65,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.10.8</version>
<version>2.12.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -88,7 +88,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<version>31.1-jre</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/yahoofinance/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand All @@ -21,12 +22,12 @@
public class Utils {

private static final Logger log = LoggerFactory.getLogger(Utils.class);

public static final BigDecimal HUNDRED = new BigDecimal(100);
public static final BigDecimal THOUSAND = new BigDecimal(1000);
public static final BigDecimal MILLION = new BigDecimal(1000000);
public static final BigDecimal BILLION = new BigDecimal(1000000000);

public static String join(String[] data, String d) {
if (data.length == 0) {
return "";
Expand All @@ -45,7 +46,7 @@ private static String cleanNumberString(String data) {
}

private static boolean isParseable(String data) {
return !(data == null || data.equals("N/A") || data.equals("-")
return !(data == null || data.equals("N/A") || data.equals("-")
|| data.equals("") || data.equals("nan"));
}

Expand All @@ -55,7 +56,7 @@ public static String getString(String data) {
}
return data;
}

public static BigDecimal getBigDecimal(String data) {
BigDecimal result = null;
if (!Utils.isParseable(data)) {
Expand Down Expand Up @@ -86,7 +87,7 @@ public static BigDecimal getBigDecimal(String data) {
}
return result;
}

public static BigDecimal getBigDecimal(String dataMain, String dataSub) {
BigDecimal main = getBigDecimal(dataMain);
BigDecimal sub = getBigDecimal(dataSub);
Expand Down Expand Up @@ -161,10 +162,10 @@ public static BigDecimal getPercent(BigDecimal numerator, BigDecimal denominator
if (denominator == null || numerator == null || denominator.compareTo(BigDecimal.ZERO) == 0) {
return BigDecimal.ZERO;
}
return numerator.divide(denominator, 4, BigDecimal.ROUND_HALF_EVEN)
.multiply(HUNDRED).setScale(2, BigDecimal.ROUND_HALF_EVEN);
return numerator.divide(denominator, 4, RoundingMode.HALF_EVEN)
.multiply(HUNDRED).setScale(2, RoundingMode.HALF_EVEN);
}

public static double getPercent(double numerator, double denominator) {
if (denominator == 0) {
return 0;
Expand Down Expand Up @@ -235,7 +236,7 @@ public static Calendar parseDividendDate(String date) {
public static Calendar parseDateTime(String date, String time, TimeZone timeZone) {
String datetime = date + " " + time;
SimpleDateFormat format = new SimpleDateFormat("M/d/yyyy h:mma", Locale.US);

format.setTimeZone(timeZone);
try {
if (Utils.isParseable(date) && Utils.isParseable(time)) {
Expand Down Expand Up @@ -294,7 +295,7 @@ public static String getURLParameters(Map<String, String> params) {
}

/**
* Strips the unwanted chars from a line returned in the CSV
* Strips the unwanted chars from a line returned in the CSV
* Used for parsing the FX CSV lines
*
* @param line the original CSV line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public List<HistoricalSplit> getResult() throws IOException {

private HistoricalSplit parseCSVLine(String line) {
String[] data = line.split(YahooFinance.QUOTES_CSV_DELIMITER);
String[] parts = data[1].split("/");
String[] parts = data[1].split(":");
return new HistoricalSplit(this.symbol,
Utils.parseHistDate(data[0]),
Utils.getBigDecimal(parts[0]),
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/yahoofinance/HistoricalQuoteRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void historicalQuoteTest() throws IOException {
assertEquals(new BigDecimal("769.900024"), histQuote.getHigh());
assertEquals(new BigDecimal("689.00"), histQuote.getLow());
assertEquals(new BigDecimal("738.599976"), histQuote.getOpen());
assertEquals(new Long(2125700), histQuote.getVolume());
assertEquals(Long.valueOf(2125700), histQuote.getVolume());
assertEquals(3, histQuote.getDate().get(Calendar.MONTH));
assertEquals(1, histQuote.getDate().get(Calendar.DATE));
assertEquals(2016, histQuote.getDate().get(Calendar.YEAR));
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/yahoofinance/SimpleQuoteRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public void europeStockQuoteTest() throws IOException {
assertNotNull(stock.getDividend());

assertEquals(new BigDecimal("54.93"), stock.getQuote().getAsk());
assertEquals(new Long(700), stock.getQuote().getAskSize());
assertEquals(Long.valueOf(700), stock.getQuote().getAskSize());
assertEquals(new BigDecimal("54.00"), stock.getQuote().getBid());
assertEquals(new Long(42000), stock.getQuote().getBidSize());
assertEquals(Long.valueOf(42000), stock.getQuote().getBidSize());
assertEquals(new BigDecimal("50.34"), stock.getQuote().getPrice());
assertEquals(new Long(813), stock.getQuote().getLastTradeSize());
assertEquals(Long.valueOf(813), stock.getQuote().getLastTradeSize());
assertEquals(new BigDecimal("50.58"), stock.getQuote().getOpen());
assertEquals(new BigDecimal("51.00"), stock.getQuote().getPreviousClose());

Expand All @@ -46,8 +46,8 @@ public void europeStockQuoteTest() throws IOException {
assertEquals(new BigDecimal("51.81"), stock.getQuote().getPriceAvg50());
assertEquals(new BigDecimal("55.21"), stock.getQuote().getPriceAvg200());

assertEquals(new Long(1460112), stock.getQuote().getVolume());
assertEquals(new Long(2211770), stock.getQuote().getAvgVolume());
assertEquals(Long.valueOf(1460112), stock.getQuote().getVolume());
assertEquals(Long.valueOf(2211770), stock.getQuote().getAvgVolume());
assertEquals("8/8/2016", stock.getQuote().getLastTradeDateStr());
assertEquals("5:35pm", stock.getQuote().getLastTradeTimeStr());
assertEquals(TimeZone.getTimeZone("Europe/Paris"), stock.getQuote().getTimeZone());
Expand All @@ -64,8 +64,8 @@ public void europeStockQuoteTest() throws IOException {
assertEquals(new BigDecimal("4.72"), stock.getQuote().getChangeFromYearLowInPercent());

assertEquals(new BigDecimal("38880000000.00"), stock.getStats().getMarketCap());
assertEquals(new Long(654166000), stock.getStats().getSharesFloat());
assertEquals(new Long(772397000), stock.getStats().getSharesOutstanding());
assertEquals(Long.valueOf(654166000), stock.getStats().getSharesFloat());
assertEquals(Long.valueOf(772397000), stock.getStats().getSharesOutstanding());
assertEquals(new BigDecimal("3.74"), stock.getStats().getEps());
assertEquals(new BigDecimal("13.47"), stock.getStats().getPe());
assertEquals(new BigDecimal("0.00"), stock.getStats().getPeg());
Expand Down Expand Up @@ -105,7 +105,7 @@ public void usStockQuoteTest() throws IOException {
* Most things already tested by europeanStockQuoteTest
*/
assertEquals(new BigDecimal("35.03"), stock.getQuote().getAsk());
assertEquals(new Long(1699919), stock.getQuote().getLastTradeSize());
assertEquals(Long.valueOf(1699919), stock.getQuote().getLastTradeSize());
assertEquals(new BigDecimal("34.98"), stock.getQuote().getPreviousClose());
assertEquals(new BigDecimal("35.93"), stock.getQuote().getYearHigh());

Expand Down Expand Up @@ -135,7 +135,7 @@ public void singaporeStockQuoteTest() throws IOException {
assertNotNull(stock.getDividend());

assertEquals(new BigDecimal("10.89"), stock.getQuote().getAsk());
assertEquals(new Long(300), stock.getQuote().getLastTradeSize());
assertEquals(Long.valueOf(300), stock.getQuote().getLastTradeSize());
assertEquals(new BigDecimal("10.84"), stock.getQuote().getPreviousClose());
assertEquals(new BigDecimal("9.57"), stock.getQuote().getYearLow());

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/yahoofinance/mock/YahooFinanceDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class YahooFinanceDispatcher extends Dispatcher {

private static final Logger log = LoggerFactory.getLogger(YahooFinanceDispatcher.class);

private Map<String, ResponseResource> pathToResponseResource;
private final Map<String, ResponseResource> pathToResponseResource;

public YahooFinanceDispatcher() {
this.pathToResponseResource = new HashMap<String, ResponseResource>();
Expand All @@ -45,7 +45,7 @@ private void loadRequests() {
Map<String, List<Map<String, Object>>> requests;
try {
String requestsYaml = Resources.toString(Resources.getResource("requests.yml"), Charsets.UTF_8);
requests = (Map<String, List<Map<String, Object>>>) yaml.load(requestsYaml);
requests = yaml.load(requestsYaml);
} catch (IOException e) {
log.warn("Unable to process requests.yml. No requests mocked.", e);
return;
Expand Down

0 comments on commit d4d7bf4

Please sign in to comment.