wip
This commit is contained in:
parent
25384ec5a8
commit
e56f007082
@ -34,15 +34,10 @@ load_dotenv('.env.secret')
|
||||
# Configuration
|
||||
|
||||
|
||||
from config import (FOLLOWED_WALLET, YOUR_WALLET, SOLANA_WS_URL, SOLANA_HTTP_URL, FOLLOW_AMOUNT, SOLANA_ENDPOINTS, logging, error_logger, logger)
|
||||
from config import (FOLLOWED_WALLET, YOUR_WALLET, SOLANA_WS_URL, SOLANA_HTTP_URL, FOLLOW_AMOUNT, SOLANA_ENDPOINTS, logging, error_logger, logger)
|
||||
|
||||
|
||||
|
||||
TOKENS_INFO = {}
|
||||
try:
|
||||
with open('./logs/token_info.json', 'r') as f:
|
||||
TOKENS_INFO = json.load(f)
|
||||
except Exception as e:
|
||||
logging.error(f"Error loading token info: {str(e)}")
|
||||
|
||||
# # # # # # # # # # TELEGRAM # # # # # # # # # #
|
||||
# if not telegram_utils.bot:
|
||||
@ -180,8 +175,8 @@ async def process_log(log_result):
|
||||
# await get_token_prices(all_token_addresses)
|
||||
|
||||
try:
|
||||
token_in = TOKENS_INFO[tr_details["token_in"]]
|
||||
token_out = TOKENS_INFO[tr_details["token_out"]]
|
||||
token_in = SAPI.dex.TOKENS_INFO[tr_details["token_in"]]
|
||||
token_out = SAPI.dex.TOKENS_INFO[tr_details["token_out"]]
|
||||
|
||||
tr_details["symbol_in"] = token_in.get('symbol')
|
||||
tr_details["symbol_out"] = token_out.get('symbol')
|
||||
@ -231,9 +226,9 @@ async def follow_move(move):
|
||||
your_balance = your_balance_info['amount']
|
||||
|
||||
|
||||
token_info = TOKENS_INFO.get(move['token_in'])
|
||||
token_info = SAPI.dex.TOKENS_INFO.get(move['token_in'])
|
||||
token_name_in = token_info.get('symbol') or await SAPI.get_token_metadata(move['token_in'])
|
||||
token_name_out = TOKENS_INFO[move['token_out']].get('symbol') or await solanaAPI.get_token_metadata_symbol(move['token_out'])
|
||||
token_name_out = SAPI.dex.TOKENS_INFO[move['token_out']].get('symbol') or await solanaAPI.get_token_metadata_symbol(move['token_out'])
|
||||
|
||||
if not your_balance:
|
||||
msg = f"<b>Move not followed:</b>\nNo balance found for token {move['symbol_in']}. Cannot follow move."
|
||||
|
@ -4,6 +4,8 @@ import os
|
||||
import logging
|
||||
from dotenv import load_dotenv
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import json
|
||||
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
@ -33,6 +35,9 @@ TOKEN_ADDRESSES = {
|
||||
"TARD": "4nfn86ssbv7wiqcsw7bpvn46k24jhe334fudtyxhp1og",
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
# Logging configuration
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -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:
|
||||
|
1
crypto/sol/solana-swap-python
Submodule
1
crypto/sol/solana-swap-python
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit aed6399bdc7acb8b7d9baabb3f9f2f00bba3ebc2
|
1
trading
Submodule
1
trading
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 78e4a087f0f71c8b8b1b743fa8bd79ef5d6ae5af
|
Loading…
x
Reference in New Issue
Block a user