update follow

This commit is contained in:
Dobromir Popov 2024-10-02 17:55:54 +03:00
parent 45847a3f51
commit 12302961a8

View File

@ -167,6 +167,39 @@ async def follow_move(move):
proportion = your_balance / followed_balance if followed_balance > 0 else 0
amount_to_swap = move['amount'] * proportion
if your_balance >= amount_to_swap:
# Implement actual swap logic here
pair = dexscreener_client.get_token_pair("solana", move['token'])
price = float(pair['priceUsd'])
received_amount = amount_to_swap * price
message = (
f"<b>Move Followed:</b>\n"
f"Swapped {amount_to_swap:.6f} {move['token']} "
f"for {received_amount:.6f} {move['to_token']}"
)
logging.info(message)
await send_telegram_message(message)
else:
message = (
f"<b>Move Failed:</b>\n"
f"Insufficient balance to swap {amount_to_swap:.6f} {move['token']}"
)
logging.warning(message)
await send_telegram_message(message)
followed_balances = await get_wallet_balances(FOLLOWED_WALLET)
your_balances = await get_wallet_balances(YOUR_WALLET)
if move['token'] not in followed_balances or move['token'] not in your_balances:
logging.error(f"Invalid token: {move['token']}")
return
followed_balance = followed_balances[move['token']]
your_balance = your_balances[move['token']]
proportion = your_balance / followed_balance if followed_balance > 0 else 0
amount_to_swap = move['amount'] * proportion
if your_balance >= amount_to_swap:
# Implement actual swap logic here
pair = dexscreener_client.get_token_pair("solana", move['token'])
@ -189,8 +222,8 @@ async def follow_move(move):
await send_telegram_message(message)
async def on_logs(log):
print(f"Received log: {log}")
try:
print(f"Received log: {log}")
if 'err' in log and log['err']:
return
@ -222,10 +255,15 @@ async def on_logs(log):
'to_token': 'Unknown' # You might want to determine this based on the receiving address
}
await follow_move(move)
# Send a Telegram message about the swap
message_text = f"Swap detected:\nFrom: {from_pubkey}\nTo: {to_pubkey}\nAmount: {amount} SOL"
await send_telegram_message(message_text)
else:
print(f"Unexpected log format: {log}")
except:
print(f"error logging: {log}")
print(f"error processing RPC log")
async def subscribe_to_wallet():
uri = SOLANA_URL
async with websockets.connect(uri) as websocket: