# Get Balance History

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

GET https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo/api/v2/balancehistory/{address}

Returns the balance history for the specified address. Optionally enrich each bucket with secondary (fiat) currency rates at the time of the transaction.


Reference: https://www.alchemy.com/docs/chains/bitcoin/utxo-api-endpoints/utxo-api-endpoints/get-balance-history

## Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| address | string | Yes | Coin-specific address string. |

## Query Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| from | integer | Yes | Start of the history range as a Unix timestamp. |
| to | integer | Yes | End of the history range as a Unix timestamp. |
| fiatcurrency | string | No | Fiat currency code to enrich each bucket with. |
| groupBy | integer | No | Aggregation interval in seconds. Defaults to 3600. |

## Code Examples

### cURL

```bash
curl --request GET \
  --url 'https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo/api/v2/balancehistory/bc1q0wd209cv5k9pd9mhk7nspacywcj038xxdhnt5u?from=1578391200&to=1578488400'
```

### JavaScript

```javascript
const options = {method: 'GET'};

fetch('https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo/api/v2/balancehistory/bc1q0wd209cv5k9pd9mhk7nspacywcj038xxdhnt5u?from=1578391200&to=1578488400', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo/api/v2/balancehistory/bc1q0wd209cv5k9pd9mhk7nspacywcj038xxdhnt5u?from=1578391200&to=1578488400"

response = requests.get(url)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo/api/v2/balancehistory/bc1q0wd209cv5k9pd9mhk7nspacywcj038xxdhnt5u?from=1578391200&to=1578488400"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.get("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo/api/v2/balancehistory/bc1q0wd209cv5k9pd9mhk7nspacywcj038xxdhnt5u?from=1578391200&to=1578488400")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://bitcoin-mainnet.g.alchemy.com/v2/docs-demo/api/v2/balancehistory/bc1q0wd209cv5k9pd9mhk7nspacywcj038xxdhnt5u?from=1578391200&to=1578488400");
var client = new RestClient(options);
var request = new RestRequest("");
var response = await client.GetAsync(request);

Console.WriteLine("{0}", response.Content);

```


## Operation Specification

```yaml
path: /api/v2/balancehistory/{address}
method: GET
operation:
  operationId: getBalanceHistory
  summary: Get Balance History
  description: |
    Returns the balance history for the specified address. Optionally enrich each bucket with secondary (fiat) currency rates at the time of the transaction.
  tags:
    - UTXO API Endpoints
  parameters:
    - in: path
      name: address
      required: true
      description: Coin-specific address string.
      schema:
        type: string
      example: bc1q0wd209cv5k9pd9mhk7nspacywcj038xxdhnt5u
    - in: query
      name: from
      required: true
      description: Start of the history range as a Unix timestamp.
      schema:
        type: integer
        example: 1578391200
    - in: query
      name: to
      required: true
      description: End of the history range as a Unix timestamp.
      schema:
        type: integer
        example: 1578488400
    - in: query
      name: fiatcurrency
      required: false
      description: Fiat currency code to enrich each bucket with.
      schema:
        type: string
        example: usd
    - in: query
      name: groupBy
      required: false
      description: Aggregation interval in seconds. Defaults to 3600.
      schema:
        type: integer
        default: 3600
  responses:
    '200':
      description: Balance history buckets.
      content:
        application/json:
          schema:
            type: array
            items:
              type: object
              properties:
                time:
                  type: integer
                txs:
                  type: integer
                received:
                  type: string
                sent:
                  type: string
                sentToSelf:
                  type: string
                rates:
                  type: object
                  additionalProperties:
                    type: number
          example:
            - time: 1578391200
              txs: 5
              received: '5000000'
              sent: '0'
              sentToSelf: '100000'
              rates:
                usd: 7855.9
            - time: 1578488400
              txs: 1
              received: '0'
              sent: '5000000'
              sentToSelf: '0'
              rates:
                usd: 8283.11
    '400':
      description: Malformed request.
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: object
                properties:
                  message:
                    type: string
          example:
            error:
              message: invalid request
```
