Skip to content

Commit

Permalink
update changelog and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
crazzyghost committed May 9, 2020
1 parent 307c6b6 commit 7c81870
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.3.0] - 09-05-2020
### Added
- Support for Quote Endpoint
- Tests for TimeSeries
### Changed
- RequestHelper to RequestProxy for TimeSeries
### Fixed
- Time Series IntradayRequest interval bug


## [v1.2.1] - 07-05-2020
### Added
- Tests for Forex
Expand Down Expand Up @@ -47,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Tests for Time Series
- README

[1.3.0]: https://github.com/crazzyghost/alphavantage-java/releases/tag/1.3.0
[1.2.1]: https://github.com/crazzyghost/alphavantage-java/releases/tag/1.2.1
[1.2.0]: https://github.com/crazzyghost/alphavantage-java/releases/tag/1.2.0
[1.1.1]: https://github.com/crazzyghost/alphavantage-java/releases/tag/1.1.1
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,22 @@ When you are okay with setting the parameters call the `fetch()` method. Simple!
### Examples
#### Fetching Stock Time Series Data
```java
...
AlphaVantage.api()
.timeSeries()
.intraday()
.onSuccess(e->handleSuccess(e))
.onSuccess((TimeSeriesResponse e)->handleSuccess(e))
.interval(Interval.ONE_MIN)
.onFailure(e->handleFailure(e))
.forSymbol("MSFT")
.fetch();
...
void handleSuccess(TimeSeriesResponse e){
plotGraph(e.getStockUnits(), e.getMetaData());
}

//Quote Endpoint
AlphaVantage.api()
.timeSeries()
.quote()
.forSymbol("IBM")
.onSuccess((QuoteResponse e) -> handleSuccess(e))
.fetch();
```

#### Fetching Forex Rate Data
Expand Down Expand Up @@ -143,7 +145,7 @@ AlphaVantage.api()
.market("CNY")
.onSuccess(CryptoResponse response -> handleSuccess(response.getCryptoUnits()))
.fetch();
...

//Crypto Rating/ Health Index
AlphaVantage.api()
.crypto()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'crazzyghost'
version '1.2.1'
version '1.3.0'

sourceCompatibility = 1.8

Expand Down
34 changes: 33 additions & 1 deletion src/main/java/com/crazzyghost/alphavantage/AlphaVantage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import com.crazzyghost.alphavantage.indicator.Indicator;
import com.crazzyghost.alphavantage.timeseries.TimeSeries;

/**
* Client interface of library. The API is accessed through this class. Exposes a singleton instance for interaction
* @since 1.0.0
* @author crazzyghost
*/
public class AlphaVantage {

private static AlphaVantage INSTANCE;
Expand All @@ -17,27 +22,42 @@ public class AlphaVantage {
private Indicator indicator;

private AlphaVantage(){

}

/**
* Initialize the client with a {@link Config} instance
* @param config
*/
public void init(Config config){
this.config = config;
}

/**
* Access the client interface
* @return Singleton instance of {@link AlphaVantage}
*/
public static AlphaVantage api(){
if(INSTANCE == null){
INSTANCE = new AlphaVantage();
}
return INSTANCE;
}

/**
* Access to Time Series Data. All requests associated with Stock Time Series is accessed through this method.
* @return A {@link TimeSeries} instance for access to Time Series Data
*/
public TimeSeries timeSeries(){
if(timeSeries == null){
timeSeries = new TimeSeries(config);
}
return timeSeries;
}

/**
* Access to Foreign Exchange Data. All requests associated with Foreing Exchange (FX) is accessed through this method.
* @return A {@link Forex} instance for access to FX data
*/
public Forex forex(){
if(forex == null){
forex = new Forex(config);
Expand All @@ -46,6 +66,10 @@ public Forex forex(){
}


/**
* Access to Digital/Physical Exchange Rates.
* @return An {@link ExchangeRate} instance for access to Exchange Rate Data
*/
public ExchangeRate exchangeRate() {
if(exchangeRate == null){
exchangeRate = new ExchangeRate(config);
Expand All @@ -54,13 +78,21 @@ public ExchangeRate exchangeRate() {
}


/**
* Access to Digital Currencies.
* @return A {@link Crypto} instance for access to Digital Currency Data
*/
public Crypto crypto(){
if(crypto == null){
crypto = new Crypto(config);
}
return crypto;
}

/**
* Access to Technical Indicators.
* @return A {@link Indicator} instance for access to Technical Indicator Data
*/
public Indicator indicator(){
if(indicator == null){
indicator = new Indicator(config);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.crazzyghost.alphavantage;

/**
* Exception class for the library
* @since 1.0.0
* @author crazzyghost
*/
public class AlphaVantageException extends RuntimeException{

public AlphaVantageException(){
Expand Down
44 changes: 43 additions & 1 deletion src/main/java/com/crazzyghost/alphavantage/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
* Allows you to set the library configuration parameters.
* @since 1.0.0
* @author crazzyghost
*/
public class Config {



private String key;
private int timeOut;
Expand All @@ -17,28 +23,50 @@ private Config(Builder builder) {
this.httpClient = builder.httpClient == null ? defaultClient(builder.timeOut): builder.httpClient;
}

/**
* @return the connection timeout value
*/
public int getTimeOut() {
return timeOut;
}


/**
* @return the API Key
*/
public String getKey() {
return key;
}

/**
* @return the HTTP client used to fetch data
*/
public OkHttpClient getOkHttpClient(){
return this.httpClient;
}

/**
* Get a builder instance
* @return {@link Builder}
*/
public static Builder builder(){
return new Builder();
}

/**
*
* @param timeOut connect timeout
* @return a default HTTP client for fetching data
*/
private OkHttpClient defaultClient(int timeOut){
return new OkHttpClient.Builder()
.connectTimeout(timeOut, TimeUnit.SECONDS)
.build();
}

/**
* Builder class for {@link Config}
*/
public static class Builder{
private String key;
private int timeOut;
Expand All @@ -49,16 +77,30 @@ public Builder key(String key){
return this;
}

/**
* Set the connect timeout of the HTTP client
* @param timeOut timeout for config
* @return the builder instance
*/
public Builder timeOut(int timeOut){
this.timeOut = timeOut;
return this;
}

/**
* Set the HTTP client
* @param httpClient the HTTP client for config
* @return
*/
public Builder httpClient(OkHttpClient httpClient){
this.httpClient = httpClient;
return this;
}

/**
* Build a new Configuration instance
* @return {@link Config} instance
*/
public Config build(){
return new Config(this);
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/crazzyghost/alphavantage/Fetcher.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
package com.crazzyghost.alphavantage;

/**
* Defines an interface for pulling data from the API source.
* A fetch operation can either fail or succeed
* @since 1.0.0
* @author crazzyghost
*/
public interface Fetcher{

/**
* Perform a fetch operation
*/
void fetch();

/**
* Callback when the fetch operation succeeds
* @param <V> the type of the reponse of the fetch operation
*/
interface SuccessCallback<V>{
/**
* Call this method with a response when the fetch operation is successful
* @param response response object
*/
void onSuccess(V response);
}

/**
* Callback when the fetch operation fails
*/
interface FailureCallback{
/**
* Call this method with an exception when the fetch operation fails
* @param ex exception
*/
void onFailure(AlphaVantageException ex);
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/crazzyghost/alphavantage/UrlExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@
import java.lang.reflect.Field;


/**
* Extracts a valid url from a request object. The request object should contain valid
* api endpoint parameters
* @since 1.0.0
* @author crazzyghost
*/
public class UrlExtractor{

private UrlExtractor(){

}

/**
* Get an API url from a request object
* @param object a request object with the valid API parameters
* @return valid API url
*/
public static String extract(Object object){

//url
StringBuilder stringBuilder = new StringBuilder();

Class<?> cls = object.getClass();
while(cls != null){
//access all fields in object
Field[] fields = cls.getDeclaredFields();
for(Field field : fields){
field.setAccessible(true);
try {
//extract non-null and non-synthetic fields
if (!field.isSynthetic() && field.get(object) != null){
stringBuilder.append(field.getName().toLowerCase())
.append("=");
Expand Down

0 comments on commit 7c81870

Please sign in to comment.