KF - API
The Kingfisher API allows access to all of the Kingfisher's Liq Maps and GEX+
Last updated
The Kingfisher API allows access to all of the Kingfisher's Liq Maps and GEX+
Last updated
HOST='https://thekingfisher.io'
LOGIN="your_kf_login"
KEY="your_kf_password"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')
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)