> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.6mm.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.6mm.com/_mcp/server.

# Users & Assets

This guide targets **Agent Java SDK `v0.3.0`**, Java 8+, and the tagged public contract. Examples run in a partner backend after initializing `client` in [Quick Start](/sdk/agent-sdk/java/quick-start).

## 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.

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

## User ID Rules

`platformUserId` is the 6MM external user ID. It is currently a 10-digit numeric
string, for example:

```text
1188041528
```

Rules:

* Store it as a string, not as an integer.
* Do not generate, decode, or infer meaning from it.
* Use your own partner-side user ID as `agentUserId`.
* Persist the relationship among `agentUserId`, `platformUserId`, and `agentOrderNo`.

## 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.

```java
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:

| Field         | Type   | Required | Description                                                    |
| ------------- | ------ | -------- | -------------------------------------------------------------- |
| `agentUserId` | string | Yes      | Unique partner-side user ID                                    |
| `username`    | string | No       | Partner-side display name used as the platform user's nickname |
| `ext`         | string | No       | Extension field. JSON string is recommended                    |

Response fields:

| Field             | Type    | Description                      |
| ----------------- | ------- | -------------------------------- |
| `platformUserId`  | string  | 6MM external user ID             |
| `bindStatus`      | string  | Usually `BOUND`                  |
| `isSimulatedUser` | boolean | Whether this is a simulated user |

## Query Partner Account

```java
import com.sixmm.agent.model.QueryAccountRequest;
import com.sixmm.agent.model.QueryAccountResponse;

QueryAccountResponse resp = client.queryAccount(QueryAccountRequest.of("USDT"));

System.out.println(resp.agentCode);
System.out.println(resp.agentStatus);
resp.assets.forEach(asset -> {
    System.out.println(asset.currency);
    System.out.println(asset.depositBalance);
});
```

When `currency` is absent, the SDK uses `defaultCurrency`.

## Query User Assets

```java
import com.sixmm.agent.model.QueryUserAssetsRequest;
import com.sixmm.agent.model.QueryUserAssetsResponse;

QueryUserAssetsResponse resp = client.queryUserAssets(
        QueryUserAssetsRequest.of("1188041528"));

System.out.println(resp.walletBalance);
System.out.println(resp.availableBalance);
System.out.println(resp.version);
```

Fields:

| Field              | Type    | Description                      |
| ------------------ | ------- | -------------------------------- |
| `walletBalance`    | string  | Wallet balance                   |
| `frozenMargin`     | string  | Frozen margin                    |
| `usedMargin`       | string  | Used margin                      |
| `availableBalance` | string  | Available balance                |
| `isolatedMargin`   | string  | Isolated margin                  |
| `version`          | int64   | Asset version                    |
| `isSimulatedUser`  | boolean | Whether this is a simulated user |

### Distinguish the three wallets

| wallet                     | Balance source                                | use                                                        |
| -------------------------- | --------------------------------------------- | ---------------------------------------------------------- |
| Merchant’s own user wallet | Merchant’s own accounting system              | The user’s available balance on the merchant side          |
| Platform Funding           | `queryUserAssets` of `funding`                | Seconds trading funds and Funding/Contract mutual transfer |
| Platform Contract          | The contract asset field of `queryUserAssets` | Perpetual contract margin and transferable balance         |

`queryAccount` Query the merchant platform margin account, not the merchant user wallet. This interface does not have `environment` parameters and cannot be queried as a simulated user asset.

Query the two platform wallets of simulated users:

```java
QueryUserAssetsResponse assets = client.queryUserAssets(
        QueryUserAssetsRequest.of(platformUserId)
                .withFunding()
                .withEnvironment(ExecutionEnvironment.SIMULATED));
```

Interface: `POST /v1/agent/query-user-assets`. Funding is requested only when `includeFunding=true`; the original contract asset query semantics are used by default.

| response fields                                                                     | meaning                                                                                                                          |
| ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `walletBalance`, `availableBalance`, `frozenMargin`, `usedMargin`, `isolatedMargin` | Contract wallet related amounts                                                                                                  |
| `funding.assetCode`                                                                 | Currently USDT                                                                                                                   |
| `funding.availableAmount`, `heldAmount`, `totalAmount`                              | Funding available, occupied and total amount                                                                                     |
| `funding.materialized`                                                              | Whether the Funding account has been materialized?                                                                               |
| `environment`                                                                       | This field is echoed when the environment is passed explicitly; old requests that omit the environment do not return this field. |
| `isSimulatedUser`                                                                   | Account classification; cannot replace trading environment selection                                                             |

Amounts are handled as strings or `BigDecimal`, not `float`/`double`.

## Source and related guides

* [Official v0.3.0 source](https://github.com/6mm-com/agent-java-sdk/tree/54aa3c1)
* [Query overview and pagination](/sdk/agent-sdk/java/perpetual-queries)
* [Funding wallet](/sdk/agent-sdk/java/funding-wallet)
* [Upgrade guide](/sdk/agent-sdk/java/upgrade)