$BTC
nhập requests
import matplotlib.pyplot as plt
import numpy as np
# 1. Lấy dữ liệu thanh lý từ 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"} # Dán API key của bạn vào đây
params = {
"symbol": symbol,
"exchange": "all",
"timeType": "7d" # Dữ liệu 7 ngày như ảnh chụp màn hình của bạn
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
return data['data']
# 2. Vẽ biểu đồ nhiệt thanh lý
def plot_liquidation_map(data):
prices = data['priceList'] # Các mức giá
long_liq = data['longList'] # Giá trị thanh lý Long
short_liq = data['shortList'] # Giá trị thanh lý Short
current_price = data['currentPrice']
plt.figure(figsize=(14,7))
# Vẽ thanh lý Short - Khu vực màu đỏ ở bên trái
plt.bar(prices, short_liq, color='red', alpha=0.5, label='Short Liquidations')
# Vẽ thanh lý Long - Khu vực màu xanh lá ở bên phải
plt.bar(prices, long_liq, color='green', alpha=0.5, label='Long Liquidations')
# Đường giá hiện tại
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. Cách chạy
if __name__ == "__main__":
print("Đang lấy dữ liệu thanh lý BTC...")
data = get_liquidation_data("BTC")
plot_liquidation_map(data)
nhập requests
import matplotlib.pyplot as plt
import numpy as np
# 1. Lấy dữ liệu thanh lý từ 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"} # Dán API key của bạn vào đây
params = {
"symbol": symbol,
"exchange": "all",
"timeType": "7d" # Dữ liệu 7 ngày như ảnh chụp màn hình của bạn
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
return data['data']
# 2. Vẽ biểu đồ nhiệt thanh lý
def plot_liquidation_map(data):
prices = data['priceList'] # Các mức giá
long_liq = data['longList'] # Giá trị thanh lý Long
short_liq = data['shortList'] # Giá trị thanh lý Short
current_price = data['currentPrice']
plt.figure(figsize=(14,7))
# Vẽ thanh lý Short - Khu vực màu đỏ ở bên trái
plt.bar(prices, short_liq, color='red', alpha=0.5, label='Short Liquidations')
# Vẽ thanh lý Long - Khu vực màu xanh lá ở bên phải
plt.bar(prices, long_liq, color='green', alpha=0.5, label='Long Liquidations')
# Đường giá hiện tại
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. Cách chạy
if __name__ == "__main__":
print("Đang lấy dữ liệu thanh lý BTC...")
data = get_liquidation_data("BTC")
plot_liquidation_map(data)
