Skip to navigation

Java Quick Start

Java Quick Start: Agent Java SDK v0.3.0 integration, examples, parameters and response semantics.

View as Markdown

This guide targets Agent Java SDK v0.3.0, Java 8+, and the tagged public contract. Initialize client using the installation and configuration steps on this page; run the examples in a partner backend.

Example prerequisites

The Java snippets share these imports. Initialize client using Quick Start and obtain platformUserId from the saved binding. Example user/order IDs must be replaced with your own persisted values.

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

Maven Coordinates

Current source coordinates:

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

GitHub is source hosting, not a Maven dependency repository. If the SDK has not been published to a Maven repository yet, install it into your local Maven repository first:

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

After local installation, your business project can resolve com.sixmm.exchange.sdk:agent:0.3.0 from the local Maven repository.

For team builds and test environments, publish the SDK to a Maven repository such as Nexus, Artifactory, GitHub Packages, Maven Central, or use a GitHub based build service such as JitPack.

For an existing integration, see the SDK upgrade guide. Use the stable v0.3.0 source tag to install the SDK and read its matching integration documentation.

Client Initialization

Plain 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());

Spring Boot

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());
}
}

Example application properties:

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

Bind User

Bind creates or fetches the relationship between a partner user and a 6MM platform user. Call it when a user first enters the trading flow or before the first transfer into 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);

Request fields:

FieldTypeRequiredDescription
agentUserIdstringYesUnique partner-side user ID
usernamestringNoPartner-side display name used as the platform user’s nickname
extstringNoExtension field. JSON string is recommended

Response fields:

FieldTypeDescription
platformUserIdstring6MM external user ID
bindStatusstringUsually BOUND
isSimulatedUserbooleanWhether this is a simulated user

First Trading Entry

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.

Deposit Into 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.

Withdraw Back To Partner

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.

Error Handling

SDK exceptions are split into two categories:

ExceptionScenarioSuggested handling
AgentApiExceptionHTTP status is not 2xx, or Agent response code != 0Read getHttpStatus(), getCode(), and getResponseBody() and treat it as a business/API failure
AgentSdkExceptionNetwork, serialization, configuration, or signing failureLog it and treat it as a system exception

Example:

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);
}

Receive Webhooks

All four event types share the configured merchant callback URL; dispatch by the body event. Verify the original received bytes, then check the time window, merchant, and environment. Return HTTP 2xx only after committing business data and successful deduplication records, or reliably saving a persistent task.

Events and liquidation warnings · Signature verification, responses, and retries