ナビゲーションにスキップ

Java クイックスタート

Java クイック スタート: Agent Java SDK v0.3.0 の統合、例、パラメーター、および応答セマンティクス。

Markdownとして表示

このガイドは、Agent Java SDK v0.3.0、Java 8 以降、およびタグ付けされたパブリック コントラクトを対象としています。このページのインストールおよび構成手順を使用して client を初期化します。パートナーのバックエンドでサンプルを実行します。

前提条件の例

Java スニペットはこれらのインポートを共有します。クイック スタートを使用して client を初期化し、保存されたバインディングから platformUserId を取得します。ユーザー/オーダー ID の例は、独自の永続化された値に置き換える必要があります。

import com.sixmm.agent.*;
import com.sixmm.agent.model.*;
import java.util.*;

Maven 座標

現在のソース座標:

<dependency>
<groupId>com.sixmm.exchange.sdk</groupId>
<artifactId>agent</artifactId>
<version>0.3.0</version>
</dependency>

GitHub はソース ホスティングであり、Maven 依存関係リポジトリではありません。 SDK がまだ行われていない場合 まだ Maven リポジトリに公開されていない場合は、ローカル Maven にインストールしてください 最初にリポジトリ:

git clone https://github.com/6mm-com/agent-java-sdk.git
cd agent-java-sdk
git checkout v0.3.0
mvn install

ローカルにインストールした後、ビジネス プロジェクトを解決できます。 com.sixmm.exchange.sdk:agent:0.3.0 ローカル Maven リポジトリから。

チームビルドおよびテスト環境の場合、SDK を Maven リポジトリに公開します Nexus、Artifactory、GitHub パッケージ、Maven Central など、または GitHub を使用する JitPack などのベースのビルド サービス。

既存の統合については、を参照してください。 SDK アップグレード ガイド。安定した v0.3.0 ソースタグを使用して SDK をインストールし、対応する統合ドキュメントを読んでください。

クライアントの初期化

プレーン Java

import com.sixmm.agent.AgentClient;
import com.sixmm.agent.AgentClientConfig;
AgentClient client = new AgentClient(AgentClientConfig.builder()
.baseUrl("https://agent-api.6mm.com")
.agentCode("AGENT001")
.apiSecret("your-api-secret")
.defaultCurrency("USDT")
.build());

スプリングブーツ

import com.sixmm.agent.AgentClient;
import com.sixmm.agent.AgentClientConfig;
import java.time.Duration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AgentSdkConfig {
@Bean
public AgentClient agentClient(AgentSdkProperties props) {
return new AgentClient(AgentClientConfig.builder()
.baseUrl(props.getBaseUrl())
.agentCode(props.getAgentCode())
.apiSecret(props.getApiSecret())
.defaultCurrency("USDT")
.timeout(Duration.ofSeconds(10))
.build());
}
}

アプリケーションのプロパティの例:

agent.sdk.base-url=https://agent-api.6mm.com
agent.sdk.agent-code=AGENT001
agent.sdk.api-secret=${AGENT_API_SECRET}

バインドユーザー

バインドは、パートナー ユーザーと 6MM の間の関係を作成または取得します。 プラットフォームのユーザー。ユーザーが最初に取引フローに入るとき、または取引フローに入る前に呼び出します。 最初に 6MM に転送します。

import com.sixmm.agent.model.BindRequest;
import com.sixmm.agent.model.BindResponse;
BindResponse resp = client.bind(
BindRequest.of("agent-user-001")
.withUsername("alice")
.withExt("{\"source\":\"web\"}"));
System.out.println(resp.platformUserId);
System.out.println(resp.bindStatus);
System.out.println(resp.isSimulatedUser);

リクエストフィールド:

分野タイプ必須説明
agentUserIdstringはいパートナー側の一意のユーザーID
usernamestringいいえプラットフォームユーザーのニックネームとして使用されるパートナー側の表示名
extstringいいえ拡張フィールド。 JSON 文字列が推奨されます

応答フィールド:

分野タイプ説明
platformUserIdstring6MM 外部ユーザー ID
bindStatusstring通常 BOUND
isSimulatedUserbooleanこれがシミュレートされたユーザーであるかどうか

推奨業務フロー

最初の取引エントリー

1. User logs in to the partner site.
2. Partner backend calls bind with agentUserId.
3. Partner stores the agentUserId and platformUserId relationship.
4. User clicks the trading entry.
5. Redirect mode: call createEntryUrl and open webUrl in the browser.
6. Embed mode: Trading Widget calls tokenProvider, and partner backend calls createEmbedToken.

6MM に入金する

1. Partner creates a unique agentOrderNo.
2. Partner calls transfer(Direction.IN).
3. If SUCCESS is returned, mark the local order as successful.
4. If PROCESSING is returned, wait for webhook or poll queryOrder.
5. If FAILED is returned or AgentApiException is thrown, handle it as failed.

撤退してパートナーに戻る

1. Partner creates a unique agentOrderNo.
2. Fixed amount withdraw: call transfer(Direction.OUT).
3. Full withdraw: call transferAllOut.
4. Confirm the final result by orderStatus, webhook, or queryOrder.

ソースおよび関連ガイド

エラー処理

SDK 例外は 2 つのカテゴリに分類されます。

例外シナリオ推奨される取り扱い
AgentApiExceptionHTTP ステータスが 2xx ではない、またはエージェントの応答 code != 0getHttpStatus()、getCode()、および getResponseBody() を読み取り、ビジネス/API の失敗として扱います
AgentSdkExceptionネットワーク、シリアル化、構成、または署名の失敗ログに記録し、システム例外として扱います

例:

import com.sixmm.agent.AgentApiException;
import com.sixmm.agent.AgentSdkException;
try {
TransferResponse resp = client.transfer(TransferRequest.fixed(
"AGT-ORDER-1001", "agent-user-001", Direction.IN, "USDT", "10.00"));
// Update the local order according to resp.orderStatus.
} catch (AgentApiException e) {
// Business rejection or HTTP error.
log.warn("6mm agent api rejected request, httpStatus={}, code={}, body={}",
e.getHttpStatus(), e.getCode(), e.getResponseBody());
} catch (AgentSdkException e) {
// Local SDK error or network error.
log.error("6mm agent sdk request failed", e);
}

Webhooksを受信します

4 つのイベント タイプはすべて、設定されたマーチャント コールバック URL を共有します。本体 event による発送。元の受信バイトを確認し、時間枠、マーチャント、および環境を確認します。ビジネス データと成功した重複排除レコードをコミットした後、または永続タスクを確実に保存した後でのみ、HTTP 2xx を返します。

イベントと清算に関する警告 · 署名の検証、応答、および再試行