Developer-friendly & type-safe Java SDK specifically catered to leverage openapi API.
Important
This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your workspace. Delete this section before > publishing to a package manager.
Benzinga APIs: This REST API provides endpoints to all Benzinga APIs.
JDK 11 or later is required.
The samples below show how a published SDK artifact is used:
Gradle:
implementation 'com.benzinga:bzclient:0.3.7'
Maven:
<dependency>
<groupId>com.benzinga</groupId>
<artifactId>bzclient</artifactId>
<version>0.3.7</version>
</dependency>
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
package hello.world;
import com.benzinga.bzclient.Bzclient;
import com.benzinga.bzclient.models.operations.GetAnalystReportsRawTextDataResponse;
import java.lang.Exception;
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
}
}
}
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 com.benzinga.bzclient.Bzclient;
import com.benzinga.bzclient.models.operations.GetAnalystReportsRawTextDataResponse;
import java.lang.Exception;
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 methods
- get - Get Analyst Insights V1
- get - Get Analyst Reports Raw Text Data
- get - Get Bars V2
- get - Get Bulls Say Bears Say V1
- get - Get Conference Calls
- get - Get Consensus Ratings
- get - Get derived figures and ratios V3
- get - Get earning ratios V2.1
- get - Get Earnings
- get - Get Economics
- get - Get Events
- get - Get FDA
- getV21 - Get Fundamentals V2.1
- getAlphaBeta - Get Alpha Beta V2.1
- getCompanyV21 - Get Company Data v2.1
- getCompanyProfileV21 - Get Company Profile v2.1
- getShareClass - Get Share Class V2.1
- getShareClassProfile - Get Share Class Profile V2.1
- get - Get Fundamentals V2
- getAssetClassification - Get Asset Classification V2.1
- getEarningsReports - Get Earnings Reports V2.1
- getFinancialsV21 - Get Financials V2.1
- getV3 - Get Fundamentals V3
- getBalanceSheetV3 - Get Balance Sheet V3
- getCashFlowV3 - Get Cash Flow V3
- getIncomeStatement - Get Income Statement V3
- getSharePriceRatios - Get Share Price Ratios V3
- get - Get Government Trade Reports
- get - Get Government Trades
- get - Get Guidance
- get - Get Insider Transaction
- getOwner - Get Insider Transaction Owner
- get - Get Merger and Acquisition
- get - Get News
- getRemoved - Get Removed News
- get - Get Newsquantified Data
- get - Get Offerings
- get - Get operation ratios V2.1
- get - Get OptionActivity V1
- getV1 - Get delayed quotes V1
- get - Get delayed quotes V2
- get - Get Ratings
- get - Get Ratings Analysts
- get - Get Ratings Firms
- get - Get Removed (v2)
- get - Get Splits
- get - Get valuation ratios V2.1
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 com.benzinga.bzclient.Bzclient;
import com.benzinga.bzclient.models.operations.GetAnalystReportsRawTextDataResponse;
import com.benzinga.bzclient.utils.BackoffStrategy;
import com.benzinga.bzclient.utils.RetryConfig;
import java.lang.Exception;
import java.util.concurrent.TimeUnit;
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 com.benzinga.bzclient.Bzclient;
import com.benzinga.bzclient.models.operations.GetAnalystReportsRawTextDataResponse;
import com.benzinga.bzclient.utils.BackoffStrategy;
import com.benzinga.bzclient.utils.RetryConfig;
import java.lang.Exception;
import java.util.concurrent.TimeUnit;
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
}
}
}
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 | */* |
package hello.world;
import com.benzinga.bzclient.Bzclient;
import com.benzinga.bzclient.models.errors.ApiErrorResponse;
import com.benzinga.bzclient.models.operations.GetAnalystInsightsV1Request;
import com.benzinga.bzclient.models.operations.GetAnalystInsightsV1Response;
import java.lang.Exception;
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
}
}
}
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 |
package hello.world;
import com.benzinga.bzclient.Bzclient;
import com.benzinga.bzclient.models.operations.GetAnalystReportsRawTextDataResponse;
import java.lang.Exception;
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
}
}
}
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 com.benzinga.bzclient.Bzclient;
import com.benzinga.bzclient.models.operations.GetAnalystReportsRawTextDataResponse;
import java.lang.Exception;
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
}
}
}
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.
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.