try even if we report no ballance

This commit is contained in:
Dobromir Popov 2024-10-09 14:11:47 +03:00
parent 3471f6aa6d
commit 12769cd3cc

View File

@ -58,8 +58,6 @@ error_logger.setLevel(logging.ERROR)
error_logger.addHandler(error_file_handler) error_logger.addHandler(error_file_handler)
app = Flask(__name__) app = Flask(__name__)
ENV_FILE = '.env' ENV_FILE = '.env'
@ -990,6 +988,12 @@ async def follow_move(move):
# amount_to_swap = amount_to_swap * 0.99 # amount_to_swap = amount_to_swap * 0.99
if your_balance >= amount_to_swap: if your_balance >= amount_to_swap:
msg = (
f"<b>Warning:</b>\n"
f"We have {your_balance:.6f} {token_name_in}. Insufficient balance to swap {amount_to_swap:.6f} ({move['token_in']}). This will probably fail. But we will try anyway."
)
logging.warning(msg)
await send_telegram_message(msg)
try: try:
# Convert to lamports # Convert to lamports
# if decimals is 6, then amount = amount * 1e6; if 9, then amount = amount * 1e9 # if decimals is 6, then amount = amount * 1e6; if 9, then amount = amount * 1e9
@ -1068,13 +1072,13 @@ async def follow_move(move):
error_logger.error(error_message) error_logger.error(error_message)
error_logger.exception(e) error_logger.exception(e)
# await send_telegram_message(error_message) # await send_telegram_message(error_message)
else: # else:
msg = ( # msg = (
f"<b>Move Not Followed:</b>\n" # f"<b>Move Not Followed:</b>\n"
f"Insufficient balance to swap {amount_to_swap:.6f} {token_name_in} ({move['token_in']})" # f"Insufficient balance to swap {amount_to_swap:.6f} {token_name_in} ({move['token_in']})"
) # )
logging.warning(msg) # logging.warning(msg)
await send_telegram_message(msg) # await send_telegram_message(msg)
# Helper functions (implement these according to your needs) # Helper functions (implement these according to your needs)
@ -1181,7 +1185,6 @@ if not pk:
async def main(): async def main():
# Initialize logging
await send_telegram_message("Solana Agent Started. Connecting to mainnet...") await send_telegram_message("Solana Agent Started. Connecting to mainnet...")
asyncio.create_task( list_initial_wallet_states()) asyncio.create_task( list_initial_wallet_states())
await subscribe_to_wallet() await subscribe_to_wallet()