> For the complete documentation index, see [llms.txt](https://crypto.phbot.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://crypto.phbot.org/python/api.md).

# API

## `get_bars(exchange, pair, granularity)`

This function retrieves historical bars for a given pair from an exchange. Granularity is in seconds.

### **Usage**

`get_bars(EX_COINBASE, 'BTC-USD', 60)`

### **Returns**

`None` or a `list` containing the historical bars in JSON.

```json
[{
   't': 1663858740,
   'o': 18865.76,
   'h': 18891.17,
   'l': 18855.5,
   'c': 18879.53,
   'v': 41.84053623
}, {
   't': 1663858680,
   'o': 18893.84,
   'h': 18900.26,
   'l': 18862.77,
   'c': 18866.74,
   'v': 41.47941474
}, {
   't': 1663858620,
   'o': 18896.58,
   'h': 18904.81,
   'l': 18882.33,
   'c': 18892.81,
   'v': 50.05292682
}, {
   't': 1663858560,
   'o': 18908.72,
   'h': 18917.8,
   'l': 18878.35,
   'c': 18898.82,
   'v': 29.25498139
}, {
   't': 1663858500,
   'o': 18911.94,
   'h': 18912.82,
   'l': 18883.5,
   'c': 18909.35,
   'v': 38.71486704
}

...etc

]
```

## `get_dominance()`

This function returns the Bitcoin and Ethereum dominance values from [CoinMarketCap](https://coinmarketcap.com/api/pricing/). A CMC API key must be configured in the `phBot.ini`file.

### Usage

`get_dominance()`

### Returns

`None`or a `dict` containing dominance data from CMC. Data is cached for 2 minutes before being refreshed.

```
{
   "btc_dominance":54.95772073293,
   "eth_dominance":13.109460109462,
   "btc_dominance_24h_percentage_change":0.13599359293,
   "eth_dominance_24h_percentage_change":0.148275599462,
   "btc_dominance_yesterday":54.82172714,
   "eth_dominance_yesterday":12.96118451,
   "last_updated":"2024-12-13T05:14:59.999Z"
}
```

## `get_fear_greed()`

This function returns the crypto fear and greed index from CoinMarketCap.

### Usage

`get_fear_greed()`

### Returns

`None`or a `dict`containing the latest fear/greed index from CMC. Data is cached for 2 minutes before being refreshed.

```
{
   "timestamp":1733961600,
   "value":80,
   "classification":"Extreme greed"
}
```
