trading-quant/utils.py
2024-06-06 22:48:51 +08:00

43 lines
1.2 KiB
Python

import requests
# 获取市值前10的币种
def get_top_coins_by_market_cap(top):
coingecko_url = "https://api.coingecko.com/api/v3/coins/markets"
params = {
'vs_currency': 'usd',
'order': 'market_cap_desc',
'per_page': top,
'page': 1
}
response = requests.get(coingecko_url, params=params)
coins = response.json()
return coins
# 获取Binance上的USDT交易对信息
def get_binance_usdt_pairs():
url = "https://api.binance.com/api/v3/exchangeInfo"
response = requests.get(url)
data = response.json()
usdt_pairs = [symbol['symbol'] for symbol in data['symbols'] if (symbol['quoteAsset'] == 'USDT' and symbol['status'] == 'TRADING')]
return usdt_pairs
def get_top_binance_usdt_pairs(top):
# 获取市值前10的币种
top_coins = get_top_coins_by_market_cap(top)
# 获取Binance上的USDT交易对
usdt_pairs = get_binance_usdt_pairs()
# 筛选出前10币种中与USDT有交易对的币种
top_pairs = []
for coin in top_coins:
coin_symbol = coin['symbol'].upper()
pair = f"{coin_symbol}USDT"
if pair in usdt_pairs:
top_pairs.append(pair)
return top_pairs