# Mercado Financeiro

A **HG Finance** reúne diversos conjuntos de dados essenciais para o monitoramento do mercado financeiro. Com ela, você poderá:

- Acessar **cotações de moedas e ativos** (como ações e FIIs);
- Descobrir os **tickers disponíveis** para consulta nos endpoints;
- Consultar **índices de mercado**, inclusive os que exibem altas e baixas;
- Obter informações sobre **criptomoedas** a partir de múltiplas exchanges;
- Recuperar as principais **taxas de juros** do Brasil (CDI, SELIC, etc.);
- Consultar **dados históricos** para análises e projeções.

Esta página serve como ponto de partida para entender a estrutura geral da API, como autenticar suas requisições e quais formatos de resposta estão disponíveis.

<callout color="neutral" icon="tabler:key" to="/docs/guide/key">

Para acessar os dados da API é necessário utilizar uma chave de integração.

</callout>

<note icon="tabler:clock">

As cotações são atualizadas em intervalos de 15 a 45 minutos durante o pregão.

</note>

## Requisição

Todas as requisições têm como base o seguinte endpoint:

```http
GET https://api.hgbrasil.com/finance?key=suachave
```

```bash [cURL]
curl -X GET "https://api.hgbrasil.com/finance?key=suachave"
```

```javascript [JavaScript]
const url = new URL("/finance", "https://api.hgbrasil.com")

url.searchParams.set("key", "suachave")

const response = await fetch(url.href)
const data = await response.json()
```

```php [PHP]
$url = 'https://api.hgbrasil.com/finance';

$queryString = http_build_query([
    'key' => 'suachave'
]);

$response = file_get_contents($url . '?' . $queryString);
$data = json_decode($response, true);
```

```python [Python]
import requests

url = 'https://api.hgbrasil.com/finance'

params = {
    'key': 'suachave'
}

response = requests.get(url, params=params)
data = response.json()
```

```ruby [Ruby]
require 'net/http'
require 'uri'
require 'json'

uri = URI('https://api.hgbrasil.com/finance')

uri.query = URI.encode_www_form({
  key: 'suachave'
})

response = Net::HTTP.get(uri)
data = JSON.parse(response, symbolize_names: true)
```

```java [Java]
import java.net.URI;
import java.net.http.*;

var url = "https://api.hgbrasil.com/finance?key=suachave";

var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
    .uri(URI.create(url))
    .GET()
    .build();

var response = client.send(request, HttpResponse.BodyHandlers.ofString());
var data = response.body();
```

```csharp [C#]
using System.Net.Http;
using System.Text.Json;
using System.Web;

var client = new HttpClient();
var baseUrl = "https://api.hgbrasil.com/finance";

var queryParams = HttpUtility.ParseQueryString(string.Empty);
queryParams["key"] = "suachave";

var url = $"{baseUrl}?{queryParams}";
var response = await client.GetStringAsync(url);
var data = JsonSerializer.Deserialize<dynamic>(response);
```

## Resposta

Exemplo de resposta no formato `JSON`.

```json
{
  "by": "default",
  "valid_key": true,
  "results": {
    "currencies": {
      "source": "BRL",
      "USD": {
        "name": "Dollar",
        "buy": 5.1421,
        "sell": 5.142,
        "variation": 0.035
      },
      "EUR": {
        "name": "Euro",
        "buy": 5.9057,
        "sell": 5.9067,
        "variation": 0.02
      },
      "GBP": {
        "name": "Pound Sterling",
        "buy": 6.8886,
        "sell": null,
        "variation": 0.019
      },
      "ARS": {
        "name": "Argentine Peso",
        "buy": 0.0032,
        "sell": null,
        "variation": 0
      },
      "CAD": {
        "name": "Canadian Dollar",
        "buy": 3.6799,
        "sell": null,
        "variation": 0.139
      },
      "AUD": {
        "name": "Australian Dollar",
        "buy": 3.6592,
        "sell": null,
        "variation": 0.019
      },
      "JPY": {
        "name": "Japanese Yen",
        "buy": 0.0327,
        "sell": null,
        "variation": 0
      },
      "CNY": {
        "name": "Renminbi",
        "buy": 0.7684,
        "sell": null,
        "variation": 0.183
      },
      "BTC": {
        "name": "Bitcoin",
        "buy": 442348.169,
        "sell": 442348.169,
        "variation": -0.012
      }
    },
    "stocks": {
      "IBOVESPA": {
        "name": "BM&F BOVESPA",
        "location": "Sao Paulo, Brazil",
        "points": 185229.17,
        "variation": -0.41
      },
      "IFIX": {
        "name": "Índice de Fundos de Investimentos Imobiliários B3",
        "location": "Sao Paulo, Brazil",
        "points": 3750.27,
        "variation": 0.07
      },
      "NASDAQ": {
        "name": "NASDAQ Stock Market",
        "location": "New York City, United States",
        "points": 26522.55,
        "variation": 0.39
      },
      "DOWJONES": {
        "name": "Dow Jones Industrial Average",
        "location": "New York City, United States",
        "points": 51682.64,
        "variation": -0.18
      },
      "CAC": {
        "name": "CAC 40",
        "location": "Paris, French",
        "points": 8065.02,
        "variation": -1.49
      },
      "NIKKEI": {
        "name": "Nikkei 225",
        "location": "Tokyo, Japan",
        "points": 65018.95,
        "variation": 1.38
      }
    },
    "available_sources": [
      "BRL"
    ],
    "bitcoin": {
      "blockchain_info": {
        "name": "Blockchain.info",
        "format": [
          "USD",
          "en_US"
        ],
        "last": 81258.79,
        "buy": 81258.79,
        "sell": 81258.79,
        "variation": 0.115
      },
      "bitstamp": {
        "name": "BitStamp",
        "format": [
          "USD",
          "en_US"
        ],
        "last": 81191.54,
        "buy": 81201.09,
        "sell": 81201.08,
        "variation": -0.001
      },
      "foxbit": {
        "name": "FoxBit",
        "format": [
          "BRL",
          "pt_BR"
        ],
        "last": 418939,
        "variation": 0.009
      },
      "mercadobitcoin": {
        "name": "Mercado Bitcoin",
        "format": [
          "BRL",
          "pt_BR"
        ],
        "last": 419507,
        "buy": 419506,
        "sell": 419507,
        "variation": 0.05
      }
    },
    "taxes": [
      {
        "date": "2026-09-18",
        "cdi": 14.25,
        "selic": 14.25,
        "daily_factor": 0,
        "selic_daily": 14.15,
        "cdi_daily": 14.15
      }
    ]
  },
  "execution_time": 0,
  "from_cache": true
}
```

### Campos

Os dados referentes à consulta chegam no parâmetro `results`, você também pode conferir a autenticação de sua chave no parâmetro de retorno `valid_key`.

<field-group>
<field name="currencies" type="object">

Cotação das moedas.

<table>
<thead>
  <tr>
    <th>
      Campo
    </th>
    
    <th>
      Tipo
    </th>
    
    <th>
      Descrição
    </th>
    
    <th>
      Exemplo
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        source
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          string
        </span>
      </code>
    </td>
    
    <td>
      Código ISO da moeda base da cotação.
    </td>
    
    <td>
      BRL
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [iso]
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          object
        </span>
      </code>
    </td>
    
    <td>
      Código ISO da moeda destino.
    </td>
    
    <td>
      USD
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [iso].name
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          string
        </span>
      </code>
    </td>
    
    <td>
      Nome da moeda.
    </td>
    
    <td>
      Dollar
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [iso].buy
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Valor de compra.
    </td>
    
    <td>
      5.7276
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [iso].sell
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Valor de venda.
    </td>
    
    <td>
      5.7274
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [iso].variation
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Variação em percentual referente à última hora útil anterior.
    </td>
    
    <td>
      -0.021
    </td>
  </tr>
</tbody>
</table>
</field>

<field name="stocks" type="object">

Posições dos principais mercados.

<table>
<thead>
  <tr>
    <th>
      Campo
    </th>
    
    <th>
      Tipo
    </th>
    
    <th>
      Descrição
    </th>
    
    <th>
      Exemplo
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        [index]
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          object
        </span>
      </code>
    </td>
    
    <td>
      Dados do índice de mercado.
    </td>
    
    <td>
      Ibovespa
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [index].name
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          string
        </span>
      </code>
    </td>
    
    <td>
      Nome do índice.
    </td>
    
    <td>
      BM&F BOVESPA
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [index].location
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          string
        </span>
      </code>
    </td>
    
    <td>
      Localização do mercado.
    </td>
    
    <td>
      Sao Paulo, Brazil
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [index].points
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Pontos (somente Ibovespa).
    </td>
    
    <td>
      126571.9
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [index].variation
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Variação em percentual referente à última hora útil anterior.
    </td>
    
    <td>
      -0.44
    </td>
  </tr>
</tbody>
</table>
</field>

<field name="bitcoin" type="object">

Cotação do Bitcoin nas principais corretoras.

<table>
<thead>
  <tr>
    <th>
      Campo
    </th>
    
    <th>
      Tipo
    </th>
    
    <th>
      Descrição
    </th>
    
    <th>
      Exemplo
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        [broker]
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          object
        </span>
      </code>
    </td>
    
    <td>
      Dados da corretora.
    </td>
    
    <td>
      blockchain_info
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [broker].name
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          string
        </span>
      </code>
    </td>
    
    <td>
      Nome da corretora.
    </td>
    
    <td>
      Blockchain.info
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [broker].format
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="sE6NF">
          Array
        </span>
      </code>
    </td>
    
    <td>
      Array com moeda base e idioma da moeda.
    </td>
    
    <td>
      <code className="language-json shiki shiki-themes one-light one-dark-pro one-dark-pro" language="json" style="">
        <span class="sFmRJ">
          [
        </span>
        
        <span class="s8ZqH">
          "USD"
        </span>
        
        <span class="sFmRJ">
          ,
        </span>
        
        <span class="s8ZqH">
          "en_US"
        </span>
        
        <span class="sFmRJ">
          ]
        </span>
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [broker].last
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Última posição (cotação atual).
    </td>
    
    <td>
      93989.45
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [broker].buy
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Valor para compra (pode não estar disponível).
    </td>
    
    <td>
      93989.45
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [broker].sell
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Valor para venda (pode não estar disponível).
    </td>
    
    <td>
      93989.45
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [broker].variation
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Variação em percentual referente à última hora útil anterior.
    </td>
    
    <td>
      -1.245
    </td>
  </tr>
</tbody>
</table>
</field>

<field name="taxes" type="array">

Taxas de juros do Brasil.

<table>
<thead>
  <tr>
    <th>
      Campo
    </th>
    
    <th>
      Tipo
    </th>
    
    <th>
      Descrição
    </th>
    
    <th>
      Exemplo
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        [].date
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          string
        </span>
      </code>
    </td>
    
    <td>
      Data de referência.
    </td>
    
    <td>
      2025-02-27
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [].cdi
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Taxa CDI em percentual.
    </td>
    
    <td>
      13.25
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [].selic
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Taxa Selic em percentual.
    </td>
    
    <td>
      13.25
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [].daily_factor
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Fator diário.
    </td>
    
    <td>
      1.00049037
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [].selic_daily
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Taxa Selic diária em percentual.
    </td>
    
    <td>
      13.15
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        [].cdi_daily
      </code>
    </td>
    
    <td>
      <code className="language-ts-type shiki shiki-themes one-light one-dark-pro one-dark-pro" language="ts-type" style="">
        <span class="s3iYH">
          number
        </span>
      </code>
    </td>
    
    <td>
      Taxa CDI diária em percentual.
    </td>
    
    <td>
      13.15
    </td>
  </tr>
</tbody>
</table>
</field>
</field-group>
