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:

NameTypeScheme
apiKeyAuthapiKeyAPI 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

analystInsights()

  • get - Get Analyst Insights V1

analystReportsRawText()

  • get - Get Analyst Reports Raw Text Data

bars()

  • get - Get Bars V2

bullsBearsSayBearsSay()

  • get - Get Bulls Say Bears Say V1

conferenceCalls()

  • get - Get Conference Calls

consensusRatings()

  • get - Get Consensus Ratings

derivedFiguresAndRatios()

  • get - Get derived figures and ratios V3

dividends()

  • getV22 - Get Dividends V2.2
  • get - Get Dividends V2 & V2.1

earningRatios()

  • get - Get earning ratios V2.1

earnings()

  • get - Get Earnings

earningsCallTranscripts()

  • get - Get Earnings Call Transcripts
  • getAudio - Get Earnings Call Transcript Audio Files

economics()

  • get - Get Economics

events()

  • get - Get Events

fda()

  • get - Get FDA

fundamentals()

governmentTradeReports()

  • get - Get Government Trade Reports

governmentTrades()

  • get - Get Government Trades

guidance()

  • get - Get Guidance

insiderTransaction()

  • get - Get Insider Transaction

insiderTransactions()

  • getOwner - Get Insider Transaction Owner

ipos()

logos()

  • bulkSync - Get Logos for given search keys
  • search - Get Logos for given search keys

ma()

  • get - Get Merger and Acquisition

news()

newsquantified()

  • get - Get Newsquantified Data

offerings()

  • get - Get Offerings

operationRatios()

  • get - Get operation ratios V2.1

optionActivity()

  • get - Get OptionActivity V1

quotedelayed()

  • getV1 - Get delayed quotes V1

quoteDelayed()

  • get - Get delayed quotes V2

ratings()

  • get - Get Ratings

ratingsAnalysts()

  • get - Get Ratings Analysts

ratingsFirms()

  • get - Get Ratings Firms

removed()

  • get - Get Removed (v2)

splits()

  • get - Get Splits

tickerTrends()

  • get - Get ticker trend data
  • getList - Get ticker trend list data

valuationRatios()

  • 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 TypeStatus CodeContent Type
models/errors/ApiErrorResponse400, 500application/json
models/errors/APIException4XX, 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
0https://api.benzinga.com
1https://api.benzinga.com/api/v1
2https://api.benzinga.com/api/v2
3https://api.benzinga.com/api/v2.1
4https://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.

SDK Created by Speakeasy

Was this page helpful?