diff --git a/src/main/java/nl/capite/tiingo4j/abstracts/AbstractApi.java b/src/main/java/nl/capite/tiingo4j/abstracts/AbstractApi.java index 8517aeb..cf0f4c5 100644 --- a/src/main/java/nl/capite/tiingo4j/abstracts/AbstractApi.java +++ b/src/main/java/nl/capite/tiingo4j/abstracts/AbstractApi.java @@ -92,38 +92,4 @@ protected String csvString(List strings) { return sb.toString(); } - - - protected List getCryptoTopOfTheBook(List tickers, CryptoTopOfTheBookParameters parameters) throws IOException, ApiException { - final String url = "https://api.tiingo.com/tiingo/crypto/top"; - - - - if(tickers==null) { - throw new NullPointerException("tickers parameters cannot be null."); - } - if(tickers.size()==0) { - throw new NullPointerException("tickers list must include at least one ticker."); - } - - HashMap params = new HashMap<>(); - if(parameters!=null) { - params = parameters.getMap(); - } - - String tickerStringList = csvString(tickers); - params.put("tickers",tickerStringList); - - Request request = createRequestFromMap(url,params); - - Response response = client.newCall(request).execute(); - String body = response.body().string(); - if(!isStatus2XX(response.code())) { - throw parseError(body,null); - } - - CryptoTopOfTheBook[] data = mapper.readValue(body,CryptoTopOfTheBook[].class); - return data==null ? new ArrayList<>():Arrays.asList(data); - } - } diff --git a/src/main/java/nl/capite/tiingo4j/apis/CryptoApi.java b/src/main/java/nl/capite/tiingo4j/apis/CryptoApi.java new file mode 100644 index 0000000..66a808a --- /dev/null +++ b/src/main/java/nl/capite/tiingo4j/apis/CryptoApi.java @@ -0,0 +1,53 @@ +package nl.capite.tiingo4j.apis; + +import nl.capite.tiingo4j.abstracts.AbstractApi; +import nl.capite.tiingo4j.exceptions.ApiException; +import nl.capite.tiingo4j.models.CryptoTopOfTheBook; +import nl.capite.tiingo4j.requestParameters.CryptoTopOfTheBookParameters; +import okhttp3.Request; +import okhttp3.Response; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +public class CryptoApi extends AbstractApi { + + public CryptoApi(String apiKey) { + super(apiKey); + } + + public List getCryptoTopOfTheBook(List tickers, CryptoTopOfTheBookParameters parameters) throws IOException, ApiException { + final String url = "https://api.tiingo.com/tiingo/crypto/top"; + + + + if(tickers==null) { + throw new NullPointerException("tickers parameters cannot be null."); + } + if(tickers.size()==0) { + throw new NullPointerException("tickers list must include at least one ticker."); + } + + HashMap params = new HashMap<>(); + if(parameters!=null) { + params = parameters.getMap(); + } + + String tickerStringList = csvString(tickers); + params.put("tickers",tickerStringList); + + Request request = createRequestFromMap(url,params); + + Response response = client.newCall(request).execute(); + String body = response.body().string(); + if(!isStatus2XX(response.code())) { + throw parseError(body,null); + } + + CryptoTopOfTheBook[] data = mapper.readValue(body,CryptoTopOfTheBook[].class); + return data==null ? new ArrayList<>(): Arrays.asList(data); + } +} diff --git a/src/main/java/nl/capite/tiingo4j/apis/TiingoApi.java b/src/main/java/nl/capite/tiingo4j/apis/TiingoApi.java index bd26411..c810d15 100644 --- a/src/main/java/nl/capite/tiingo4j/apis/TiingoApi.java +++ b/src/main/java/nl/capite/tiingo4j/apis/TiingoApi.java @@ -15,11 +15,13 @@ public class TiingoApi extends AbstractApi { private final StockApi stockApi; private final NewsApi newsApi; + private final CryptoApi cryptoApi; public TiingoApi(String apiKey) { super(apiKey); stockApi = new StockApi(apiKey); newsApi = new NewsApi(apiKey); + cryptoApi = new CryptoApi(apiKey); } public Optional getMeta(String ticker) throws IOException, ApiException { @@ -35,7 +37,7 @@ public List
getNews(NewsParameters parameters) throws IOException, ApiE } public List getCryptoTopOfTheBook(List tickers, CryptoTopOfTheBookParameters parameters) throws IOException, ApiException { - return super.getCryptoTopOfTheBook(tickers,parameters); + return cryptoApi.getCryptoTopOfTheBook(tickers,parameters); } }