diff --git a/src/main/java/io/github/f4pl0/IEXCloudClient.java b/src/main/java/io/github/f4pl0/IEXCloudClient.java index 53ec146..f075802 100644 --- a/src/main/java/io/github/f4pl0/IEXCloudClient.java +++ b/src/main/java/io/github/f4pl0/IEXCloudClient.java @@ -1,5 +1,6 @@ package io.github.f4pl0; +import io.github.f4pl0.companydata.CompanyData; import io.github.f4pl0.config.ConfigInjector; import io.github.f4pl0.config.IEXCloudConfig; import io.github.f4pl0.equitiesmarketdata.EquitiesMarketData; @@ -12,6 +13,7 @@ public class IEXCloudClient { public final EquitiesMarketData equitiesMarketData; public final Reference reference; + public final CompanyData companyData; /** * Create a new IEXCloudClient. @@ -21,6 +23,7 @@ private IEXCloudClient(IEXCloudConfig config) { ConfigInjector.injectIEXConfiguration(IEXHttpClient.getInstance(), config); equitiesMarketData = new EquitiesMarketData(); reference = new Reference(); + companyData = new CompanyData(); } /** diff --git a/src/main/java/io/github/f4pl0/companydata/CompanyData.java b/src/main/java/io/github/f4pl0/companydata/CompanyData.java new file mode 100644 index 0000000..87f1fd3 --- /dev/null +++ b/src/main/java/io/github/f4pl0/companydata/CompanyData.java @@ -0,0 +1,190 @@ +package io.github.f4pl0.companydata; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.github.f4pl0.IEXHttpClient; +import io.github.f4pl0.companydata.data.IEXCompanyCeoCompensation; +import io.github.f4pl0.companydata.data.IEXCompanyData; +import io.github.f4pl0.companydata.data.IEXCompanyLogo; +import io.github.f4pl0.reference.data.IEXTradeDate; +import lombok.NonNull; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +public class CompanyData { + private final IEXHttpClient httpClient = IEXHttpClient.getInstance(); + private final ObjectMapper mapper = new ObjectMapper(); + + /** + * Company Information + * + *

Latest snapshot of public company information such as address, number of employees, CEO, and description.

+ * + * @see IEX Cloud API + * @param symbol Company symbol. + * @throws IOException If the request fails. + * @return A {@link io.github.f4pl0.companydata.data.IEXCompanyData} object. + */ + public IEXCompanyData companyData(@NonNull String symbol) throws IOException { + String encodedSymbol = URLEncoder.encode(symbol, StandardCharsets.UTF_8); + CloseableHttpResponse response = httpClient.execute("/data/core/company/" + encodedSymbol); + + List data = mapper.readValue( + EntityUtils.toString(response.getEntity()), + mapper.getTypeFactory().constructCollectionType(List.class, IEXCompanyData.class)); + + return data.get(0); + } + + /** + * Company Information + * + *

Latest snapshot of public company information such as address, number of employees, CEO, and description.

+ * + * @see IEX Cloud API + * @param symbols Company symbols. + * @throws IOException If the request fails. + * @return A List of {@link io.github.f4pl0.companydata.data.IEXCompanyData} objects. + */ + public List companyData(@NonNull String[] symbols) throws IOException { + List encodedSymbols = new ArrayList<>(symbols.length); + for (String symbol : symbols) { + encodedSymbols.add(URLEncoder.encode(symbol, StandardCharsets.UTF_8)); + } + String joinedSymbols = String.join(",", encodedSymbols); + CloseableHttpResponse response = httpClient.execute("/data/core/company/" + joinedSymbols); + + return mapper.readValue( + EntityUtils.toString(response.getEntity()), + mapper.getTypeFactory().constructCollectionType(List.class, IEXCompanyData.class)); + } + + /** + * Historical Company Snapshots + * + *

Historical daily snapshot of public company information such as address, number of employees, CEO, and description.

+ * + * @see IEX Cloud API + * @param symbol Company symbol. + * @throws IOException If the request fails. + * @return A List of {@link io.github.f4pl0.companydata.data.IEXCompanyData} objects. + */ + public List companyDataSnapshots(@NonNull String symbol) throws IOException { + String encodedSymbol = URLEncoder.encode(symbol, StandardCharsets.UTF_8); + CloseableHttpResponse response = httpClient.execute("/data/core/company_historical/" + encodedSymbol); + + return mapper.readValue( + EntityUtils.toString(response.getEntity()), + mapper.getTypeFactory().constructCollectionType(List.class, IEXCompanyData.class)); + } + + /** + * Historical Company Snapshots + * + *

Historical daily snapshot of public company information such as address, number of employees, CEO, and description.

+ * + * @see IEX Cloud API + * @param symbol Company symbol. + * @param last Number of records to return. + * @throws IOException If the request fails. + * @return A List of {@link io.github.f4pl0.companydata.data.IEXCompanyData} objects. + */ + public List companyDataSnapshots(@NonNull String symbol, int last) throws IOException { + String encodedSymbol = URLEncoder.encode(symbol, StandardCharsets.UTF_8); + CloseableHttpResponse response = httpClient.execute( + "/data/core/company_historical/" + encodedSymbol + "?last=" + last + ); + + return mapper.readValue( + EntityUtils.toString(response.getEntity()), + mapper.getTypeFactory().constructCollectionType(List.class, IEXCompanyData.class)); + } + + /** + * Historical Company Snapshots + * + *

Historical daily snapshot of public company information such as address, number of employees, CEO, and description.

+ * + * @see IEX Cloud API + * @param symbols Company symbols. + * @throws IOException If the request fails. + * @return A List of {@link io.github.f4pl0.companydata.data.IEXCompanyData} objects. + */ + public List companyDataSnapshots(@NonNull String[] symbols) throws IOException { + List encodedSymbols = new ArrayList<>(symbols.length); + for (String symbol : symbols) { + encodedSymbols.add(URLEncoder.encode(symbol, StandardCharsets.UTF_8)); + } + String joinedSymbols = String.join(",", encodedSymbols); + CloseableHttpResponse response = httpClient.execute("/data/core/company_historical/" + joinedSymbols); + + return mapper.readValue( + EntityUtils.toString(response.getEntity()), + mapper.getTypeFactory().constructCollectionType(List.class, IEXCompanyData.class)); + } + + /** + * Historical Company Snapshots + * + *

Historical daily snapshot of public company information such as address, number of employees, CEO, and description.

+ * + * @see IEX Cloud API + * @param symbols Company symbols. + * @param last Number of records to return. + * @throws IOException If the request fails. + * @return A List of {@link io.github.f4pl0.companydata.data.IEXCompanyData} objects. + */ + public List companyDataSnapshots(@NonNull String[] symbols, int last) throws IOException { + List encodedSymbols = new ArrayList<>(symbols.length); + for (String symbol : symbols) { + encodedSymbols.add(URLEncoder.encode(symbol, StandardCharsets.UTF_8)); + } + String joinedSymbols = String.join(",", encodedSymbols); + CloseableHttpResponse response = httpClient.execute( + "/data/core/company_historical/" + joinedSymbols + "?last=" + last + ); + + return mapper.readValue( + EntityUtils.toString(response.getEntity()), + mapper.getTypeFactory().constructCollectionType(List.class, IEXCompanyData.class)); + } + + /** + * CEO Compensation + * + *

Returns the latest compensation information for the CEO of the company matching the symbol.

+ * + * @see IEX Cloud API + * @param symbol Company symbol. + * @throws IOException If the request fails. + * @return A {@link io.github.f4pl0.companydata.data.IEXCompanyCeoCompensation} object. + */ + public IEXCompanyCeoCompensation companyCeoCompensation(@NonNull String symbol) throws IOException { + String encodedSymbol = URLEncoder.encode(symbol, StandardCharsets.UTF_8); + CloseableHttpResponse response = httpClient.execute("/stock/" + encodedSymbol + "/ceo-compensation"); + + return mapper.readValue(EntityUtils.toString(response.getEntity()), IEXCompanyCeoCompensation.class); + } + + /** + * Company Logo + * + *

Returns a logo (if available) for the company.

+ * + * @see IEX Cloud API + * @param symbol Company symbol. + * @throws IOException If the request fails. + * @return A {@link io.github.f4pl0.companydata.data.IEXCompanyLogo} object. + */ + public IEXCompanyLogo companyLogo(@NonNull String symbol) throws IOException { + String encodedSymbol = URLEncoder.encode(symbol, StandardCharsets.UTF_8); + CloseableHttpResponse response = httpClient.execute("/stock/" + encodedSymbol + "/logo"); + + return mapper.readValue(EntityUtils.toString(response.getEntity()), IEXCompanyLogo.class); + } +} diff --git a/src/main/java/io/github/f4pl0/companydata/data/IEXCompanyCeoCompensation.java b/src/main/java/io/github/f4pl0/companydata/data/IEXCompanyCeoCompensation.java new file mode 100644 index 0000000..8372bd1 --- /dev/null +++ b/src/main/java/io/github/f4pl0/companydata/data/IEXCompanyCeoCompensation.java @@ -0,0 +1,24 @@ +package io.github.f4pl0.companydata.data; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class IEXCompanyCeoCompensation { + private String symbol; + private String name; + private String companyName; + private String location; + private long salary; + private long bonus; + private long stockAwards; + private long optionAwards; + private long nonEquityIncentives; + private long pensionAndDeferred; + private long otherComp; + private long total; + private String year; +} diff --git a/src/main/java/io/github/f4pl0/companydata/data/IEXCompanyData.java b/src/main/java/io/github/f4pl0/companydata/data/IEXCompanyData.java new file mode 100644 index 0000000..5050e8e --- /dev/null +++ b/src/main/java/io/github/f4pl0/companydata/data/IEXCompanyData.java @@ -0,0 +1,43 @@ +package io.github.f4pl0.companydata.data; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class IEXCompanyData { + private String address; + private String address2; + private String ceo; + private String city; + private String companyName; + private String country; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + private Date date; + private int employees; + private String exchange; + private String exchangeCode; + private String industry; + private String issuetype; + private String longDescription; + private long marketcap; + private String phone; + private String primarySicCode; + private String sector; + private String securityName; + private String securityType; + private String shortDescription; + private String state; + private String symbol; + private String website; + private String zip; + private String id; + private String key; + private String subkey; + private long updated; +} diff --git a/src/main/java/io/github/f4pl0/companydata/data/IEXCompanyLogo.java b/src/main/java/io/github/f4pl0/companydata/data/IEXCompanyLogo.java new file mode 100644 index 0000000..1d570c3 --- /dev/null +++ b/src/main/java/io/github/f4pl0/companydata/data/IEXCompanyLogo.java @@ -0,0 +1,12 @@ +package io.github.f4pl0.companydata.data; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class IEXCompanyLogo { + private String url; +}