# KF - API

## Apply for API access

To access the Kingfisher's API, you need to fill an application form. Upon reception, we'll get in touch with you.

On <http://alpha.thekingfisher.io>, click "Subscription" --> API Access --> Apply for API Access

<figure><img src="/files/WPTKTb6cGBfXZvcXYR0U" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/LWA96oaGYHjbpb0esi9U" alt=""><figcaption></figcaption></figure>

Upon reception of the form, the Kingfisher team will get in touch with you.&#x20;

Once your access becomes active, refer to the following section to effectively make use of the KF API.

## API Usage

See below a crude API connector.

Note: Make sure to create a .env with

```
HOST='https://thekingfisher.io'
LOGIN="your_kf_login"
KEY="your_kf_password"
```

```python
import requests
import os
import json
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())

# in .env
# HOST='https://thekingfisher.io'
# LOGIN="your_kf_login"
# KEY="your_kf_password"


class KingfisherController(object):

    def __init__(self):
        self.users = []
        self.token = ""
        self.headers = {}
        self.keys = []
        self.login()

    def login(self):
       login_response = requests.post(HOST + "/api/auth/login", data={"login": LOGIN, "password": KEY})
       if(login_response.status_code):
        self.token = (login_response.json()['token'])
        self.headers = {'Authorization': 'Bearer ' + self.token}
        
    def get_last_map(self, exchange, pair, type):
        data = {'exchange': exchange, 'pair': pair, 'type': type}
        return requests.post(HOST + '/api/private/map/latest',json=data, headers=self.headers).json()
    
    # Being reworked, coming back soon
    def get_ts_map(self, exchange, pair, ts, type):
        data = {'exchange': exchange, 'pair': pair, 'ts' : ts,'type': type}
        return requests.post(HOST + '/api/private/map/timestamp',json=data, headers=self.headers).json()
    
def plot_data (data):
    prices = []
    rel_str = []
    for cluster in data:
        if cluster not in ['Cummulated short liqs','Cummulated long liqs']:
            prices += data[cluster][0]
            rel_str += data[cluster][1]
            
    import plotly.express as px
    plot = px.histogram(x=prices, labels={'x': 'Price'}, y=rel_str, nbins = len(prices))
    plot.show()
    
if __name__ == '__main__':
    kf_control = KingfisherController()
    resp = kf_control.get_ts_map('binance', 'BTC/USDT', time.time(), 'all_leverage')
    data = resp['result']['data']
    plot_data(data)
    # plot histogram with plotly of data
    
    resp = kf_control.get_last_map('binance', 'BTC/USDT', 'high_leverage')

```

To improve data readability, we recommend flattening the liqmap. The response contains multiple clusters, including noise, which helps with color representation in UX design. However, for GMM, KDE, or statistical analysis, this can be inconvenient and make data manipulation more difficult.

```python
 import pandas as pd
 
 def process_data(self, data):
            flattened_data = []
            for key in data:
                prices, density = data[key]
                flattened_data.extend([{'price': p, 'density': d} for p, d in zip(prices, density) if d != 0])
            return pd.DataFrame(flattened_data)
```


---

# Agent Instructions: 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:

```
GET https://docs.thekingfisher.io/products/kf-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
