This repository has been archived by the owner on Aug 31, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
src/main/java/io/github/f4pl0/companydata/CompanyData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
* | ||
* <p>Latest snapshot of public company information such as address, number of employees, CEO, and description.</p> | ||
* | ||
* @see <a href="https://iexcloud.io/docs/core/COMPANY#company-information">IEX Cloud API</a> | ||
* @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<IEXCompanyData> data = mapper.readValue( | ||
EntityUtils.toString(response.getEntity()), | ||
mapper.getTypeFactory().constructCollectionType(List.class, IEXCompanyData.class)); | ||
|
||
return data.get(0); | ||
} | ||
|
||
/** | ||
* Company Information | ||
* | ||
* <p>Latest snapshot of public company information such as address, number of employees, CEO, and description.</p> | ||
* | ||
* @see <a href="https://iexcloud.io/docs/core/COMPANY#company-information">IEX Cloud API</a> | ||
* @param symbols Company symbols. | ||
* @throws IOException If the request fails. | ||
* @return A List of {@link io.github.f4pl0.companydata.data.IEXCompanyData} objects. | ||
*/ | ||
public List<IEXCompanyData> companyData(@NonNull String[] symbols) throws IOException { | ||
List<String> 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 | ||
* | ||
* <p>Historical daily snapshot of public company information such as address, number of employees, CEO, and description.</p> | ||
* | ||
* @see <a href="https://iexcloud.io/docs/core/COMPANY_HISTORICAL#historical-company-snapshots">IEX Cloud API</a> | ||
* @param symbol Company symbol. | ||
* @throws IOException If the request fails. | ||
* @return A List of {@link io.github.f4pl0.companydata.data.IEXCompanyData} objects. | ||
*/ | ||
public List<IEXCompanyData> 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 | ||
* | ||
* <p>Historical daily snapshot of public company information such as address, number of employees, CEO, and description.</p> | ||
* | ||
* @see <a href="https://iexcloud.io/docs/core/COMPANY_HISTORICAL#historical-company-snapshots">IEX Cloud API</a> | ||
* @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<IEXCompanyData> 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 | ||
* | ||
* <p>Historical daily snapshot of public company information such as address, number of employees, CEO, and description.</p> | ||
* | ||
* @see <a href="https://iexcloud.io/docs/core/COMPANY_HISTORICAL#historical-company-snapshots">IEX Cloud API</a> | ||
* @param symbols Company symbols. | ||
* @throws IOException If the request fails. | ||
* @return A List of {@link io.github.f4pl0.companydata.data.IEXCompanyData} objects. | ||
*/ | ||
public List<IEXCompanyData> companyDataSnapshots(@NonNull String[] symbols) throws IOException { | ||
List<String> 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 | ||
* | ||
* <p>Historical daily snapshot of public company information such as address, number of employees, CEO, and description.</p> | ||
* | ||
* @see <a href="https://iexcloud.io/docs/core/COMPANY_HISTORICAL#historical-company-snapshots">IEX Cloud API</a> | ||
* @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<IEXCompanyData> companyDataSnapshots(@NonNull String[] symbols, int last) throws IOException { | ||
List<String> 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 | ||
* | ||
* <p>Returns the latest compensation information for the CEO of the company matching the symbol.</p> | ||
* | ||
* @see <a href="https://iexcloud.io/docs/core/ceo-compensation#ceo-compensation">IEX Cloud API</a> | ||
* @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 | ||
* | ||
* <p>Returns a logo (if available) for the company.</p> | ||
* | ||
* @see <a href="https://iexcloud.io/docs/core/company-logo#company-logo">IEX Cloud API</a> | ||
* @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); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/io/github/f4pl0/companydata/data/IEXCompanyCeoCompensation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/io/github/f4pl0/companydata/data/IEXCompanyData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/io/github/f4pl0/companydata/data/IEXCompanyLogo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |