debug logs again
This commit is contained in:
@ -44,8 +44,8 @@ load_dotenv()
|
||||
load_dotenv('.env.secret') # ToDo - make it work
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
# logging.basicConfig(level=logging.DEBUG)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
#logging.basicConfig(level=logging.INFO)
|
||||
|
||||
# Set up error logger
|
||||
log_dir = './logs'
|
||||
@ -1018,19 +1018,20 @@ async def follow_move(move):
|
||||
amount_to_swap = your_balance * (move['percentage_swapped'] / 100)
|
||||
|
||||
# # always get 99% of the amount to swap
|
||||
# amount_to_swap = amount_to_swap * 0.99
|
||||
amount_to_swap = amount_to_swap * 0.95
|
||||
|
||||
# Convert to lamports
|
||||
# if decimals is 6, then amount = amount * 1e6; if 9, then amount = amount * 1e9
|
||||
amount = int(amount_to_swap * 10**token_info.get('decimals') )
|
||||
|
||||
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."
|
||||
f"Insufficient balance: {your_balance:.6f} {token_name_in}. We want to swap {amount_to_swap:.6f}\n({move['symbol_in']}, decimals {token_info.get('decimals')} amount {amount}).\n This will probably fail. But we will try anyway."
|
||||
)
|
||||
logging.warning(msg)
|
||||
await send_telegram_message(msg)
|
||||
try:
|
||||
# Convert to lamports
|
||||
# if decimals is 6, then amount = amount * 1e6; if 9, then amount = amount * 1e9
|
||||
amount = int(amount_to_swap * 10**token_info.get('decimals') )
|
||||
|
||||
try:
|
||||
notification = (
|
||||
@ -1105,14 +1106,20 @@ async def follow_move(move):
|
||||
# log the errors to /logs/errors.log
|
||||
error_logger.error(error_message)
|
||||
error_logger.exception(e)
|
||||
# await send_telegram_message(error_message)
|
||||
await send_telegram_message(error_message)
|
||||
|
||||
|
||||
# Helper functions (implement these according to your needs)
|
||||
|
||||
|
||||
|
||||
|
||||
async def heartbeat(websocket):
|
||||
while True:
|
||||
try:
|
||||
await websocket.ping()
|
||||
await asyncio.sleep(PING_INTERVAL)
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
break
|
||||
|
||||
async def subscribe_to_wallet():
|
||||
SOLANA_ENDPOINTS = [
|
||||
@ -1127,9 +1134,11 @@ async def subscribe_to_wallet():
|
||||
|
||||
while True:
|
||||
try:
|
||||
async with websockets.connect(uri) as websocket:
|
||||
async with websockets.connect(uri, ping_interval=30, ping_timeout=20) as websocket:
|
||||
logger.info("Connected to Solana websocket")
|
||||
|
||||
heartbeat_task = asyncio.create_task(heartbeat(websocket))
|
||||
|
||||
subscription_id = await load_subscription_id()
|
||||
|
||||
request = {
|
||||
@ -1181,6 +1190,9 @@ async def subscribe_to_wallet():
|
||||
logger.error(f"An unexpected error occurred: {e}")
|
||||
break
|
||||
|
||||
# Cancel the heartbeat task when the connection is closed
|
||||
heartbeat_task.cancel()
|
||||
|
||||
except websockets.exceptions.WebSocketException as e:
|
||||
logger.error(f"WebSocket error: {e}")
|
||||
except Exception as e:
|
||||
|
Reference in New Issue
Block a user