From e3afd5d40e3ec599213ac02b7e20f3368af8e92d Mon Sep 17 00:00:00 2001 From: Marc Blatter Date: Fri, 10 Jul 2026 19:46:45 +0200 Subject: [PATCH] Tool: validate_credentials.py - verifyze Binance API + Telegram Bot Tokens automatisiert (2026-07-10 16:40) --- src/validate_credentials.py | 105 ++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/validate_credentials.py diff --git a/src/validate_credentials.py b/src/validate_credentials.py new file mode 100644 index 0000000..ec52317 --- /dev/null +++ b/src/validate_credentials.py @@ -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} βœ…')