mirror of
https://github.com/chainstacklabs/pumpfun-bonkfun-bot.git
synced 2026-08-08 04:57:45 +00:00
minor fixes
This commit is contained in:
+1
-2
@@ -3,12 +3,11 @@ Solana client abstraction for blockchain operations.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||
from typing import Any, Dict
|
||||
|
||||
from solana.rpc.async_api import AsyncClient
|
||||
from solana.rpc.commitment import Confirmed
|
||||
from solana.rpc.types import TxOpts
|
||||
from solders.instruction import Instruction
|
||||
from solders.keypair import Keypair
|
||||
from solders.pubkey import Pubkey
|
||||
from solders.transaction import Transaction
|
||||
|
||||
+33
-23
@@ -6,10 +6,8 @@ import asyncio
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from solders.pubkey import Pubkey
|
||||
|
||||
import config
|
||||
from src.core.client import SolanaClient
|
||||
from src.core.curve import BondingCurveManager
|
||||
from src.core.pubkeys import PumpAddresses
|
||||
@@ -120,26 +118,25 @@ class PumpTrader:
|
||||
try:
|
||||
await self._save_token_info(token_info)
|
||||
|
||||
logger.info("Waiting for 15 seconds for the bonding curve to stabilize...")
|
||||
await asyncio.sleep(15)
|
||||
|
||||
try:
|
||||
token_price = await self.curve_manager.calculate_price(
|
||||
token_info.bonding_curve
|
||||
)
|
||||
logger.info(f"Token price: {token_price:.10f} SOL")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get token price: {str(e)}")
|
||||
token_price = 0
|
||||
logger.info(
|
||||
f"Waiting for {config.WAIT_TIME_AFTER_CREATION} seconds for the bonding curve to stabilize..."
|
||||
)
|
||||
await asyncio.sleep(config.WAIT_TIME_AFTER_CREATION)
|
||||
|
||||
logger.info(
|
||||
f"Buying {self.buy_amount:.6f} SOL worth of {token_info.symbol}..."
|
||||
)
|
||||
buy_result = await self.buyer.execute(token_info)
|
||||
buy_result: TradeResult = await self.buyer.execute(token_info)
|
||||
|
||||
if buy_result.success:
|
||||
logger.info(f"Successfully bought {token_info.symbol}")
|
||||
self._log_trade("buy", token_info, token_price, buy_result.tx_signature)
|
||||
self._log_trade(
|
||||
"buy",
|
||||
token_info,
|
||||
buy_result.price, # type: ignore
|
||||
buy_result.amount, # type: ignore
|
||||
buy_result.tx_signature,
|
||||
)
|
||||
else:
|
||||
logger.error(
|
||||
f"Failed to buy {token_info.symbol}: {buy_result.error_message}"
|
||||
@@ -147,16 +144,22 @@ class PumpTrader:
|
||||
|
||||
# Sell token if not in marry mode
|
||||
if not marry_mode and buy_result.success:
|
||||
logger.info("Waiting for 20 seconds before selling...")
|
||||
await asyncio.sleep(20)
|
||||
logger.info(
|
||||
f"Waiting for {config.WAIT_TIME_AFTER_BUY} seconds before selling..."
|
||||
)
|
||||
await asyncio.sleep(config.WAIT_TIME_AFTER_BUY)
|
||||
|
||||
logger.info(f"Selling {token_info.symbol}...")
|
||||
sell_result = await self.seller.execute(token_info)
|
||||
sell_result: TradeResult = await self.seller.execute(token_info)
|
||||
|
||||
if sell_result.success:
|
||||
logger.info(f"Successfully sold {token_info.symbol}")
|
||||
self._log_trade(
|
||||
"sell", token_info, token_price, sell_result.tx_signature
|
||||
"sell",
|
||||
token_info,
|
||||
sell_result.price, # type: ignore
|
||||
sell_result.amount, # type: ignore
|
||||
sell_result.tx_signature,
|
||||
)
|
||||
else:
|
||||
logger.error(
|
||||
@@ -168,9 +171,9 @@ class PumpTrader:
|
||||
# Wait before looking for the next token
|
||||
if yolo_mode:
|
||||
logger.info(
|
||||
"YOLO mode enabled. Waiting 5 seconds before looking for next token..."
|
||||
f"YOLO mode enabled. Waiting {config.WAIT_TIME_BEFORE_NEW_TOKEN} seconds before looking for next token..."
|
||||
)
|
||||
await asyncio.sleep(5)
|
||||
await asyncio.sleep(config.WAIT_TIME_BEFORE_NEW_TOKEN)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error handling token {token_info.symbol}: {str(e)}")
|
||||
@@ -190,7 +193,12 @@ class PumpTrader:
|
||||
logger.info(f"Token information saved to {file_name}")
|
||||
|
||||
def _log_trade(
|
||||
self, action: str, token_info: TokenInfo, price: float, tx_hash: str | None
|
||||
self,
|
||||
action: str,
|
||||
token_info: TokenInfo,
|
||||
price: float,
|
||||
amount: float,
|
||||
tx_hash: str | None,
|
||||
) -> None:
|
||||
"""Log trade information.
|
||||
|
||||
@@ -198,6 +206,7 @@ class PumpTrader:
|
||||
action: Trade action (buy/sell)
|
||||
token_info: Token information
|
||||
price: Token price in SOL
|
||||
amount: Trade amount in SOL
|
||||
tx_hash: Transaction hash
|
||||
"""
|
||||
os.makedirs("trades", exist_ok=True)
|
||||
@@ -208,6 +217,7 @@ class PumpTrader:
|
||||
"token_address": str(token_info.mint),
|
||||
"symbol": token_info.symbol,
|
||||
"price": price,
|
||||
"amount": amount,
|
||||
"tx_hash": tx_hash,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user