follow move works
This commit is contained in:
parent
2a15df144c
commit
c16129bcf0
@ -210,14 +210,16 @@ async def get_sol_price() -> float:
|
||||
|
||||
async def convert_balances_to_currency(balances, token_prices, sol_price):
|
||||
converted_balances = {}
|
||||
for token, amount in balances.items():
|
||||
if token == 'SOL':
|
||||
converted_balances[token] = amount * sol_price
|
||||
elif token in token_prices:
|
||||
converted_balances[token] = amount * token_prices[token]
|
||||
for address, info in balances.items():
|
||||
converted_balance = info.copy() # Create a copy of the original info
|
||||
if info['name'] == 'SOL':
|
||||
converted_balance['value'] = info['amount'] * sol_price
|
||||
elif address in token_prices:
|
||||
converted_balance['value'] = info['amount'] * token_prices[address]
|
||||
else:
|
||||
converted_balances[token] = None # Price not available
|
||||
logging.warning(f"Price not available for token {token}")
|
||||
converted_balance['value'] = None # Price not available
|
||||
logging.warning(f"Price not available for token {info['name']} ({address})")
|
||||
converted_balances[address] = converted_balance
|
||||
return converted_balances
|
||||
|
||||
|
||||
@ -374,50 +376,6 @@ async def list_initial_wallet_states():
|
||||
|
||||
logging.info(message)
|
||||
await send_telegram_message(message)
|
||||
global TOKEN_ADDRESSES, FOLLOWED_WALLET_VALUE, YOUR_WALLET_VALUE
|
||||
|
||||
followed_wallet_balances = await get_wallet_balances(FOLLOWED_WALLET)
|
||||
your_wallet_balances = await get_wallet_balances(YOUR_WALLET)
|
||||
|
||||
all_token_addresses = list(set(followed_wallet_balances.keys()) | set(your_wallet_balances.keys()))
|
||||
token_prices = await get_token_prices(all_token_addresses)
|
||||
sol_price = await get_sol_price()
|
||||
|
||||
followed_converted_balances = await convert_balances_to_currency(followed_wallet_balances, token_prices, sol_price)
|
||||
your_converted_balances = await convert_balances_to_currency(your_wallet_balances, token_prices, sol_price)
|
||||
|
||||
TOKEN_ADDRESSES = {token: amount for token, amount in {**followed_converted_balances, **your_converted_balances}.items() if amount is not None and amount > 0}
|
||||
logging.info(f"Monitoring balances for tokens: {TOKEN_ADDRESSES.keys()}")
|
||||
|
||||
followed_wallet_state = []
|
||||
FOLLOWED_WALLET_VALUE = 0
|
||||
for token, amount in followed_converted_balances.items():
|
||||
if amount is not None and amount > 0:
|
||||
followed_wallet_state.append(f"{token}: {amount:.2f} {DISPLAY_CURRENCY}")
|
||||
FOLLOWED_WALLET_VALUE += amount
|
||||
|
||||
your_wallet_state = []
|
||||
YOUR_WALLET_VALUE = 0
|
||||
for token, amount in your_converted_balances.items():
|
||||
if amount is not None and amount > 0:
|
||||
your_wallet_state.append(f"{token}: {amount:.2f} {DISPLAY_CURRENCY}")
|
||||
YOUR_WALLET_VALUE += amount
|
||||
|
||||
message = (
|
||||
f"<b>Initial Wallet States (All balances in {DISPLAY_CURRENCY}):</b>\n\n"
|
||||
f"<b>Followed Wallet ({FOLLOWED_WALLET}):</b>\n"
|
||||
f"{chr(10).join(followed_wallet_state)}\n"
|
||||
f"<b>Total Value:</b> {FOLLOWED_WALLET_VALUE:.2f} {DISPLAY_CURRENCY}\n\n"
|
||||
f"<b>Your Wallet ({YOUR_WALLET}):</b>\n"
|
||||
f"{chr(10).join(your_wallet_state)}\n"
|
||||
f"<b>Total Value:</b> {YOUR_WALLET_VALUE:.2f} {DISPLAY_CURRENCY}\n\n"
|
||||
f"<b>Monitored Tokens:</b>\n"
|
||||
f"{', '.join(TOKEN_ADDRESSES.keys())}"
|
||||
)
|
||||
|
||||
logging.info(message)
|
||||
await send_telegram_message(message)
|
||||
|
||||
|
||||
async def get_transaction_details_rpc(tx_signature, readfromDump=False):
|
||||
url = SOLANA_HTTP_URL
|
||||
@ -574,7 +532,7 @@ async def parse_swap_logs(logs):
|
||||
|
||||
async def follow_move(move):
|
||||
your_balances = await get_wallet_balances(YOUR_WALLET)
|
||||
your_balance_info = your_balances.get(move['token_in'])
|
||||
your_balance_info = next((balance for balance in your_balances.values() if balance['address'] == move['token_in']), None)
|
||||
|
||||
if not your_balance_info:
|
||||
message = f"<b>Move Failed:</b>\nNo balance found for token {move['token_in']}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user