# Hệ thống lấy giá cao nhất và thấp nhất từ Binance cho 100 đồng coin vốn hóa lớn nhất
import requests
import pandas as pd
from datetime import datetime
# ========== PHẦN 1: LẤY DANH SÁCH 100 COIN VỐN HÓA LỚN ==========
# Dữ liệu được lấy từ CoinGecko API (vì không dùng được ccxt)
def get_top_100_symbols():
url = "https://api.coingecko.com/api/v3/coins/markets"
params = {
"vs_currency": "usd",
"order": "market_cap_desc",
"per_page": 100,
"page": 1,
"sparkline": False
}
response = requests.get(url, params=params)
coins = response.json()
symbols = [coin['symbol'].upper() + "/USDT" for coin in coins]
return symbols
# ========== PHẦN 2: LẤY GIÁ CAO NHẤT & THẤP NHẤT QUA BINANCE API ==========
# Sử dụng trực tiếp Binance REST API để tránh dùng ccxt hoặc streamlit
BINANCE_BASE_URL = "https://api.binance.com/api/v3/klines"
def get_high_low(symbol, interval="1d", limit=90):
symbol_formatted = symbol.replace("/", "") # BTC/USDT -> BTCUSDT
params = {
"symbol": symbol_formatted,
"interval": interval,
"limit": limit
}
try:
response = requests.get(BINANCE_BASE_URL, params=params)
data = response.json()
highs = [float(entry[2]) for entry in data]
lows = [float(entry[3]) for entry in data]
return {
'symbol': symbol,
'high': max(highs),
'low': min(lows)
}
except Exception as e:
print(f"Lỗi khi lấy dữ liệu {symbol}: {e}")
return {
'symbol': symbol,
'high': None,
'low': None
}
# ========== PHẦN 3: TỔNG HỢP DỮ LIỆU 100 COIN ==========
def get_top_100_high_low():
symbols = get_top_100_symbols()
data = [get_high_low(symbol) for symbol in symbols if symbol.endswith("USDT")]
df = pd.DataFrame(data)
return df
# ========== PHẦN 4: CHẠY Ở CHẾ ĐỘ CLI ==========
def main():
print("Đang tải dữ liệu từ Binance cho 100 coin vốn hóa lớn...")
df = get_top_100_high_low()
print("\nGiá cao nhất và thấp nhất trong 3 ngày gần nhất:")
print(df.to_string(index=False))
if __name__ == '__main__':
main()
Tín hiệu
Short Signal Auto Scorer
Written tháng 6 28, 2025 by Nguyễn Hiền
No commentsGiao thức short
Short Signal Evaluator
Written tháng 6 28, 2025 by Nguyễn Hiền
No comments
Đăng ký:
Nhận xét (Atom)