myTestFreqAI/tools/listpairs.sh

38 lines
1.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# OKX API 端点
API_URL="https://www.okx.com/api/v5/market/tickers?instType=SPOT"
# 发送请求并获取数据
response=$(curl -s -X GET "$API_URL" -H "accept: application/json")
# 检查请求是否成功
if [ -z "$response" ]; then
echo "错误:无法获取 API 数据,请检查网络连接或 API 端点。"
exit 1
fi
# 解析 JSON 数据,只保留-USDT交易对提取 instId 和 volCcy24h按 volCcy24h 降序排序,取前 50 个
pairs=$(echo "$response" | jq -r '.data | map(select(.instId | endswith("-USDT"))) | sort_by(.volCcy24h | tonumber) | reverse | .[0:50] | .[] | [.instId, .volCcy24h] | @csv')
# 检查是否成功解析数据
if [ -z "$pairs" ]; then
echo "错误:无法解析 API 返回的 JSON 数据或没有找到-USDT交易对请检查响应格式。"
exit 1
fi
# 格式化输出
echo "OKX 交易所当前交易量最高的 USDT 现货交易对(按 24 小时交易量降序排序):"
echo "排名,交易对,24小时交易量(USDT)"
echo "---------------------------------------------"
index=1
echo "$pairs" | while IFS=, read -r instId volCcy24h; do
# 去除引号并格式化输出
instId=$(echo "$instId" | tr -d '"')
volCcy24h=$(echo "$volCcy24h" | tr -d '"')
printf "%-5s %-15s %s\n" "$index" "$instId" "$volCcy24h"
((index++))
done
exit 0