$BTC
import requests
import matplotlib.pyplot as plt
import numpy as np
# 1. Get liquidation data from CoinGlass API
def get_liquidation_data(symbol="BTC"):
url = "https://open-api.coinglass.com/api/futures/liquidation/chart"
headers = {"coinglass-api-key": "YOUR_API_KEY"} # Put your API key here
params = {
"symbol": symbol,
"exchange": "all",
"timeType": "7d" # 7 days data like your screenshot
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
return data['data']
# 2. Plot the liquidation heatmap
def plot_liquidation_map(data):
prices = data['priceList'] # Price levels
long_liq = data['longList'] # Long liquidation amounts
short_liq = data['shortList'] # Short liquidation amounts
current_price = data['currentPrice']
plt.figure(figsize=(14,7))
# Plot short liquidations - Red area on left
plt.bar(prices, short_liq, color='red', alpha=0.5, label='Short Liquidations')
# Plot long liquidations - Green area on right
plt.bar(prices, long_liq, color='green', alpha=0.5, label='Long Liquidations')
# Current price line
plt.axvline(x=current_price, color='red', linestyle='--', linewidth=2, label=f'Current Price: ${current_price}')
plt.title("BTC Exchange Liquidation Heatmap", fontsize=16, fontweight='bold')
plt.xlabel("BTC Price (USD)")
plt.ylabel("Liquidation Amount (USD)")
plt.legend()
plt.grid(axis='y', alpha=0.3)
plt.show()
# 3. How to run
if __name__ == "__main__":
print("Fetching BTC liquidation data...")
data = get_liquidation_data("BTC")
plot_liquidation_map(data)
import requests
import matplotlib.pyplot as plt
import numpy as np
# 1. Get liquidation data from CoinGlass API
def get_liquidation_data(symbol="BTC"):
url = "https://open-api.coinglass.com/api/futures/liquidation/chart"
headers = {"coinglass-api-key": "YOUR_API_KEY"} # Put your API key here
params = {
"symbol": symbol,
"exchange": "all",
"timeType": "7d" # 7 days data like your screenshot
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
return data['data']
# 2. Plot the liquidation heatmap
def plot_liquidation_map(data):
prices = data['priceList'] # Price levels
long_liq = data['longList'] # Long liquidation amounts
short_liq = data['shortList'] # Short liquidation amounts
current_price = data['currentPrice']
plt.figure(figsize=(14,7))
# Plot short liquidations - Red area on left
plt.bar(prices, short_liq, color='red', alpha=0.5, label='Short Liquidations')
# Plot long liquidations - Green area on right
plt.bar(prices, long_liq, color='green', alpha=0.5, label='Long Liquidations')
# Current price line
plt.axvline(x=current_price, color='red', linestyle='--', linewidth=2, label=f'Current Price: ${current_price}')
plt.title("BTC Exchange Liquidation Heatmap", fontsize=16, fontweight='bold')
plt.xlabel("BTC Price (USD)")
plt.ylabel("Liquidation Amount (USD)")
plt.legend()
plt.grid(axis='y', alpha=0.3)
plt.show()
# 3. How to run
if __name__ == "__main__":
print("Fetching BTC liquidation data...")
data = get_liquidation_data("BTC")
plot_liquidation_map(data)
