Skip to content

Commit

Permalink
Deprecate finance downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
apete committed Sep 7, 2024
1 parent 5893489 commit e52116e
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Added / Changed / Deprecated / Fixed / Removed / Security

- Re-implemented `Quadruple`'s divide method using primitives only. (Previously delegated to `BigDecimal`.)

### Deprecated

#### org.ojalgo.data

- Everything related to downloading (historical) financial data is deprecated. It's already broken (due to changes in the external "service") and we're not going to try fix it.

### Removed

#### org.ojalgo.structure
Expand Down
2 changes: 1 addition & 1 deletion ojAlgo Functionality Tests.launch
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<stringAttribute key="org.eclipse.jdt.junit.EXCLUDE_TAGS" value="slow"/>
<booleanAttribute key="org.eclipse.jdt.junit.HAS_EXCLUDE_TAGS" value="true"/>
<booleanAttribute key="org.eclipse.jdt.junit.HAS_INCLUDE_TAGS" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.INCLUDE_TAGS" value="new_lp_problem"/>
<stringAttribute key="org.eclipse.jdt.junit.INCLUDE_TAGS" value="network"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import org.ojalgo.type.CalendarDateUnit;

/**
* All data downloaders/fetchers are deprecated. They will be removed in a future release, and most likely
* they're already broken.
* <P>
* Fetch historical financial time series data from Alpha Vantage: https://www.alphavantage.co
*
* @see https://www.alphavantage.co
* @author stefanvanegmond
* @deprecated
*/
@Deprecated
public final class AlphaVantageFetcher implements DataFetcher {

private final ServiceClient.Request myRequest;
Expand Down Expand Up @@ -42,11 +47,12 @@ public AlphaVantageFetcher(final String symbol, final CalendarDateUnit resolutio
myRequest.query("symbol", symbol);
myRequest.query("apikey", apiKey);
myRequest.query("datatype", "csv");
if (fullOutputSize && (resolution == CalendarDateUnit.DAY) && !"demo".equals(apiKey)) {
if (fullOutputSize && resolution == CalendarDateUnit.DAY && !"demo".equals(apiKey)) {
myRequest.query("outputsize", "full");
}
}

@Override
public InputStream getInputStream() {
Response<InputStream> response = myRequest.send(BodyHandlers.ofInputStream());
if (response.isResponseOK()) {
Expand All @@ -56,10 +62,12 @@ public InputStream getInputStream() {
}
}

@Override
public CalendarDateUnit getResolution() {
return myResolution;
}

@Override
public String getSymbol() {
return mySymbol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public DataSource.Coordinated addYahoo(final String symbol) {
return this;
}

@Override
public CoordinatedSet<LocalDate> get() {
switch (myResolution) {
case YEAR:
Expand Down Expand Up @@ -127,10 +128,24 @@ public static Coordinated coordinated(final CalendarDateUnit resolution) {
return new DataSource.Coordinated().resolution(resolution);
}

/**
* All data downloaders/fetchers are deprecated. They will be removed in a future release, and most likely
* they're already broken.
*
* @deprecated
*/
@Deprecated
public static DataSource newAlphaVantage(final String symbol, final CalendarDateUnit resolution, final String apiKey) {
return DataSource.newAlphaVantage(symbol, resolution, apiKey, false);
}

/**
* All data downloaders/fetchers are deprecated. They will be removed in a future release, and most likely
* they're already broken.
*
* @deprecated
*/
@Deprecated
public static DataSource newAlphaVantage(final String symbol, final CalendarDateUnit resolution, final String apiKey, final boolean fullOutputSize) {
AlphaVantageFetcher fetcher = new AlphaVantageFetcher(symbol, resolution, apiKey, fullOutputSize);
AlphaVantageParser parser = new AlphaVantageParser();
Expand All @@ -145,12 +160,26 @@ public static <T extends DatePrice> DataSource newFileReader(final File file, fi
return new DataSource(FinanceDataReader.of(file, parser, resolution), parser);
}

/**
* All data downloaders/fetchers are deprecated. They will be removed in a future release, and most likely
* they're already broken.
*
* @deprecated
*/
@Deprecated
public static DataSource newIEXTrading(final String symbol) {
IEXTradingFetcher fetcher = new IEXTradingFetcher(symbol);
IEXTradingParser parser = new IEXTradingParser();
return new DataSource(fetcher, parser);
}

/**
* All data downloaders/fetchers are deprecated. They will be removed in a future release, and most likely
* they're already broken.
*
* @deprecated
*/
@Deprecated
public static DataSource newYahoo(final YahooSession session, final String symbol, final CalendarDateUnit resolution) {
YahooSession.Fetcher fetcher = session.newFetcher(symbol, resolution);
YahooParser parser = new YahooParser();
Expand Down Expand Up @@ -215,6 +244,7 @@ public CalendarDateSeries<Double> getCalendarDateSeries(final LocalTime time, fi
return this.getCalendarDateSeries(myFetcher.getResolution(), time, zoneId);
}

@Override
public KeyValue<String, List<DatePrice>> getHistoricalData() {

String key = myFetcher.getSymbol();
Expand All @@ -233,6 +263,7 @@ public KeyValue<String, List<DatePrice>> getHistoricalData() {
return KeyValue.of(key, value);
}

@Override
public List<DatePrice> getHistoricalPrices() {
return this.getHistoricalData().getValue();
}
Expand All @@ -253,10 +284,12 @@ public BasicSeries<LocalDate, PrimitiveNumber> getLocalDateSeries(final DenseArr
return this.getLocalDateSeries(this.getHistoricalPrices(), myFetcher.getResolution());
}

@Override
public BasicSeries<LocalDate, PrimitiveNumber> getPriceSeries() {
return this.getLocalDateSeries(this.getHistoricalPrices(), myFetcher.getResolution());
}

@Override
public String getSymbol() {
return myFetcher.getSymbol();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.ojalgo.type.CalendarDateUnit;

/**
* All data downloaders/fetchers are deprecated. They will be removed in a future release, and most likely
* they're already broken.
* <P>
* Fetch historical financial time series data from IEX Trading: https://exchange.iex.io / https://iexcloud.io
* <p>
* This service has been moved/renamed/repackaged – this {@link DataFetcher} no longer works. Looks to me as
Expand Down Expand Up @@ -38,6 +41,7 @@ public IEXTradingFetcher(final String symbol) {
myRequest = ServiceClient.newRequest().host("cloud.iexapis.com").path("/1.0/stock/" + symbol + "/chart/5y").query("format", "csv");
}

@Override
public InputStream getInputStream() {
Response<InputStream> response = myRequest.send(BodyHandlers.ofInputStream());
if (response.isResponseOK()) {
Expand All @@ -52,10 +56,12 @@ public InputStream getInputStream() {
*
* @see org.ojalgo.data.domain.finance.series.DataFetcher#getResolution()
*/
@Override
public CalendarDateUnit getResolution() {
return CalendarDateUnit.DAY;
}

@Override
public String getSymbol() {
return mySymbol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@
import org.ojalgo.type.CalendarDateUnit;

/**
* All data downloaders/fetchers are deprecated. They will be removed in a future release, and most likely
* they're already broken.
* <P>
* Fetch historical financial time series data from Yahoo Finance: https://finance.yahoo.com
*
* @see https://finance.yahoo.com
* @author apete
* @deprecated
*/
@Deprecated
public final class YahooSession {

public static final class Fetcher implements DataFetcher {
Expand All @@ -52,6 +57,7 @@ public static final class Fetcher implements DataFetcher {
myResolution = resolution;
}

@Override
public InputStream getInputStream() {

// https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=345427200&period2=1663718400&interval=1d&events=history&includeAdjustedClose=true
Expand Down Expand Up @@ -88,10 +94,12 @@ public InputStream getInputStream() {
}
}

@Override
public CalendarDateUnit getResolution() {
return myResolution;
}

@Override
public String getSymbol() {
return mySymbol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import org.ojalgo.type.CalendarDateUnit;

/**
* All data downloaders/fetchers are deprecated. They will be removed in a future release, and most likely
* they're already broken.
* <P>
* Old, deprecated and non-functioning, version of {@link YahooSession}. Keeping it for a while as
* documentation of how it had to be done previously.
*
Expand Down Expand Up @@ -61,6 +64,7 @@ static final class Fetcher implements DataFetcher {

}

@Override
public InputStream getInputStream() {

if (debug) {
Expand All @@ -70,7 +74,7 @@ public InputStream getInputStream() {
}

String crumb = mySession.getParameterValue(CRUMB);
if ((crumb == null) || (crumb.length() <= 0)) {
if (crumb == null || crumb.length() <= 0) {
// No crumb, and assume no cookie either

Request challengeRequest = YahooSessionOld.buildChallengeRequest(mySession, mySymbol);
Expand All @@ -81,15 +85,15 @@ public InputStream getInputStream() {
challengeResponse.print(BasicLogger.DEBUG);
}

if ((challengeResponse.toString() != null) && !challengeRequest.equals(challengeResponse.getRequest())) {
if (challengeResponse.toString() != null && !challengeRequest.equals(challengeResponse.getRequest())) {
// Was redirect (to ask for consent)

YahooSessionOld.scrapeChallengeResponse(mySession, challengeResponse);

Request consentRequest = YahooSessionOld.buildConsentRequest(mySession, challengeRequest);
Response consentResponse = consentRequest.response();

if ((consentResponse.toString() != null) && debug) {
if (consentResponse.toString() != null && debug) {
consentRequest.print(BasicLogger.DEBUG);
consentResponse.print(BasicLogger.DEBUG);
}
Expand Down Expand Up @@ -119,10 +123,12 @@ public InputStream getInputStream() {
return response.getInputStream();
}

@Override
public CalendarDateUnit getResolution() {
return myResolution;
}

@Override
public String getSymbol() {
return mySymbol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.ojalgo.data.domain.finance.series;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.ojalgo.TestUtils;
Expand All @@ -31,6 +32,7 @@
* @author stefanvanegmond
*/
@Tag("network")
@Disabled
public class AlphaVantageDataSourceTest extends FinanceSeriesTests {

public AlphaVantageDataSourceTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.ojalgo.data.domain.finance.series;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.ojalgo.TestUtils;
Expand All @@ -33,6 +34,7 @@
* @author apete
*/
@Tag("network")
@Disabled
public class YahooDataSourceTest extends FinanceSeriesTests {

private static YahooSession SESSION = new YahooSession();
Expand Down

0 comments on commit e52116e

Please sign in to comment.