Documentation Index
Fetch the complete documentation index at: https://docs.benzinga.com/llms.txt
Use this file to discover all available pages before exploring further.
BZ-Java-Client
Developer-friendly & type-safe Java SDK specifically catered to leverage openapi API.
Summary
Benzinga APIs: This REST API provides endpoints to all Benzinga APIs.
Table of Contents
SDK Installation
Getting started
JDK 11 or later is required.
The samples below show how a published SDK artifact is used:
Gradle:
implementation 'org.benzinga:BZClient:0.2.7'
Maven:
<dependency>
<groupId>org.benzinga</groupId>
<artifactId>BZClient</artifactId>
<version>0.2.7</version>
</dependency>
How to build
After cloning the git repository to your file system you can build the SDK artifact from source to the build directory by running ./gradlew build on *nix systems or gradlew.bat on Windows systems.
If you wish to build from source and publish the SDK artifact to your local Maven repository (on your filesystem) then use the following command (after cloning the git repo locally):
On *nix:
./gradlew publishToMavenLocal -Pskip.signing
On Windows:
gradlew.bat publishToMavenLocal -Pskip.signing
SDK Example Usage
Example
package hello.world;
import java.lang.Exception;
import org.benzinga.BZClient.Bzclient;
import org.benzinga.BZClient.models.operations.GetAnalystReportsRawTextDataResponse;
public class Application {
public static void main(String[] args) throws Exception {
Bzclient sdk = Bzclient.builder()
.apiKeyAuth("<YOUR_API_KEY_HERE>")
.build();
GetAnalystReportsRawTextDataResponse res = sdk.analystReportsRawText().get()
.page(700347L)
.pagesize(558834L)
.call();
if (res.modelsAnalystReportRawTexts().isPresent()) {
// handle response
}
}
}
Authentication
Per-Client Security Schemes
This SDK supports the following security scheme globally:
| Name | Type | Scheme |
|---|
apiKeyAuth | apiKey | API key |
To authenticate with the API the apiKeyAuth parameter must be set when initializing the SDK client instance. For example:
package hello.world;
import java.lang.Exception;
import org.benzinga.BZClient.Bzclient;
import org.benzinga.BZClient.models.operations.GetAnalystReportsRawTextDataResponse;
public class Application {
public static void main(String[] args) throws Exception {
Bzclient sdk = Bzclient.builder()
.apiKeyAuth("<YOUR_API_KEY_HERE>")
.build();
GetAnalystReportsRawTextDataResponse res = sdk.analystReportsRawText().get()
.page(700347L)
.pagesize(558834L)
.call();
if (res.modelsAnalystReportRawTexts().isPresent()) {
// handle response
}
}
}
Available Resources and Operations
- get - Get Analyst Insights V1
- get - Get Analyst Reports Raw Text Data
- get - Get Bulls Say Bears Say V1
- get - Get Conference Calls
- get - Get Consensus Ratings
- get - Get derived figures and ratios V3
- getV22 - Get Dividends V2.2
- get - Get Dividends V2 & V2.1
- get - Get earning ratios V2.1
- get - Get Earnings Call Transcripts
- getAudio - Get Earnings Call Transcript Audio Files
- get - Get Government Trade Reports
- get - Get Government Trades
- get - Get Insider Transaction
- getOwner - Get Insider Transaction Owner
- bulkSync - Get Logos for given search keys
- search - Get Logos for given search keys
- get - Get Merger and Acquisition
- get - Get Newsquantified Data
- get - Get operation ratios V2.1
- get - Get OptionActivity V1
- getV1 - Get delayed quotes V1
- get - Get delayed quotes V2
- get - Get Ratings Analysts
- get - Get ticker trend data
- getList - Get ticker trend list data
- get - Get valuation ratios V2.1
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, you can provide a RetryConfig object through the retryConfig builder method:
package hello.world;
import java.lang.Exception;
import java.util.concurrent.TimeUnit;
import org.benzinga.BZClient.Bzclient;
import org.benzinga.BZClient.models.operations.GetAnalystReportsRawTextDataResponse;
import org.benzinga.BZClient.utils.BackoffStrategy;
import org.benzinga.BZClient.utils.RetryConfig;
public class Application {
public static void main(String[] args) throws Exception {
Bzclient sdk = Bzclient.builder()
.apiKeyAuth("<YOUR_API_KEY_HERE>")
.build();
GetAnalystReportsRawTextDataResponse res = sdk.analystReportsRawText().get()
.retryConfig(RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(1L, TimeUnit.MILLISECONDS)
.maxInterval(50L, TimeUnit.MILLISECONDS)
.maxElapsedTime(1000L, TimeUnit.MILLISECONDS)
.baseFactor(1.1)
.jitterFactor(0.15)
.retryConnectError(false)
.build())
.build())
.page(700347L)
.pagesize(558834L)
.call();
if (res.modelsAnalystReportRawTexts().isPresent()) {
// handle response
}
}
}
If you’d like to override the default retry strategy for all operations that support retries, you can provide a configuration at SDK initialization:
package hello.world;
import java.lang.Exception;
import java.util.concurrent.TimeUnit;
import org.benzinga.BZClient.Bzclient;
import org.benzinga.BZClient.models.operations.GetAnalystReportsRawTextDataResponse;
import org.benzinga.BZClient.utils.BackoffStrategy;
import org.benzinga.BZClient.utils.RetryConfig;
public class Application {
public static void main(String[] args) throws Exception {
Bzclient sdk = Bzclient.builder()
.retryConfig(RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(1L, TimeUnit.MILLISECONDS)
.maxInterval(50L, TimeUnit.MILLISECONDS)
.maxElapsedTime(1000L, TimeUnit.MILLISECONDS)
.baseFactor(1.1)
.jitterFactor(0.15)
.retryConnectError(false)
.build())
.build())
.apiKeyAuth("<YOUR_API_KEY_HERE>")
.build();
GetAnalystReportsRawTextDataResponse res = sdk.analystReportsRawText().get()
.page(700347L)
.pagesize(558834L)
.call();
if (res.modelsAnalystReportRawTexts().isPresent()) {
// handle response
}
}
}
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.
By default, an API error will throw a models/errors/APIException exception. When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the get method throws the following exceptions:
| Error Type | Status Code | Content Type |
|---|
| models/errors/ApiErrorResponse | 400, 500 | application/json |
| models/errors/APIException | 4XX, 5XX | */* |
Example
package hello.world;
import java.lang.Exception;
import org.benzinga.BZClient.Bzclient;
import org.benzinga.BZClient.models.errors.ApiErrorResponse;
import org.benzinga.BZClient.models.operations.GetAnalystInsightsV1Request;
import org.benzinga.BZClient.models.operations.GetAnalystInsightsV1Response;
public class Application {
public static void main(String[] args) throws ApiErrorResponse, Exception {
Bzclient sdk = Bzclient.builder()
.apiKeyAuth("<YOUR_API_KEY_HERE>")
.build();
GetAnalystInsightsV1Request req = GetAnalystInsightsV1Request.builder()
.build();
GetAnalystInsightsV1Response res = sdk.analystInsights().get()
.request(req)
.call();
if (res.modelsAnalystInsightsJSON().isPresent()) {
// handle response
}
}
}
Server Selection
Select Server by Index
You can override the default server globally using the .serverIndex(int serverIdx) builder method when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
| # | Server |
|---|
| 0 | https://api.benzinga.com |
| 1 | https://api.benzinga.com/api/v1 |
| 2 | https://api.benzinga.com/api/v2 |
| 3 | https://api.benzinga.com/api/v2.1 |
| 4 | https://api.benzinga.com/api/v2.2 |
Example
package hello.world;
import java.lang.Exception;
import org.benzinga.BZClient.Bzclient;
import org.benzinga.BZClient.models.operations.GetAnalystReportsRawTextDataResponse;
public class Application {
public static void main(String[] args) throws Exception {
Bzclient sdk = Bzclient.builder()
.serverIndex(4)
.apiKeyAuth("<YOUR_API_KEY_HERE>")
.build();
GetAnalystReportsRawTextDataResponse res = sdk.analystReportsRawText().get()
.page(700347L)
.pagesize(558834L)
.call();
if (res.modelsAnalystReportRawTexts().isPresent()) {
// handle response
}
}
}
Override Server URL Per-Client
The default server can also be overridden globally using the .serverURL(String serverUrl) builder method when initializing the SDK client instance. For example:
package hello.world;
import java.lang.Exception;
import org.benzinga.BZClient.Bzclient;
import org.benzinga.BZClient.models.operations.GetAnalystReportsRawTextDataResponse;
public class Application {
public static void main(String[] args) throws Exception {
Bzclient sdk = Bzclient.builder()
.serverURL("https://api.benzinga.com")
.apiKeyAuth("<YOUR_API_KEY_HERE>")
.build();
GetAnalystReportsRawTextDataResponse res = sdk.analystReportsRawText().get()
.page(700347L)
.pagesize(558834L)
.call();
if (res.modelsAnalystReportRawTexts().isPresent()) {
// handle response
}
}
}
Development
Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
looking for the latest version.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we’ll do our best to include it in a future release.