-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPumpFun_Sol_Bot.py
144 lines (121 loc) · 5.22 KB
/
PumpFun_Sol_Bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os
import time
import requests
from bs4 import BeautifulSoup
from bxsolana_trader import Trader, Wallet, Market
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Constants
INITIAL_INVESTMENT_SOL = 0.005 # Initial investment in SOL
PROFIT_TARGET_1 = 0.25 # 25% profit
PROFIT_TARGET_2 = 0.25 # Another 25% profit after target 1
STOP_LOSS = 0.10 # 10% decrease in market cap
BONDING_CRITICAL = 0.75 # 75% of the bonding curve reached
TIMEOUT = 3600 # 1 hour trade timeout
# Load wallet mnemonic from ENV
WALLET_MNEMONIC = os.getenv("WALLET_MNEMONIC")
if not WALLET_MNEMONIC:
raise ValueError("Wallet mnemonic is not set. Please set the WALLET_MNEMONIC in the environment.")
# Initialize Wallet and Trader
wallet = Wallet.from_mnemonic(WALLET_MNEMONIC)
trader = Trader(wallet=wallet)
def scrape_pump_fun():
"""Scrape pump.fun for new tokens."""
url = "https://pump.fun/" # Update with the correct URL if necessary
response = requests.get(url)
if response.status_code != 200:
print("Failed to scrape pump.fun")
return []
soup = BeautifulSoup(response.content, "html.parser")
# Adjust this logic based on the structure of pump.fun
tokens = []
for token_entry in soup.select(".token-entry"): # Replace with actual HTML structure
token = {
"name": token_entry.select_one(".token-name").text.strip(), # Adjust class names
"pair": token_entry.select_one(".token-pair").text.strip(),
"bonding_curve": float(token_entry.select_one(".bonding-curve").text.strip("%")) / 100,
}
tokens.append(token)
# Filter tokens with favorable bonding curves
return [token for token in tokens if token["bonding_curve"] < 0.5]
def monitor_market(token):
"""Monitor the market cap and bonding curve for a token."""
# Mockup for scraping or an external API for live data
# Replace with actual market monitoring implementation
market_data = {
"market_cap": 5000000, # Example market cap
"bonding_curve": token["bonding_curve"], # Use bonding curve from scraping
"price": 0.05, # Example price in SOL
}
return market_data
def execute_trade(strategy):
"""Execute the trading strategy."""
token = strategy["token"]
buy_price = strategy["buy_price"]
quantity = strategy["quantity"]
# Monitor until conditions are met
while True:
data = monitor_market(token)
market_cap = data["market_cap"]
bonding_curve = data["bonding_curve"]
current_price = data["price"]
# Stop Loss Condition
if market_cap <= strategy["initial_market_cap"] * (1 - STOP_LOSS):
print("Stop loss triggered. Selling all tokens.")
trader.sell(symbol=token["pair"], quantity=quantity)
break
# Profit Target 1
if current_price >= buy_price * (1 + PROFIT_TARGET_1) and not strategy["target_1_hit"]:
sell_quantity = quantity * 0.5
print(f"Profit target 1 reached. Selling {sell_quantity} tokens.")
trader.sell(symbol=token["pair"], quantity=sell_quantity)
strategy["target_1_hit"] = True
quantity -= sell_quantity
# Profit Target 2
if strategy["target_1_hit"] and current_price >= buy_price * (1 + PROFIT_TARGET_2):
sell_quantity = quantity * 0.75
print(f"Profit target 2 reached. Selling {sell_quantity} tokens.")
trader.sell(symbol=token["pair"], quantity=sell_quantity)
break
# Bonding Curve Condition
if bonding_curve >= BONDING_CRITICAL:
sell_quantity = quantity * 0.75
print(f"Critical bonding curve reached. Selling {sell_quantity} tokens.")
trader.sell(symbol=token["pair"], quantity=sell_quantity)
quantity -= sell_quantity
# Timeout
if time.time() - strategy["start_time"] > TIMEOUT:
print("Trade timeout reached. Exiting trade.")
trader.sell(symbol=token["pair"], quantity=quantity)
break
time.sleep(30) # Monitor every 30 seconds
def main():
"""Main function to execute trading bot."""
while True:
# Find new tokens
new_tokens = scrape_pump_fun()
for token in new_tokens:
print(f"Found new token: {token['name']}")
# Get initial market data
data = monitor_market(token)
market_cap = data["market_cap"]
bonding_curve = data["bonding_curve"]
buy_price = data["price"] # Price in SOL
# Calculate quantity based on SOL investment
quantity = INITIAL_INVESTMENT_SOL / buy_price
print(f"Buying {quantity} tokens of {token['pair']} at {buy_price} SOL")
trader.buy(symbol=token["pair"], quantity=quantity)
# Start monitoring
strategy = {
"token": token,
"buy_price": buy_price,
"quantity": quantity,
"initial_market_cap": market_cap,
"target_1_hit": False,
"start_time": time.time(),
}
execute_trade(strategy)
time.sleep(300) # Scrape pump.fun every 5 minutes
if __name__ == "__main__":
main()