import json
import os

# 取得當前腳本的資料夾路徑
current_directory = os.path.dirname(os.path.realpath(__file__))
json_file_path = os.path.join(current_directory, 'arbitrage_pairs.json')

# 載入 JSON 檔案
with open(json_file_path, 'r', encoding='utf-8') as f:
    data = json.load(f)

# 初始化
total_count = len(data)
positive_count = 0
negative_count = 0
funding_total = 0
funding_positive_total = 0
funding_negative_total = 0

# 分析每一筆資料
for item in data:
    apy = float(item['funding_apy'])
    funding_total += apy
    if apy > 0:
        positive_count += 1
        funding_positive_total += apy
    elif apy < 0:
        negative_count += 1
        funding_negative_total += apy

# 計算平均值
average_apy = funding_total / total_count if total_count else 0
average_positive_apy = funding_positive_total / positive_count if positive_count else 0
average_negative_apy = funding_negative_total / negative_count if negative_count else 0

# 輸出結果
print(f"幣種總數量: {total_count}")
print(f"funding_apy 為正的數量: {positive_count}")
print(f"funding_apy 為負的數量: {negative_count}")
print(f"funding_apy 平均值: {average_apy:.4f}")
print(f"funding_apy 為正的平均: {average_positive_apy:.4f}")
print(f"funding_apy 為負的平均: {average_negative_apy:.4f}")
