> For the complete documentation index, see [llms.txt](https://docs.pretoke.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pretoke.xyz/api-reference/portfolio.md).

# Portfolio (Positions, Trades, Balance)

{% hint style="warning" %}
**All endpoints require authentication.** Data is scoped to the authenticated user — there is no way to query another user's portfolio.
{% endhint %}

***

## GET /balance

Returns your current balance breakdown.

### Code examples

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X GET "https://predict.pretoke.xyz/api/v1/balance" \
  -H "Authorization: Bearer <token>"
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch('https://predict.pretoke.xyz/api/v1/balance', {
  headers: { 'Authorization': `Bearer ${accessToken}` }
});
const { data: balance } = await response.json();
console.log(`Available: ${balance.available}, Locked: ${balance.locked}`);
```

{% endtab %}

{% tab title="Python" %}

```python
response = requests.get(
    "https://predict.pretoke.xyz/api/v1/balance",
    headers={"Authorization": f"Bearer {access_token}"}
)
balance = response.json()["data"]
print(f"Available: {balance['available']}, Locked: {balance['locked']}")
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { data: result } = await axios.get('https://predict.pretoke.xyz/api/v1/balance', {
  headers: { Authorization: `Bearer ${accessToken}` }
});
const { available, locked, total } = result.data;
```

{% endtab %}
{% endtabs %}

### Response `200 OK`

```json
{
  "data": { "available": "1250000000", "locked": "50000000", "total": "1300000000" },
  "requestId": "..."
}
```

All values in micro-USDT (divide by 1,000,000 for dollar amount).

***

## GET /positions

Returns your open positions with unrealized P\&L.

### Code examples

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X GET "https://predict.pretoke.xyz/api/v1/positions" \
  -H "Authorization: Bearer <token>"
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch('https://predict.pretoke.xyz/api/v1/positions', {
  headers: { 'Authorization': `Bearer ${accessToken}` }
});
const { data: positions } = await response.json();

positions.forEach(pos => {
  console.log(`${pos.outcome} x${pos.quantity} — PnL: ${pos.unrealizedPnl}`);
});
```

{% endtab %}

{% tab title="Python" %}

```python
response = requests.get(
    "https://predict.pretoke.xyz/api/v1/positions",
    headers={"Authorization": f"Bearer {access_token}"}
)
positions = response.json()["data"]
for pos in positions:
    print(f"{pos['outcome']} x{pos['quantity']} — PnL: {pos.get('unrealizedPnl', 'N/A')}")
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const { data: result } = await axios.get('https://predict.pretoke.xyz/api/v1/positions', {
  headers: { Authorization: `Bearer ${accessToken}` }
});
result.data.forEach(pos => console.log(pos));
```

{% endtab %}
{% endtabs %}

### Response `200 OK`

```json
{
  "data": [
    {
      "id": "pos_01hz...",
      "marketId": "mkt_01hz...",
      "outcome": "YES",
      "quantity": "100000000",
      "avgEntryPrice": "0.55",
      "totalCost": "55000000",
      "realizedPnl": "0",
      "status": "open",
      "market": { "id": "mkt_01hz...", "title": "..." },
      "markPrice": "0.63",
      "unrealizedPnl": "8000000"
    }
  ],
  "requestId": "..."
}
```

| Field           | Description                                                                                                                                    |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `markPrice`     | Depth-aware exit price — the blended price of selling the entire held quantity through the order book. `null` if no liquidity to exit against. |
| `unrealizedPnl` | `(markPrice − avgEntryPrice) × quantity`, in micro-USDT. `null` when `markPrice` is unavailable.                                               |
| `status`        | `open` or `settled`                                                                                                                            |

***

## GET /trades

Paginated trade history.

### Query parameters

| Param      | Type   | Description    |
| ---------- | ------ | -------------- |
| `page`     | number | Page number    |
| `pageSize` | number | Items per page |

### Code examples

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X GET "https://predict.pretoke.xyz/api/v1/trades?page=1&pageSize=20" \
  -H "Authorization: Bearer <token>"
```

{% endtab %}

{% tab title="Python" %}

```python
response = requests.get(
    "https://predict.pretoke.xyz/api/v1/trades",
    headers={"Authorization": f"Bearer {access_token}"},
    params={"page": 1, "pageSize": 20}
)
trades = response.json()["data"]
```

{% endtab %}
{% endtabs %}

***

## GET /trades/:id

Fetch a single trade — primarily used to poll settlement status.

### Code examples

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X GET "https://predict.pretoke.xyz/api/v1/trades/trd_01hz..." \
  -H "Authorization: Bearer <token>"
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch('https://predict.pretoke.xyz/api/v1/trades/trd_01hz...', {
  headers: { 'Authorization': `Bearer ${accessToken}` }
});
const { data: trade } = await response.json();
console.log(`Settlement: ${trade.settlementStatus}, TX: ${trade.settlementTxHash}`);
```

{% endtab %}

{% tab title="Python" %}

```python
response = requests.get(
    "https://predict.pretoke.xyz/api/v1/trades/trd_01hz...",
    headers={"Authorization": f"Bearer {access_token}"}
)
trade = response.json()["data"]
print(f"Status: {trade['settlementStatus']}, TX: {trade.get('settlementTxHash')}")
```

{% endtab %}
{% endtabs %}

### Response `200 OK`

```json
{
  "data": {
    "id": "trd_01hz...",
    "settlementStatus": "confirmed",
    "settlementTxHash": "e4f1a2..."
  },
  "requestId": "..."
}
```

{% hint style="info" %}
`settlementStatus` progresses: `pending` → `confirmed` (or `failed`). Once `confirmed`, `settlementTxHash` is a real TON transaction hash you can look up on any TON block explorer.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.pretoke.xyz/api-reference/portfolio.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
