wip
This commit is contained in:
@ -36,7 +36,7 @@ import requests
|
||||
from datetime import datetime
|
||||
from solana.rpc.types import TokenAccountOpts, TxOpts
|
||||
from typing import List, Dict, Any, Tuple
|
||||
|
||||
import traceback
|
||||
|
||||
# # # solders/solana libs (solana_client) # # #
|
||||
from spl.token._layouts import MINT_LAYOUT
|
||||
@ -53,9 +53,7 @@ logger = logging.getLogger(__name__)
|
||||
PING_INTERVAL = 30
|
||||
SUBSCRIBE_INTERVAL = 10*60 # Resubscribe every 1 minute
|
||||
|
||||
from config import (
|
||||
FOLLOWED_WALLET, SOLANA_HTTP_URL, DISPLAY_CURRENCY, SOLANA_ENDPOINTS, YOUR_WALLET
|
||||
)
|
||||
from config import ( FOLLOWED_WALLET, SOLANA_HTTP_URL, DISPLAY_CURRENCY, SOLANA_ENDPOINTS, YOUR_WALLET)
|
||||
|
||||
from modules.utils import telegram_utils, async_safe_call
|
||||
|
||||
@ -81,7 +79,7 @@ class SolanaWS:
|
||||
while True:
|
||||
try:
|
||||
current_url = random.choice(SOLANA_ENDPOINTS)
|
||||
self.websocket = await websockets.connect(current_url, ping_interval=30, ping_timeout=20)
|
||||
self.websocket = await websockets.connect(current_url, ping_interval=30, ping_timeout=10)
|
||||
logger.info(f"Connected to Solana websocket: {current_url}")
|
||||
return
|
||||
except Exception as e:
|
||||
@ -126,6 +124,7 @@ class SolanaWS:
|
||||
# define onmessage as inline callback to get subscription_id which waits for last_msg_responded
|
||||
# self.on_message = lambda message: self.subscription_id = message.get('result')
|
||||
await self.ws_jsonrpc("logsSubscribe", params, False)
|
||||
await asyncio.sleep(.4)
|
||||
await self.receive_messages(True)
|
||||
result = await self.process_messages(True)
|
||||
|
||||
@ -149,6 +148,7 @@ class SolanaWS:
|
||||
async def receive_messages(self, one = False):
|
||||
while True:
|
||||
try:
|
||||
|
||||
response = await self.websocket.recv()
|
||||
response_data = json.loads(response)
|
||||
self.last_msg_responded = True
|
||||
@ -260,6 +260,7 @@ class SolanaAPI:
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An unexpected error occurred: {e}")
|
||||
logger.error("".join(traceback.format_exception(None, e, e.__traceback__)))
|
||||
finally:
|
||||
try:
|
||||
await solana_ws.unsubscribe()
|
||||
@ -613,6 +614,11 @@ class SolanaDEX:
|
||||
self.TOKEN_ADDRESSES = {}
|
||||
self.FOLLOWED_WALLET_VALUE = 0
|
||||
self.YOUR_WALLET_VALUE = 0
|
||||
try:
|
||||
with open('../logs/token_info.json', 'r') as f:
|
||||
self.TOKENS_INFO = json.load(f)
|
||||
except Exception as e:
|
||||
logging.error(f"Error loading token info: {str(e)}")
|
||||
|
||||
async def get_token_prices(self, token_addresses: List[str]) -> Dict[str, float]:
|
||||
prices = {addr: 1.0 for addr in token_addresses if addr == "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"}
|
||||
@ -800,19 +806,14 @@ class SolanaDEX:
|
||||
if isinstance(info, dict) and 'mint' in info and 'tokenAmount' in info:
|
||||
mint = info['mint']
|
||||
decimals = int(info['tokenAmount']['decimals'])
|
||||
amount = info['tokenAmount']['amount']
|
||||
try:
|
||||
amount = float(amount)
|
||||
except ValueError:
|
||||
print(f"Error: amount '{amount}' cannot be converted to a float")
|
||||
# You might want to add some error handling here
|
||||
|
||||
if amount > 0.0:
|
||||
amount = amount /10**decimals
|
||||
amount = int(info['tokenAmount']['amount'])
|
||||
amount = float(amount /10**decimals)
|
||||
if amount > 1:
|
||||
if mint in self.TOKENS_INFO:
|
||||
token_name = self.TOKENS_INFO[mint].get('symbol')
|
||||
elif doGetTokenName:
|
||||
token_name = await self.get_token_metadata_symbol(mint) or 'N/A'
|
||||
self.TOKENS_INFO[mint] = {'symbol': token_name}
|
||||
await asyncio.sleep(2)
|
||||
|
||||
self.TOKENS_INFO[mint]['holdedAmount'] = round(amount,decimals)
|
||||
@ -823,7 +824,10 @@ class SolanaDEX:
|
||||
'amount': amount,
|
||||
'decimals': decimals
|
||||
}
|
||||
logging.debug(f"Account balance for {token_name} ({mint}): {amount}")
|
||||
try:
|
||||
logging.debug(f"Account balance for {token_name} ({mint}): {amount}")
|
||||
except Exception as e:
|
||||
logging.error(f"Error logging account balance: {str(e)}")
|
||||
else:
|
||||
logging.warning(f"Unexpected data format for account: {account}")
|
||||
except Exception as e:
|
||||
|
Reference in New Issue
Block a user