# Ledger

<div class="api-grid" markdown>
<div class="api-main" markdown>

<span class="api-method api-method--get">GET</span> <span class="api-url">`https://api.pro.anboto.xyz/api/v2/portfolio/pnl/ledger`</span>

Income from the exchange's own history: realized PnL, funding, commissions, rebates and other income, in USD. Signs are from the account's point of view: + is income, − is cost. `net` is the net realized PnL of futures (Net realized (futures)). Spot income is trading fees only: they are in `commission` and `fee_rebate` but not in `net`, and spot rows (and a spot-only selection's `totals`) have null `realized_pnl`, `funding`, `other` and `net`, never 0. `coverage` gives the ingestion status per account; venues without ingestion are listed there as `unsupported` and are never reported as zero. Today's figures are provisional. Results are paged: pass `next_cursor` back as `cursor`; `totals` always cover the whole window. **ApiKeyAuth** required.

### Query params

<div class="api-params" markdown>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`accounts` <span class="api-param__type">string</span></div>
<div class="api-param__desc" markdown="span">Comma-separated accounts: `binance` = every account on Binance (main and subaccounts), `binance:` = the main account only, `binance:Sub1` = that subaccount. Omit for every account of the team. At most 20 items. Unlike /api/v2/trading/*, a missing subaccount means all accounts. Sign the raw value, e.g. `accounts=binance:,bybit:Sub1`.</div>
<div class="api-param__meta" markdown="span">Example: `binance:`</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`groupBy` <span class="api-param__type">enum</span></div>
<div class="api-param__desc" markdown="span">Row grouping: day, symbol or day_symbol (default) — `day`, `symbol`, `day_symbol`</div>
<div class="api-param__meta" markdown="span">Default: `day_symbol`</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`symbol` <span class="api-param__type">string</span></div>
<div class="api-param__desc" markdown="span">Only this Anboto symbol, e.g. BTC/USDT:USDT (futures) or BTC/USDT (spot)</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`market` <span class="api-param__type">enum</span></div>
<div class="api-param__desc" markdown="span">Only this market: spot or future — `spot`, `future`</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`period` <span class="api-param__type">string</span></div>
<div class="api-param__desc" markdown="span">Window ending at endDate: `<N>d`, week, month, quarter or year. Default 30d. Ignored when startDate is given</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`startDate` <span class="api-param__type">date</span></div>
<div class="api-param__desc" markdown="span">First day, YYYY-MM-DD (UTC, inclusive)</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`endDate` <span class="api-param__type">date</span></div>
<div class="api-param__desc" markdown="span">Last day, YYYY-MM-DD (UTC, inclusive). Defaults to today; at most today. The window spans at most 366 days</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`limit` <span class="api-param__type">integer</span></div>
<div class="api-param__desc" markdown="span">Rows per page, 1 to 5000 (default 1000)</div>
<div class="api-param__meta" markdown="span">Default: `1000`</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`cursor` <span class="api-param__type">string</span></div>
<div class="api-param__desc" markdown="span">`next_cursor` of the previous page</div>
</div>
</div>

### Headers

| Header | | |
|---|---|---|
| `X-API-KEY` | string | <span class="api-req">required</span> |
| `X-TIMESTAMP` | int64 ms | <span class="api-req">required</span> |
| `X-SIGN` | string | <span class="api-req">required</span> |
| `X-RECV-WINDOW` | int, default 5000 | |

### Responses

| | |
|---|---|
| <span class="api-status api-status--ok">200</span> | The income ledger |
| <span class="api-status api-status--err">400</span> | Invalid parameter, {"error": "..."} |
| <span class="api-status api-status--err">401</span> | Unauthorized: missing or unknown API key |
| <span class="api-status api-status--err">429</span> | Rate limit exceeded, retry later |
| <span class="api-status api-status--err">503</span> | The portfolio service is unavailable, {"error": "..."} |

### Response fields — [PortfolioLedgerResponse](schemas.md#portfolioledgerresponse)

<div class="api-params" markdown>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`as_of` <span class="api-param__type">date-time</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">UTC time of the newest ingested income data</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`from_date` <span class="api-param__type">date</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">First day of the window (YYYY-MM-DD, UTC)</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`to_date` <span class="api-param__type">date</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Last day of the window (YYYY-MM-DD, UTC); today's figures are provisional</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`group_by` <span class="api-param__type">enum</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Grouping of `rows` — `day`, `symbol`, `day_symbol`</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`currency` <span class="api-param__type">string</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Currency of every money value</div>
<div class="api-param__meta" markdown="span">Example: `USD`</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`coverage` <span class="api-param__type">array[[LedgerCoverage](schemas.md#ledgercoverage)]</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Ingestion status per account and market. Unsupported venues are listed here, not reported as zero</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`coverage[].exchange` <span class="api-param__type">string</span> <span class="api-req">required</span></div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`coverage[].subaccount` <span class="api-param__type">string</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">"" is the main account; null means every account on the exchange</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`coverage[].market` <span class="api-param__type">enum</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">`spot`, `future`</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`coverage[].status` <span class="api-param__type">enum</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">`complete`, `partial`, `unsupported`</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`coverage[].ingested_through` <span class="api-param__type">date-time</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">UTC time up to which income is ingested</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`coverage[].reason` <span class="api-param__type">string</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Why the account is partial or unsupported, e.g. exchange_not_supported, key_invalid</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`totals` <span class="api-param__type">[LedgerTotals](schemas.md#ledgertotals)</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Income components in USD. net is the net realized PnL of the futures scopes only: spot trading fees are in commission and fee_rebate but not in net. Every value is null when no day of the window is covered</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`totals.realized_pnl` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Realized trading PnL; null when the selection has no futures scope</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`totals.funding` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Funding: positive when received; null when the selection has no futures scope</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`totals.commission` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Trading fees (≤ 0)</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`totals.fee_rebate` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Fee rebates (≥ 0)</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`totals.interest` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Margin interest: not ingested, 0</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`totals.other` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Other PnL-relevant income; null when the selection has no futures scope</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`totals.net` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Net realized (futures): the sum of the futures components. Spot trading fees are in commission and fee_rebate but not in net, so with a spot scope in the selection net is not the sum of the values above. Null when the selection has no futures scope</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`unpriced_assets` <span class="api-param__type">array[string]</span></div>
<div class="api-param__desc" markdown="span">Assets with income rows that could not be valued in USD; those amounts are missing from the USD figures</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows` <span class="api-param__type">array[[LedgerRow](schemas.md#ledgerrow)]</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">One row per day, symbol or day and symbol, depending on group_by</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].date` <span class="api-param__type">date</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">UTC day (YYYY-MM-DD); null when group_by is symbol</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].exchange` <span class="api-param__type">string</span> <span class="api-req">required</span></div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].subaccount` <span class="api-param__type">string</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">"" is the main account</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].symbol` <span class="api-param__type">string</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Anboto symbol, e.g. BTC/USDT:USDT (futures) or BTC/USDT (spot); null when group_by is day or for income without a symbol</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].market` <span class="api-param__type">enum</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">`spot`, `future`</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].realized_pnl` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Realized trading PnL; null for market spot (trading fees only), never 0</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].funding` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Funding; null for market spot (trading fees only), never 0</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].commission` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Trading fees (≤ 0), spot and futures</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].fee_rebate` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Fee rebates (≥ 0), spot and futures</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].interest` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Margin interest: not ingested, 0</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].other` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Other PnL-relevant income; null for market spot (trading fees only), never 0</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`rows[].net` <span class="api-param__type">number</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Net realized (futures): sum of the row's components. Null for market spot: spot trading fees are in commission and fee_rebate only, never in net</div>
</div>
<div class="api-param" markdown>
<div class="api-param__head" markdown="span">`next_cursor` <span class="api-param__type">string</span> <span class="api-req">required</span></div>
<div class="api-param__desc" markdown="span">Pass as `cursor` to read the next page; null on the last page</div>
</div>
</div>

</div>
<div class="api-code" markdown>

=== "Shell"

    ```bash
    curl -X GET "$BASE/api/v2/portfolio/pnl/ledger?accounts=string" \
      -H "X-API-KEY: $API_KEY" -H "X-TIMESTAMP: $ts" \
      -H "X-SIGN: $sign"
    ```

=== "Python"

    ```python
    params = {"accounts": ..., "groupBy": ..., "symbol": ..., "market": ..., "period": ..., "startDate": ..., "endDate": ..., "limit": ..., "cursor": ...}
    r = requests.get(f"{BASE}/api/v2/portfolio/pnl/ledger",
        params=params
        headers=signed_headers_query(params))
    print(r.json())
    ```

=== "Rust"

    ```rust
    let resp = client
        .get(format!("{BASE}/api/v2/portfolio/pnl/ledger?accounts=string"))
        .headers(signed_headers_query(&params))
        .send()?;
    println!("{}", resp.text()?);
    ```

=== "Go"

    ```go
    req, _ := http.NewRequest("GET", BASE+"/api/v2/portfolio/pnl/ledger?accounts=string", nil)
    for k, v := range signedHeadersQuery(req.URL.Query()) {
    	req.Header.Set(k, v)
    }
    resp, err := http.DefaultClient.Do(req)
    if err != nil {
    	log.Fatal(err)
    }
    defer resp.Body.Close()
    io.Copy(os.Stdout, resp.Body)
    ```

=== "Java"

    ```java
    HttpResponse<String> resp = client.send(
        signedGet("/api/v2/portfolio/pnl/ledger?accounts=string"),
        HttpResponse.BodyHandlers.ofString());
    ```

=== "TypeScript"

    ```typescript
    const res = await fetch(`${BASE}/api/v2/portfolio/pnl/ledger?accounts=string`, {
      method: "GET",
      headers: signedHeadersQuery(params),
    });
    const data: PortfolioLedgerResponse = await res.json();
    ```

=== "Kotlin"

    ```kotlin
    val request = signedGet("/api/v2/portfolio/pnl/ledger?accounts=string")
    val response = client.send(request, HttpResponse.BodyHandlers.ofString())
    println(response.body())
    ```

=== "C++"

    ```cpp
    cpr::Response r = cpr::Get(
        cpr::Url{BASE + "/api/v2/portfolio/pnl/ledger?accounts=string"},
        signedHeadersQuery(params));
    std::cout << r.text << std::endl;
    ```

=== "JavaScript"

    ```javascript
    const res = await fetch(`${BASE}/api/v2/portfolio/pnl/ledger?accounts=string`, {
      method: "GET",
      headers: signedHeadersQuery(params),
    });
    console.log(await res.json());
    ```

<div class="api-response" markdown>

**Response** <span class="api-status api-status--ok">200</span>

```json
{
  "as_of": "string",
  "from_date": "string",
  "to_date": "string",
  "group_by": "day",
  "currency": "USD",
  "coverage": [
    {
      "exchange": "string",
      "subaccount": "string",
      "market": "spot",
      "status": "complete",
      "ingested_through": "string",
      "reason": "string"
    }
  ],
  "totals": {
    "realized_pnl": 0.0,
    "funding": 0.0,
    "commission": 0.0,
    "fee_rebate": 0.0,
    "interest": 0.0,
    "other": 0.0,
    "net": 0.0
  },
  "unpriced_assets": [
    "string"
  ],
  "rows": [
    {
      "date": "string",
      "exchange": "string",
      "subaccount": "string",
      "symbol": "string",
      "market": "spot",
      "realized_pnl": 0.0,
      "funding": 0.0,
      "commission": 0.0,
      "fee_rebate": 0.0,
      "interest": 0.0,
      "other": 0.0,
      "net": 0.0
    }
  ],
  "next_cursor": "string"
}
```

</div>
</div>
</div>
