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

# Contract Ledger

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.*;
```

## `listPerpetualLedger`

Request model: `PerpetualLedgerRequest`.

```java
import com.sixmm.agent.model.PerpetualLedgerRequest;
import com.sixmm.agent.model.PerpetualResponse;
import java.util.Collections;

PerpetualLedgerRequest request = new PerpetualLedgerRequest();
request.platformUserIds = Collections.singletonList("1188041528");
request.limit = 100;
request.endTime = System.currentTimeMillis();
request.startTime = request.endTime - 3_600_000L;
PerpetualResponse response = client.listPerpetualLedger(request);
System.out.println(response.data.items.size());
System.out.println(response.data.hasMore);
System.out.println(response.data.nextCursor);
```

### Request fields

| Field             | Java type                | Required    | Meaning                                                                                                                                |
| ----------------- | ------------------------ | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `platformUserIds` | `java.util.List<String>` | Conditional | 1–100 unique public IDs; required for fills and conditional orders. Omit on supported queries for direct-player scope; \[] is invalid. |
| `assetType`       | `String`                 | No          | Asset classification as returned by the ledger; do not assume USDT.                                                                    |
| `changeType`      | `String`                 | No          | Ledger business-change type, preserving source values.                                                                                 |
| `startTime`       | `Long`                   | No          | Inclusive Unix milliseconds; use a fixed UTC history window.                                                                           |
| `endTime`         | `Long`                   | No          | Exclusive Unix milliseconds.                                                                                                           |
| `limit`           | `Integer`                | No          | Default 500; 1–1000.                                                                                                                   |
| `cursor`          | `String`                 | No          | Use the returned nextCursor with unchanged filters; stop when hasMore is false.                                                        |

The example reads one page. For required fields, player scope, filter semantics, limit, cursor and bounded retries, follow [Query overview](/sdk/agent-sdk/java/perpetual-queries). Keep all filters unchanged while paging; do not interpret an error as an empty result.

## Contract ledger records

Interface: `account/ledger`. The returned data only contains the following 11 business fields and does not carry the order boolean flags.

| `data` field          | type    | meaning                                                                                                                                                                        |
| --------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `ledgerId`            | string  | The source ledger records to the transaction ID; the same transaction may be split into multiple details                                                                       |
| `symbol`              | string  | Related trading pair, may be omitted if not related                                                                                                                            |
| `assetType`           | string  | Asset type, saved by source value; used for asset classification, not inferred by default USDT                                                                                 |
| `changeType`          | string  | Account change business type, saved according to source value, such as handling fee, profit and loss, transfer; can be filtered by the same field                              |
| `amount`              | string  | The change amount of this detail, a positive number indicates an increase, a negative number indicates a decrease; precision is retained                                       |
| `walletBalanceBefore` | string  | The wallet balance before the account change recorded in this detail                                                                                                           |
| `walletBalanceAfter`  | string  | The wallet balance after the account change recorded in this detail                                                                                                            |
| `frozenBalanceBefore` | string  | The frozen balance recorded before the account change is recorded in this detail                                                                                               |
| `frozenBalanceAfter`  | string  | The frozen balance recorded in this detail after the account change                                                                                                            |
| `referenceId`         | string  | Associated business number; interpreted as changeType and cannot be uniformly regarded as order orderId; "0" indicates that the source does not have a valid associated number |
| `createdAt`           | integer | Creation time of account change details, milliseconds; this field is used for time filtering in this interface                                                                 |

Use the balance before and after the account change returned by the interface. Different changeType have different semantics, and it cannot be assumed that each amount is equal to walletBalanceAfter − walletBalanceBefore. The display/summary of ledger records should retain the type and detail identity.

Here's an example of the format, using a fictitious ID and amount:

```json
{
  "code": 0,
  "message": "success",
  "data": {
    "items": [
      {
        "platformUserId": "1188041528",
        "entityType": "ACCOUNT_LEDGER",
        "entityId": "900001",
        "data": {
          "ledgerId": "ledger-example-001",
          "symbol": "BTCUSDT",
          "assetType": "USDT",
          "changeType": "HANDLING_FEE",
          "amount": "-0.10000000",
          "walletBalanceBefore": "100.00000000",
          "walletBalanceAfter": "99.90000000",
          "frozenBalanceBefore": "0.00000000",
          "frozenBalanceAfter": "0.00000000",
          "referenceId": "800001",
          "createdAt": 1791590400000
        }
      }
    ],
    "nextCursor": "",
    "hasMore": false
  }
}
```

## Example response envelope

This is an illustrative empty page, not a sample of a completed trade. Resource-specific field tables above describe populated `items[].data`.

```json
{"code":0,"message":"success","data":{"items":[],"nextCursor":"","hasMore":false}}
```

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