Documentation Index
Fetch the complete documentation index at: https://benzinga-2-locadex-parallel-main.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
開発者フレンドリーで型安全な Java SDK であり、openapi API を活用するために特化して設計されています。
Benzinga API 群:この REST API は、Benzinga のすべての API へのエンドポイントを提供します。
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
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では、グローバルに次のセキュリティスキームをサポートしています。
| Name | Type | Scheme |
|---|
apiKeyAuth | apiKey | API 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 - アナリストレポートの生テキストデータを取得する
- 取得 - Bulls Say Bears Say V1 データを取得
- getV22 - 配当データ V2.2 を取得
- get - 配当データ V2 および V2.1 を取得
- get - earning ratios v2.1 を取得
- getV21 - IPOs v2.1 データを取得
- get - IPOs v2 データを取得
- 取得 - Newsquantified データの取得
- get - operation ratios V2.1 を取得
- get - OptionActivity V1 を取得
- get - ティッカーのトレンドデータを取得
- getList - ティッカーのトレンドリストデータを取得
この 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/ApiErrorResponse | 400, 500 | application/json |
| models/errors/APIException | 4XX, 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 |
|---|
| 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 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()) {
// レスポンスを処理する
}
}
}
デフォルトのサーバーは、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はベータ版であり、メジャーバージョンの更新なしにバージョン間で破壊的な変更が行われる可能性があります。したがって、使用するパッケージのバージョンは特定のものに固定することを推奨します。そうすることで、意図的に最新バージョンへ更新しない限り、毎回同じバージョンを破壊的変更なしにインストールできます。
この SDK へのオープンソースとしての貢献は歓迎しますが、このライブラリはプログラムによって自動生成されています。内部ファイルに手動で加えた変更は、次回の生成時に上書きされます。
フィードバックをお待ちしています。Proof of Concept を添えた PR や issue を遠慮なく作成してください。今後のリリースに反映できるよう最善を尽くします。