Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
add: company data endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
F4pl0 committed Nov 4, 2023
1 parent 6379d58 commit 83cd4c6
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/io/github/f4pl0/IEXCloudClient.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +13,7 @@
public class IEXCloudClient {
public final EquitiesMarketData equitiesMarketData;
public final Reference reference;
public final CompanyData companyData;

/**
* Create a new IEXCloudClient.
Expand All @@ -21,6 +23,7 @@ private IEXCloudClient(IEXCloudConfig config) {
ConfigInjector.injectIEXConfiguration(IEXHttpClient.getInstance(), config);
equitiesMarketData = new EquitiesMarketData();
reference = new Reference();
companyData = new CompanyData();
}

/**
Expand Down
190 changes: 190 additions & 0 deletions src/main/java/io/github/f4pl0/companydata/CompanyData.java
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);
}
}
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 src/main/java/io/github/f4pl0/companydata/data/IEXCompanyData.java
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 src/main/java/io/github/f4pl0/companydata/data/IEXCompanyLogo.java
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;
}

0 comments on commit 83cd4c6

Please sign in to comment.