メインコンテンツへスキップ

BZ-Java-Client

開発者フレンドリーで型安全な Java SDK であり、openapi API を活用するために特化して設計されています。
Speakeasy 製MIT ライセンス

概要

Benzinga API 群:この REST API は、Benzinga のすべての API へのエンドポイントを提供します。

目次

SDKのインストール

はじめに

JDK 11 以降が必要です。 以下のサンプルコードでは、公開済み SDK アーティファクトの利用方法を示します。 Gradle:
implementation 'org.benzinga:BZClient:0.2.7'
Maven:
<dependency>
    <groupId>org.benzinga</groupId>
    <artifactId>BZClient</artifactId>
    <version>0.2.7</version>
</dependency>

ビルド方法

git リポジトリをファイルシステムにクローンした後、*nix システムでは ./gradlew build、Windows システムでは gradlew.bat を実行することで、ソースコードから SDK アーティファクトを build ディレクトリにビルドできます。 ソースコードからビルドし、SDK アーティファクトをローカルの Maven リポジトリ(ファイルシステム上)に公開したい場合は、(git リポジトリをローカルにクローンした後で)次のコマンドを使用します。 *nix の場合:
./gradlew publishToMavenLocal -Pskip.signing
Windows の場合:
gradlew.bat publishToMavenLocal -Pskip.signing

SDK 使用例

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()) {
            // レスポンスを処理する
        }
    }
}

認証

クライアントごとのセキュリティスキーム

このSDKでは、グローバルに次のセキュリティスキームをサポートしています。
NameTypeScheme
apiKeyAuthapiKeyAPI key
APIで認証を行うには、SDKクライアントインスタンスを初期化する際に apiKeyAuth パラメータを設定する必要があります。たとえば、次のように指定します。
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()) {
            // レスポンスを処理する
        }
    }
}

利用可能なリソースと操作

  • get - アナリストインサイト V1 の取得
  • get - アナリストレポートの生テキストデータを取得する
  • get - Bars v2 を取得
  • 取得 - Bulls Say Bears Say V1 データを取得
  • get - カンファレンスコールを取得
  • get - コンセンサスレーティングを取得
  • get - 派生指標および比率 v3 を取得
  • getV22 - 配当データ V2.2 を取得
  • get - 配当データ V2 および V2.1 を取得
  • get - earning ratios v2.1 を取得
  • get - 決算情報を取得
  • get - 決算説明会の書き起こしを取得
  • getAudio - 決算説明会の書き起こし音声ファイルを取得
  • get - 経済データの取得
  • get - イベントの取得
  • get - FDA データを取得
  • get - 政府取引レポートを取得
  • get - 政府取引データを取得
  • get - Guidance を取得
  • get - インサイダー取引情報を取得
  • getOwner - インサイダー取引のオーナー情報を取得
  • getV21 - IPOs v2.1 データを取得
  • get - IPOs v2 データを取得
  • bulkSync - 指定した検索キーのロゴを取得
  • search - 指定した検索キーのロゴを取得
  • get - M&A データを取得
  • get - ニュースを取得
  • getRemoved - 削除されたニュースを取得
  • 取得 - Newsquantified データの取得
  • get - オファリングを取得
  • get - operation ratios V2.1 を取得
  • get - OptionActivity V1 を取得

quotedelayed()

  • getV1 - 遅延クォート V1 の取得
  • get - 遅延クォート V2 を取得
  • get - 評価を取得
  • get - レーティングアナリスト情報を取得
  • get - レーティング機関を取得
  • get - 削除された銘柄を取得 (v2)
  • get - Splits を取得
  • get - ティッカーのトレンドデータを取得
  • getList - ティッカーのトレンドリストデータを取得
  • get - バリュエーション指標を取得 V2.1

リトライ

この SDK の一部のエンドポイントはリトライをサポートしています。SDK を特に設定せずに使用した場合は、API が提供するデフォルトのリトライ戦略が使用されます。ただし、このデフォルトのリトライ戦略は、各操作ごと、または SDK 全体に対して上書きできます。 特定の API 呼び出しに対するデフォルトのリトライ戦略を変更するには、retryConfig ビルダーメソッドを通じて RetryConfig オブジェクトを指定します。
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()) {
            // レスポンスを処理する
        }
    }
}
リトライに対応しているすべての処理に対して既定のリトライ戦略を上書きする場合は、SDK の初期化時に構成を指定できます。
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()) {
            // レスポンスを処理
        }
    }
}

エラー処理

この SDK におけるエラー処理は、概ね想定どおりのものです。すべての操作はレスポンスオブジェクトを返すか、例外をスローします。 デフォルトでは、API エラーは models/errors/APIException 例外をスローします。操作に対してカスタムエラーレスポンスが指定されている場合、SDK はそれに対応する専用の例外をスローする場合もあります。各操作ごとの発生しうる例外タイプの詳細については、SDK ドキュメント内の該当する エラー テーブルを参照してください。たとえば、get メソッドは以下の例外をスローします。
エラータイプステータスコードContent-Type
models/errors/ApiErrorResponse400, 500application/json
models/errors/APIException4XX, 5XX/

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()) {
            // レスポンスを処理する
        }
    }
}

サーバーの選択

インデックス指定でサーバーを選択

SDK クライアントインスタンスを初期化する際に、.serverIndex(int serverIdx) ビルダーメソッドを使用して、グローバルのデフォルトサーバー設定を上書きできます。選択したサーバーは、それを利用する各操作でデフォルトサーバーとして使用されます。次の表は、利用可能なサーバーに対応するインデックスを示しています。
#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

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()) {
            // レスポンスを処理する
        }
    }
}

クライアントごとにサーバー URL を上書きする

デフォルトのサーバーは、SDK クライアントインスタンスを初期化する際に .serverURL(String serverUrl) ビルダーメソッドを使用して、グローバルに上書きすることもできます。例:
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()) {
            // レスポンスを処理する
        }
    }
}

開発

安定性

このSDKはベータ版であり、メジャーバージョンの更新なしにバージョン間で破壊的な変更が行われる可能性があります。したがって、使用するパッケージのバージョンは特定のものに固定することを推奨します。そうすることで、意図的に最新バージョンへ更新しない限り、毎回同じバージョンを破壊的変更なしにインストールできます。

Contributions

この SDK へのオープンソースとしての貢献は歓迎しますが、このライブラリはプログラムによって自動生成されています。内部ファイルに手動で加えた変更は、次回の生成時に上書きされます。 フィードバックをお待ちしています。Proof of Concept を添えた PR や issue を遠慮なく作成してください。今後のリリースに反映できるよう最善を尽くします。

Speakeasy によって生成された SDK