telegram working
This commit is contained in:
@ -7,6 +7,7 @@ import asyncio
|
||||
from telegram import Bot
|
||||
from telegram.constants import ParseMode
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@ -23,20 +24,6 @@ TELEGRAM_BOT_TOKEN = "6805059978:AAHNJKuOeazMSJHc3-BXRCsFfEVyFHeFnjw"
|
||||
# Initialize Telegram Bot
|
||||
bot = Bot(token=TELEGRAM_BOT_TOKEN)
|
||||
|
||||
# Token addresses (to be populated dynamically)
|
||||
TOKEN_ADDRESSES = {}
|
||||
|
||||
async def get_token_balance(wallet_address, token_address):
|
||||
try:
|
||||
balance = await solana_client.get_token_account_balance(
|
||||
Pubkey.from_string(token_address),
|
||||
commitment=Confirmed
|
||||
)
|
||||
return float(balance['result']['value']['uiAmount'])
|
||||
except Exception as e:
|
||||
print(f"Error getting balance for {token_address}: {str(e)}")
|
||||
return 0
|
||||
|
||||
async def send_telegram_message(message):
|
||||
try:
|
||||
await bot.send_message(chat_id=DEVELOPER_CHAT_ID, text=message, parse_mode=ParseMode.HTML)
|
||||
@ -99,18 +86,40 @@ async def follow_move():
|
||||
'message': f"Insufficient balance to swap {amount_to_swap:.6f} {move['token']}"
|
||||
})
|
||||
|
||||
|
||||
|
||||
# Token addresses (to be populated dynamically)
|
||||
TOKEN_ADDRESSES = {}
|
||||
|
||||
async def get_token_balance(wallet_address, token_address):
|
||||
try:
|
||||
balance = await solana_client.get_token_account_balance(
|
||||
Pubkey.from_string(token_address),
|
||||
commitment=Confirmed
|
||||
)
|
||||
logging.debug(f"Balance for {token_address}: {balance}")
|
||||
return float(balance['result']['value']['uiAmount'])
|
||||
except Exception as e:
|
||||
logging.error(f"Error getting balance for {token_address}: {str(e)}")
|
||||
return 0
|
||||
|
||||
async def get_wallet_balances(wallet_address):
|
||||
balances = {}
|
||||
logging.info(f"Getting balances for wallet: {wallet_address}")
|
||||
for token, address in TOKEN_ADDRESSES.items():
|
||||
balances[token] = await get_token_balance(wallet_address, address)
|
||||
balance = await get_token_balance(wallet_address, address)
|
||||
balances[token] = balance
|
||||
logging.debug(f"Balance for {token}: {balance}")
|
||||
return balances
|
||||
|
||||
async def get_non_zero_token_balances(wallet_address):
|
||||
non_zero_balances = {}
|
||||
logging.info(f"Getting non-zero balances for wallet: {wallet_address}")
|
||||
for token, address in TOKEN_ADDRESSES.items():
|
||||
balance = await get_token_balance(wallet_address, address)
|
||||
if balance > 0:
|
||||
non_zero_balances[token] = address
|
||||
logging.debug(f"Non-zero balance for {token}: {balance}")
|
||||
return non_zero_balances
|
||||
|
||||
async def list_initial_wallet_states():
|
||||
|
Reference in New Issue
Block a user