Tool: validate_credentials.py - verifyze Binance API + Telegram Bot Tokens automatisiert (2026-07-10 16:40)
This commit is contained in:
parent
4b0cd1457c
commit
e3afd5d40e
|
|
@ -0,0 +1,105 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Validiere alle Credentials (Binance API + Telegram Bot)
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Change to bot directory FIRST
|
||||||
|
os.chdir('/home/marc/bot-deploy')
|
||||||
|
|
||||||
|
# Dann .env laden
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv(dotenv_path='/home/marc/bot-deploy/.env')
|
||||||
|
|
||||||
|
binance_key = os.getenv('BINANCE_API_KEY_LIVE')
|
||||||
|
binance_secret = os.getenv('BINANCE_API_SECRET_LIVE')
|
||||||
|
telegram_token = os.getenv('TELEGRAM_BOT_TOKEN')
|
||||||
|
chat_id = os.getenv('TELEGRAM_CHAT_ID')
|
||||||
|
|
||||||
|
print('🔍 VALIDIERE CREDENTIALS...\n')
|
||||||
|
|
||||||
|
# Test 1: Binance API
|
||||||
|
print('1️⃣ BINANCE API')
|
||||||
|
try:
|
||||||
|
from binance.client import Client
|
||||||
|
client = Client(binance_key, binance_secret)
|
||||||
|
|
||||||
|
# Test read
|
||||||
|
account = client.get_account()
|
||||||
|
print(f' ✅ Connected')
|
||||||
|
|
||||||
|
# Get balances
|
||||||
|
balances = [b for b in account['balances'] if float(b['free']) + float(b['locked']) > 0]
|
||||||
|
usdt = next((b for b in account['balances'] if b['asset'] == 'USDT'), None)
|
||||||
|
|
||||||
|
print(f' ✅ Balances gelesen: {len(balances)} coins')
|
||||||
|
print(f' ✅ USDT: {float(usdt["free"]):.2f} (free) + {float(usdt["locked"]):.2f} (locked)')
|
||||||
|
|
||||||
|
# Test: Get symbol info (dry, kein order)
|
||||||
|
symbol_info = client.get_symbol_info('BTCUSDT')
|
||||||
|
print(f' ✅ Symbol Info abrufbar')
|
||||||
|
|
||||||
|
# Test: Ping
|
||||||
|
ping = client.ping()
|
||||||
|
print(f' ✅ API Ping: OK')
|
||||||
|
|
||||||
|
print(f' ✅ Authentifizierung: ACTIVE (Keys working)')
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f' ❌ FAILED: {str(e)[:100]}')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Test 2: Telegram Bot
|
||||||
|
print('\n2️⃣ TELEGRAM BOT')
|
||||||
|
try:
|
||||||
|
import requests
|
||||||
|
|
||||||
|
url = f'https://api.telegram.org/bot{telegram_token}/getMe'
|
||||||
|
response = requests.get(url, timeout=10)
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
print(f' ❌ HTTP {response.status_code}')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
bot_info = response.json()
|
||||||
|
if not bot_info.get('ok'):
|
||||||
|
print(f' ❌ API Error: {bot_info}')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print(f' ✅ Connected')
|
||||||
|
print(f' ✅ Bot Name: @{bot_info["result"]["username"]}')
|
||||||
|
print(f' ✅ Bot ID: {bot_info["result"]["id"]}')
|
||||||
|
|
||||||
|
# Test send message
|
||||||
|
send_url = f'https://api.telegram.org/bot{telegram_token}/sendMessage'
|
||||||
|
payload = {
|
||||||
|
'chat_id': chat_id,
|
||||||
|
'text': '✅ Credentials TEST — Alle APIs funktionieren!'
|
||||||
|
}
|
||||||
|
send_response = requests.post(send_url, json=payload, timeout=10)
|
||||||
|
|
||||||
|
if send_response.status_code == 200:
|
||||||
|
result = send_response.json()
|
||||||
|
if result.get('ok'):
|
||||||
|
msg_id = result['result']['message_id']
|
||||||
|
print(f' ✅ Test Message versendet (ID: {msg_id})')
|
||||||
|
else:
|
||||||
|
print(f' ❌ Send Error: {result}')
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print(f' ❌ HTTP {send_response.status_code}')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f' ❌ FAILED: {str(e)[:100]}')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print('\n' + '='*70)
|
||||||
|
print('✅ ALLE CREDENTIALS VALIDIERT UND FUNKTIONSFÄHIG!')
|
||||||
|
print('='*70)
|
||||||
|
print('\nDetails:')
|
||||||
|
print(f' BINANCE_API_KEY_LIVE: {len(binance_key)} chars ✅')
|
||||||
|
print(f' BINANCE_API_SECRET_LIVE: {len(binance_secret)} chars ✅')
|
||||||
|
print(f' TELEGRAM_BOT_TOKEN: {len(telegram_token)} chars ✅')
|
||||||
|
print(f' TELEGRAM_CHAT_ID: {chat_id} ✅')
|
||||||
Loading…
Reference in New Issue