fix tr size, await tg messages

This commit is contained in:
Dobromir Popov 2024-10-15 22:53:29 +03:00
parent 6ab6e301ec
commit 1ee8c6cb0b

View File

@ -816,7 +816,8 @@ async def get_transaction_details_with_retry(transaction_id, retry_delay = 8, ma
break
except Exception as e:
logging.error(f"Error fetching transaction details: {e}")
logging.info(f"({_} of {max_retries}) Waiting for transaction details for {transaction_id}")
retry_delay = retry_delay * 1.2
logging.info(f"({_} of {max_retries}) Waiting for transaction details for {transaction_id}. retry in {retry_delay} s.")
await asyncio.sleep(retry_delay)
return tx_details
@ -886,7 +887,7 @@ async def process_log(log_result):
i += 1
# calculatte percentage swapped by digging before_source_balance, source_token_change and after_source_balance
# calculate percentage swapped by digging before_source_balance, source_token_change and after_source_balance
# "Program log: before_source_balance: 19471871, before_destination_balance: 0, amount_in: 19471871, expect_amount_out: 770877527, min_return: 763168752",
# "Program log: after_source_balance: 0, after_destination_balance: 770570049",
@ -1023,7 +1024,7 @@ async def follow_move(move):
# Calculate the amount to swap based on the same percentage as the followed move
amount_to_swap = your_balance * (move['percentage_swapped'] / 100)
amount_to_swap = min( min(amount_to_swap, your_balance), 300)
# amount_to_swap = min( min(amount_to_swap, your_balance), 300)
# # always get 99% of the amount to swap
# amount_to_swap = amount_to_swap * 0.95
@ -1236,7 +1237,7 @@ async def subscribe(websocket):
try:
await websocket.send(json.dumps(request))
logger.info("Subscription request sent")
return process_messages(websocket)
return await process_messages(websocket)
except Exception as e:
logger.error(f"An unexpected error occurred: {e}")
return None
@ -1261,8 +1262,13 @@ async def process_messages(websocket):
logger.debug(f"Received response: {response_data}")
if 'result' in response_data:
subscription_id = response_data['result']
logger.info(f"Subscription successful. Subscription id: {subscription_id}")
new_sub_id = response_data['result']
if int(new_sub_id) > 1:
subscription_id = new_sub_id
logger.info(f"Subscription successful. New id: {subscription_id}")
elif new_sub_id:
logger.info(f"Existing subscription confirmed: {subscription_id}")
else: return None
return subscription_id
elif 'params' in response_data:
log = response_data['params']['result']