Spaces:
Sleeping
Sleeping
appold.py
DELETED
@@ -1,567 +0,0 @@
|
|
1 |
-
import requests
|
2 |
-
import time
|
3 |
-
from web3 import Web3
|
4 |
-
from time import gmtime, strftime
|
5 |
-
from st_keyup import st_keyup
|
6 |
-
import datetime
|
7 |
-
import streamlit as st
|
8 |
-
import json
|
9 |
-
|
10 |
-
# Initialise les valeurs des booléens
|
11 |
-
if "bool1" not in st.session_state:
|
12 |
-
st.session_state.bool1 = False
|
13 |
-
if "bool2" not in st.session_state:
|
14 |
-
st.session_state.bool2 = False
|
15 |
-
if "bool3" not in st.session_state:
|
16 |
-
st.session_state.bool3 = False
|
17 |
-
if "bool4" not in st.session_state:
|
18 |
-
st.session_state.bool4 = False
|
19 |
-
if "bool5" not in st.session_state:
|
20 |
-
st.session_state.bool5 = False
|
21 |
-
if "bool6" not in st.session_state:
|
22 |
-
st.session_state.bool6 = False
|
23 |
-
if "bool_abi" not in st.session_state:
|
24 |
-
st.session_state.bool_abi = False
|
25 |
-
|
26 |
-
# Initialise les valeurs des prix et montants
|
27 |
-
if "price1" not in st.session_state:
|
28 |
-
st.session_state.price1 = ""
|
29 |
-
if "price2" not in st.session_state:
|
30 |
-
st.session_state.price2 = ""
|
31 |
-
if "price3" not in st.session_state:
|
32 |
-
st.session_state.price3 = ""
|
33 |
-
if "price4" not in st.session_state:
|
34 |
-
st.session_state.price4 = ""
|
35 |
-
if "price5" not in st.session_state:
|
36 |
-
st.session_state.price5 = ""
|
37 |
-
if "price6" not in st.session_state:
|
38 |
-
st.session_state.price6 = ""
|
39 |
-
|
40 |
-
if "amount1" not in st.session_state:
|
41 |
-
st.session_state.amount1 = ""
|
42 |
-
if "amount2" not in st.session_state:
|
43 |
-
st.session_state.amount2 = ""
|
44 |
-
if "amount3" not in st.session_state:
|
45 |
-
st.session_state.amount3 = ""
|
46 |
-
if "amount4" not in st.session_state:
|
47 |
-
st.session_state.amount4 = ""
|
48 |
-
if "amount5" not in st.session_state:
|
49 |
-
st.session_state.amount5 = ""
|
50 |
-
if "amount6" not in st.session_state:
|
51 |
-
st.session_state.amount6 = ""
|
52 |
-
if "abi" not in st.session_state:
|
53 |
-
st.session_state.abi = ""
|
54 |
-
|
55 |
-
|
56 |
-
# Initialise les valeurs des prix et montants
|
57 |
-
if "trx1" not in st.session_state:
|
58 |
-
st.session_state.trx1 = "no trx"
|
59 |
-
if "trx2" not in st.session_state:
|
60 |
-
st.session_state.trx2 = "no trx"
|
61 |
-
if "trx3" not in st.session_state:
|
62 |
-
st.session_state.trx3 = "no trx"
|
63 |
-
if "trx4" not in st.session_state:
|
64 |
-
st.session_state.trx4 = "no trx"
|
65 |
-
if "trx5" not in st.session_state:
|
66 |
-
st.session_state.trx5 = "no trx"
|
67 |
-
if "trx6" not in st.session_state:
|
68 |
-
st.session_state.trx6 = "no trx"
|
69 |
-
|
70 |
-
# Fonction pour modifier la valeur du booléen 1
|
71 |
-
def toggle_bool1():
|
72 |
-
st.session_state.bool1 = not st.session_state.bool1
|
73 |
-
time.sleep(1)
|
74 |
-
# Fonction pour modifier la valeur du booléen 2
|
75 |
-
def toggle_bool2():
|
76 |
-
st.session_state.bool2 = not st.session_state.bool2
|
77 |
-
time.sleep(1)
|
78 |
-
# Fonction pour modifier la valeur du booléen 3
|
79 |
-
def toggle_bool3():
|
80 |
-
st.session_state.bool3 = not st.session_state.bool3
|
81 |
-
time.sleep(1)
|
82 |
-
def toggle_bool4():
|
83 |
-
st.session_state.bool4 = not st.session_state.bool4
|
84 |
-
time.sleep(1)
|
85 |
-
def toggle_bool5():
|
86 |
-
st.session_state.bool5 = not st.session_state.bool5
|
87 |
-
time.sleep(1)
|
88 |
-
def toggle_bool6():
|
89 |
-
st.session_state.bool6 = not st.session_state.bool6
|
90 |
-
time.sleep(0.1)
|
91 |
-
|
92 |
-
st.write(
|
93 |
-
"""
|
94 |
-
<style>
|
95 |
-
body {
|
96 |
-
background-color: green !important;
|
97 |
-
color: white;
|
98 |
-
}
|
99 |
-
</style>
|
100 |
-
""",
|
101 |
-
unsafe_allow_html=True
|
102 |
-
)
|
103 |
-
|
104 |
-
st.title('🔗💬 TrollTrade - Buy/Sell BSC')
|
105 |
-
st.write('TrollTrade is a powerful trading bot designed to help users of the PancakeSwap platform improve their trading strategy. ')
|
106 |
-
prompt_address_user_container = st.empty() #situation de l'espace de trading
|
107 |
-
prompt_address_user_container.write("Wallet Adress : 0xD7eA51d434D0897DE93400b43341FB3115585111")
|
108 |
-
prompt_address_userBNB = st.text_input('Give your Wallet Address')
|
109 |
-
prompt_address_user = st.text_input('Give your Private Key')
|
110 |
-
st.write("----------------")
|
111 |
-
|
112 |
-
st.title('🔗💬 let s go trade...')
|
113 |
-
prompt_token_address = st.text_input('Choose the BSC Token Adress')
|
114 |
-
tokenAdress_container = st.empty() #situation de l'espace de trading
|
115 |
-
tokenAdress_container.write("Token Adress : 0x922722e9ef614ec9a3e94b78496e92abfbb5a624")
|
116 |
-
|
117 |
-
|
118 |
-
st.write("----------------")
|
119 |
-
output_container2 = st.empty()
|
120 |
-
output_container = st.empty()
|
121 |
-
output_container3 = st.empty()
|
122 |
-
output_container_symbole = st.empty()
|
123 |
-
output_container2.write("Time : " + strftime("%Y-%m-%d %H:%M:%S"))
|
124 |
-
output_container_symbole.write("Symbole : ")
|
125 |
-
output_container.write("Price : ")
|
126 |
-
|
127 |
-
trade7_container = st.empty() #ammount of token
|
128 |
-
trade8_container = st.empty() #ammount of token BNB
|
129 |
-
trade7_container.write("Ammount Token : ")
|
130 |
-
trade8_container.write("Ammount BNB: ")
|
131 |
-
output_container.write("Price : ")
|
132 |
-
output_container2.write("Time : " + strftime("%Y-%m-%d %H:%M:%S"))
|
133 |
-
st.write("----------------")
|
134 |
-
|
135 |
-
st.write("When Sell?")
|
136 |
-
|
137 |
-
# Crée des champs de saisie pour les prix et les montants
|
138 |
-
col1, col2, col3 = st.columns(3)
|
139 |
-
with col1:
|
140 |
-
st.write("Trade 1")
|
141 |
-
st.session_state.price1 = st.text_input("Price 1", st.session_state.price1)
|
142 |
-
st.session_state.amount1 = st.text_input("Amount 1", st.session_state.amount1)
|
143 |
-
st.write("Boolean 1:")
|
144 |
-
if st.button("START/STOP - 1"):
|
145 |
-
toggle_bool1()
|
146 |
-
# Réexécute uniquement cette partie du code
|
147 |
-
st.experimental_rerun()
|
148 |
-
st.write("Trade : " + ("True" if st.session_state.bool1 else "False"))
|
149 |
-
|
150 |
-
with col2:
|
151 |
-
st.write("Trade 2")
|
152 |
-
st.session_state.price2 = st.text_input("Price 2", st.session_state.price2)
|
153 |
-
st.session_state.amount2 = st.text_input("Amount 2", st.session_state.amount2)
|
154 |
-
st.write("Boolean 2:")
|
155 |
-
if st.button("START/STOP - 2"):
|
156 |
-
toggle_bool2()
|
157 |
-
st.experimental_rerun()
|
158 |
-
st.write("Trade : " + ("True" if st.session_state.bool2 else "False"))
|
159 |
-
|
160 |
-
with col3:
|
161 |
-
st.write("Trade 3")
|
162 |
-
st.session_state.price3 = st.text_input("Price 3", st.session_state.price3)
|
163 |
-
st.session_state.amount3 = st.text_input("Amount 3", st.session_state.amount3)
|
164 |
-
st.write("Boolean 2:")
|
165 |
-
if st.button("START/STOP - 3"):
|
166 |
-
toggle_bool3()
|
167 |
-
st.experimental_rerun()
|
168 |
-
st.write("Trade : " + ("True" if st.session_state.bool3 else "False"))
|
169 |
-
|
170 |
-
st.write("----------------")
|
171 |
-
|
172 |
-
st.write("When Buy ?")
|
173 |
-
|
174 |
-
col4 ,col5 ,col6 = st.columns(3)
|
175 |
-
with col4:
|
176 |
-
st.write("Trade 4")
|
177 |
-
st.session_state.price4 = st.text_input("Price 4", st.session_state.price4)
|
178 |
-
st.session_state.amount4= st.text_input("Amount 4 ", st.session_state.amount4)
|
179 |
-
st.write("Boolean 4:")
|
180 |
-
if st.button("START/STOP - 4"):
|
181 |
-
toggle_bool4()
|
182 |
-
st.experimental_rerun()
|
183 |
-
st.write("Trade : " + ("True" if st.session_state.bool4 else "False"))
|
184 |
-
|
185 |
-
with col5:
|
186 |
-
st.write("Trade 5")
|
187 |
-
st.session_state.price5 = st.text_input("Price 5", st.session_state.price5)
|
188 |
-
st.session_state.amount5 = st.text_input("Amount 5", st.session_state.amount5)
|
189 |
-
st.write("Boolean 5 :")
|
190 |
-
if st.button("START/STOP - 5"):
|
191 |
-
toggle_bool5()
|
192 |
-
st.experimental_rerun()
|
193 |
-
st.write("Trade : " + ("True" if st.session_state.bool5 else "False"))
|
194 |
-
|
195 |
-
with col6:
|
196 |
-
st.write("Trade 6")
|
197 |
-
st.session_state.price6 = st.text_input("Price 6", st.session_state.price6)
|
198 |
-
st.session_state.amount6 = st.text_input("Amount 6", st.session_state.amount6)
|
199 |
-
st.write("Boolean 6 :")
|
200 |
-
if st.button("START/STOP -6"):
|
201 |
-
toggle_bool6()
|
202 |
-
st.experimental_rerun()
|
203 |
-
st.write("Trade : " + ("True" if st.session_state.bool6 else "False"))
|
204 |
-
|
205 |
-
|
206 |
-
st.write("----------------")
|
207 |
-
|
208 |
-
|
209 |
-
# Affiche les informations sur les trades dans un tableau
|
210 |
-
table_data = [("Trade Sell 1", st.session_state.price1, st.session_state.amount1, "True" if st.session_state.bool1 else "False", st.session_state.trx1),
|
211 |
-
("Trade Sell 2", st.session_state.price2, st.session_state.amount2, "True" if st.session_state.bool2 else "False", st.session_state.trx2),
|
212 |
-
("Trade Sell 3", st.session_state.price3, st.session_state.amount3, "True" if st.session_state.bool3 else "False", st.session_state.trx3),
|
213 |
-
("Trade Buy 1", st.session_state.price4, st.session_state.amount4, "True" if st.session_state.bool4 else "False", st.session_state.trx4),
|
214 |
-
("Trade Buy 2", st.session_state.price5, st.session_state.amount5, "True" if st.session_state.bool5 else "False", st.session_state.trx5),
|
215 |
-
("Trade Buy 3", st.session_state.price6, st.session_state.amount6, "True" if st.session_state.bool6 else "False", st.session_state.trx6)]
|
216 |
-
st.write("Table of trades:")
|
217 |
-
with st.container():
|
218 |
-
col1, col2, col3, col4, col5 = st.columns(5)
|
219 |
-
col1.write("Trade")
|
220 |
-
col2.write("Price")
|
221 |
-
col3.write("Amount")
|
222 |
-
col4.write("Status")
|
223 |
-
col5.write("TRX")
|
224 |
-
for data in table_data:
|
225 |
-
with st.container():
|
226 |
-
col1.write(data[0])
|
227 |
-
col2.write(data[1])
|
228 |
-
col3.write(data[2])
|
229 |
-
col4.write(data[3])
|
230 |
-
col5.write(data[4])
|
231 |
-
|
232 |
-
url = "https://api.dexscreener.com/latest/dex/tokens/"
|
233 |
-
w3 = Web3(Web3.HTTPProvider('https://bsc-dataseed1.binance.org:443'))
|
234 |
-
|
235 |
-
|
236 |
-
def modify_price(pricex, symbol, total, BNB):
|
237 |
-
price = pricex
|
238 |
-
print("edit price")
|
239 |
-
trade7_container.write("Ammount Token : " + str(total) + " " + symbol)
|
240 |
-
trade8_container.write("Ammount BNB : " + str(BNB) + " " + "BNB")
|
241 |
-
output_container.write("Price : " + pricex + " USD")
|
242 |
-
output_container_symbole.write("Symbole : " + symbol)
|
243 |
-
output_container2.write("Time : " + strftime("%Y-%m-%d %H:%M:%S"))
|
244 |
-
time.sleep(1)
|
245 |
-
|
246 |
-
def analyser_amount_token(myaddress, token):
|
247 |
-
bsc = "https://bsc-dataseed.binance.org:443"
|
248 |
-
web3 = Web3(Web3.HTTPProvider(bsc))
|
249 |
-
contract_a = your_contract_adress_retrieval_function(token)
|
250 |
-
|
251 |
-
if 'bool_abi' not in st.session_state:
|
252 |
-
st.session_state.bool_abi = False
|
253 |
-
bool_abii = False
|
254 |
-
abi = ""
|
255 |
-
else:
|
256 |
-
bool_abii = st.session_state.bool_abi
|
257 |
-
abi = get_abi(token, bool_abii)
|
258 |
-
|
259 |
-
|
260 |
-
if abi == "":
|
261 |
-
return 0
|
262 |
-
contract = web3.eth.contract(address=contract_a, abi=abi)
|
263 |
-
totalSupply = contract.functions.totalSupply().call()
|
264 |
-
|
265 |
-
address = web3.to_checksum_address(myaddress)
|
266 |
-
balance12 = contract.functions.balanceOf(myaddress).call()
|
267 |
-
print(balance12)
|
268 |
-
balance1 = web3.from_wei(balance12,"ether")
|
269 |
-
return balance1
|
270 |
-
|
271 |
-
def analyser_amount_BNB(myaddress):
|
272 |
-
bsc = "https://bsc-dataseed.binance.org/"
|
273 |
-
|
274 |
-
web3 = Web3(Web3.HTTPProvider(bsc))
|
275 |
-
|
276 |
-
balance = web3.eth.get_balance(myaddress)
|
277 |
-
print(balance)
|
278 |
-
|
279 |
-
result = web3.from_wei(balance, "ether")
|
280 |
-
print(result)
|
281 |
-
return result
|
282 |
-
|
283 |
-
def analyser_prix(adress_token):
|
284 |
-
url2 = url + adress_token
|
285 |
-
while True:
|
286 |
-
try:
|
287 |
-
response = requests.get(url2)
|
288 |
-
price = response.json()['pairs'][0]['priceUsd']
|
289 |
-
priceBNB = response.json()['pairs'][0]['priceNative']
|
290 |
-
price_change_5m = response.json()['pairs'][0]['priceChange']['m5']
|
291 |
-
price_change_1h = response.json()['pairs'][0]['priceChange']['h1']
|
292 |
-
price_change_6h = response.json()['pairs'][0]['priceChange']['h6']
|
293 |
-
price_change_24h = response.json()['pairs'][0]['priceChange']['h24']
|
294 |
-
symbole = response.json()['pairs'][0]["baseToken"]["symbol"]
|
295 |
-
# call the function and pass the initial value of x
|
296 |
-
if prompt_address_userBNB.strip():
|
297 |
-
addressUser = prompt_address_userBNB.strip()
|
298 |
-
else:
|
299 |
-
addressUser = "0xD7eA51d434D0897DE93400b43341FB3115585111"
|
300 |
-
|
301 |
-
amount_user = analyser_amount_token(addressUser,adress_token)
|
302 |
-
amount_BNB = analyser_amount_BNB(addressUser)
|
303 |
-
|
304 |
-
modify_price(price, symbole,amount_user,amount_BNB)
|
305 |
-
|
306 |
-
#modify_token_address(prompt_token_address)
|
307 |
-
print("Price : " + str(price )+ " - Price 5m : " + str(price_change_5m) + " - Price 1h : " + str(price_change_1h) + " - Price 6H " + str(price_change_6h) + " - Price 1J " + str(price_change_24h))
|
308 |
-
time.sleep(1)
|
309 |
-
|
310 |
-
return price
|
311 |
-
except requests.exceptions.RequestException as e:
|
312 |
-
print("Erreur lors de la récupération des données: ", e)
|
313 |
-
time.sleep(1)
|
314 |
-
|
315 |
-
def analyser_prixBNB(adress_token):
|
316 |
-
url2 = url + adress_token
|
317 |
-
print(url2)
|
318 |
-
while True:
|
319 |
-
try:
|
320 |
-
response = requests.get(url2)
|
321 |
-
priceBNB = response.json()['pairs'][0]['priceNative']
|
322 |
-
return priceBNB
|
323 |
-
except requests.exceptions.RequestException as e:
|
324 |
-
print("Erreur lors de la récupération des données: ", e)
|
325 |
-
time.sleep(1)
|
326 |
-
|
327 |
-
def get_abi(token, bool_abi_h):
|
328 |
-
# Vérifier si l'ABI est déjà stocké dans les variables de session
|
329 |
-
print(bool_abi_h)
|
330 |
-
print("abi")
|
331 |
-
|
332 |
-
if bool_abi_h:
|
333 |
-
print("IF")
|
334 |
-
abih = st.session_state['abi']
|
335 |
-
return abih
|
336 |
-
else:
|
337 |
-
print("ELSE")
|
338 |
-
# Récupérer l'ABI depuis la source appropriée
|
339 |
-
abi = your_abi_retrieval_function(token)
|
340 |
-
print(abi)
|
341 |
-
st.session_state['abi'] = abi
|
342 |
-
print("yasdadasd")
|
343 |
-
return abi
|
344 |
-
# Retourner l'ABI
|
345 |
-
|
346 |
-
|
347 |
-
def your_contract_adress_retrieval_function(token):
|
348 |
-
bsc = "https://bsc-dataseed.binance.org:443"
|
349 |
-
web3 = Web3(Web3.HTTPProvider(bsc))
|
350 |
-
url_eth = "https://api.bscscan.com/api"
|
351 |
-
contract_address = web3.to_checksum_address(token)
|
352 |
-
return contract_address
|
353 |
-
tempa = 0
|
354 |
-
|
355 |
-
def your_abi_retrieval_function(token):
|
356 |
-
if 'bool_abi' not in st.session_state:
|
357 |
-
st.session_state.bool_abi = True
|
358 |
-
if not st.session_state.bool_abi:
|
359 |
-
st.session_state.bool_abi = True
|
360 |
-
|
361 |
-
print("returnabi_1")
|
362 |
-
print(st.session_state.bool_abi)
|
363 |
-
token_v = token
|
364 |
-
print(token_v)
|
365 |
-
|
366 |
-
bsc = "https://bsc-dataseed.binance.org:443"
|
367 |
-
web3 = Web3(Web3.HTTPProvider(bsc))
|
368 |
-
url_eth = "https://api.bscscan.com/api"
|
369 |
-
contract_address = web3.to_checksum_address(token_v)
|
370 |
-
API_ENDPOINT = url_eth+"?module=contract&action=getabi&address="+str(contract_address)
|
371 |
-
r = requests.get(url = API_ENDPOINT)
|
372 |
-
response = r.json()
|
373 |
-
abi=json.loads(response["result"])
|
374 |
-
|
375 |
-
print("returnabi_2")
|
376 |
-
return abi
|
377 |
-
st.experimental_rerun()
|
378 |
-
else:
|
379 |
-
abi3 = st.session_state['abi']
|
380 |
-
return abi3
|
381 |
-
|
382 |
-
def reset_value(temp):
|
383 |
-
numtrade = temp
|
384 |
-
if numtrade == 1:
|
385 |
-
st.session_state.amount1 = 0
|
386 |
-
st.session_state.price1 = 0
|
387 |
-
if numtrade == 2:
|
388 |
-
st.session_state.amount2 = 0
|
389 |
-
st.session_state.price2 = 0
|
390 |
-
if numtrade == 3:
|
391 |
-
st.session_state.amount3 = 0
|
392 |
-
st.session_state.price3 = 0
|
393 |
-
if numtrade == 4:
|
394 |
-
st.session_state.amount4 = 0
|
395 |
-
st.session_state.price3 = 0
|
396 |
-
if numtrade == 5:
|
397 |
-
st.session_state.amount5 = 0
|
398 |
-
st.session_state.price3 = 0
|
399 |
-
if numtrade == 6:
|
400 |
-
st.session_state.amount6 = 0
|
401 |
-
st.session_state.price3 = 0
|
402 |
-
def sellToken(amountToken, sender_address, tokenToSell, prixNative):
|
403 |
-
bsc = "https://bsc-dataseed.binance.org/"
|
404 |
-
web3 = Web3(Web3.HTTPProvider(bsc))
|
405 |
-
print(web3.is_connected())
|
406 |
-
|
407 |
-
# Adresse du contrat du routeur PancakeSwap
|
408 |
-
panRouterContractAddress = '0x10ED43C718714eb63d5aA57B78B54704E256024E'
|
409 |
-
panabi = '[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"amountADesired","type":"uint256"},{"internalType":"uint256","name":"amountBDesired","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountTokenDesired","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidityETH","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"reserveIn","type":"uint256"},{"internalType":"uint256","name":"reserveOut","type":"uint256"}],"name":"getAmountIn","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"reserveIn","type":"uint256"},{"internalType":"uint256","name":"reserveOut","type":"uint256"}],"name":"getAmountOut","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsIn","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"reserveA","type":"uint256"},{"internalType":"uint256","name":"reserveB","type":"uint256"}],"name":"quote","outputs":[{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidityETH","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidityETHSupportingFeeOnTransferTokens","outputs":[{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityETHWithPermit","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityETHWithPermitSupportingFeeOnTransferTokens","outputs":[{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityWithPermit","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapETHForExactTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactETHForTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactETHForTokensSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForETH","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForETHSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForTokensSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapTokensForExactETH","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapTokensForExactTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]'
|
410 |
-
|
411 |
-
# Adresse du contrat de BNB (WBNB)
|
412 |
-
receive = web3.to_checksum_address("0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c")
|
413 |
-
|
414 |
-
# Configuration du contrat PancakeSwap
|
415 |
-
contract = web3.eth.contract(address=panRouterContractAddress, abi=panabi)
|
416 |
-
nonce = web3.eth.get_transaction_count(sender_address)
|
417 |
-
start = time.time()
|
418 |
-
|
419 |
-
# Conversion des adresses en format checksum
|
420 |
-
checksum_address_sender = web3.to_checksum_address(sender_address)
|
421 |
-
checksum_address_tokenToSell = web3.to_checksum_address(tokenToSell)
|
422 |
-
|
423 |
-
# Calcul du montant total du token
|
424 |
-
totaltoken = 1000000000000000000 * int(amountToken)
|
425 |
-
|
426 |
-
# Calcul du montant total de BNB à recevoir
|
427 |
-
totalBNB = (float(prixNative) * float(amountToken) * 0.99 - float(0.000737585))
|
428 |
-
|
429 |
-
# Création de la transaction pour l'échange de tokens contre BNB
|
430 |
-
pancakeswap2_txn = contract.functions.swapExactTokensForETH(
|
431 |
-
totaltoken, # Montant du token à vendre
|
432 |
-
0, # Montant minimum de BNB à recevoir (0 pour ignorer)
|
433 |
-
[checksum_address_tokenToSell, receive], # Adresses du contrat du token et du contrat BNB
|
434 |
-
checksum_address_sender, # Adresse de l'acheteur
|
435 |
-
(int(time.time()) + 10000) # Timestamp + 10000 (durée de validité de la transaction)
|
436 |
-
).build_transaction({
|
437 |
-
'from': checksum_address_sender,
|
438 |
-
'gas': 250000,
|
439 |
-
'gasPrice': web3.to_wei('5', 'gwei'),
|
440 |
-
'nonce': nonce,
|
441 |
-
})
|
442 |
-
|
443 |
-
# Signature et envoi de la transaction
|
444 |
-
signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key="xxx")
|
445 |
-
tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
|
446 |
-
print("TRX : " + web3.to_hex(tx_token))
|
447 |
-
trxfinal = web3.to_hex(tx_token)
|
448 |
-
return trxfinal
|
449 |
-
|
450 |
-
def buyToken(amountToken, sender_address, tokenToBuy, prixNative):
|
451 |
-
|
452 |
-
bsc = "https://bsc-dataseed.binance.org/"
|
453 |
-
web3 = Web3(Web3.HTTPProvider(bsc))
|
454 |
-
print(web3.is_connected())
|
455 |
-
#pancakeswap router #pancakeswap router abi
|
456 |
-
panRouterContractAddress = '0x10ED43C718714eb63d5aA57B78B54704E256024E'
|
457 |
-
panabi = '[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"amountADesired","type":"uint256"},{"internalType":"uint256","name":"amountBDesired","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountTokenDesired","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidityETH","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"reserveIn","type":"uint256"},{"internalType":"uint256","name":"reserveOut","type":"uint256"}],"name":"getAmountIn","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"reserveIn","type":"uint256"},{"internalType":"uint256","name":"reserveOut","type":"uint256"}],"name":"getAmountOut","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsIn","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"reserveA","type":"uint256"},{"internalType":"uint256","name":"reserveB","type":"uint256"}],"name":"quote","outputs":[{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidityETH","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"removeLiquidityETHSupportingFeeOnTransferTokens","outputs":[{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityETHWithPermit","outputs":[{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountTokenMin","type":"uint256"},{"internalType":"uint256","name":"amountETHMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityETHWithPermitSupportingFeeOnTransferTokens","outputs":[{"internalType":"uint256","name":"amountETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"removeLiquidityWithPermit","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapETHForExactTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactETHForTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactETHForTokensSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForETH","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForETHSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForTokensSupportingFeeOnTransferTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapTokensForExactETH","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapTokensForExactTokens","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]'
|
458 |
-
#balance = web3.eth.get_balance(sender_address)
|
459 |
-
|
460 |
-
#humanReadable = web3.from_wei(balance,'ether')
|
461 |
-
|
462 |
-
#Contract Address of Token we want to buy
|
463 |
-
spend = web3.to_checksum_address("0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c") #wbnb contract
|
464 |
-
|
465 |
-
#Setup the PancakeSwap contract
|
466 |
-
contract = web3.eth.contract(address=panRouterContractAddress, abi=panabi)
|
467 |
-
nonce = web3.eth.get_transaction_count(sender_address)
|
468 |
-
start = time.time()
|
469 |
-
print(sender_address)
|
470 |
-
checksum_address_sender = web3.to_checksum_address(sender_address)
|
471 |
-
checksum_address_tokenToBuy = web3.to_checksum_address(tokenToBuy)
|
472 |
-
print(checksum_address_sender)
|
473 |
-
totaltoken = 1000000000000000000 * int(amountToken)
|
474 |
-
totalBNB = (float(prixNative) * float(amountToken) * 1.01 + float(0.000737585))
|
475 |
-
pancakeswap2_txn = contract.functions.swapETHForExactTokens(
|
476 |
-
totaltoken, # set to 0, or specify minimum amount of tokeny you want to receive - consider decimals!!!
|
477 |
-
# set to 0, or specify minimum amount of tokeny you want to receive - consider decimals!!!
|
478 |
-
[spend,checksum_address_tokenToBuy],
|
479 |
-
checksum_address_sender,
|
480 |
-
(int(time.time()) + 10000)
|
481 |
-
).build_transaction({
|
482 |
-
'from': checksum_address_sender,
|
483 |
-
'value': web3.to_wei(totalBNB,'ether'),#This is the Token(BNB) amount you want to Swap from
|
484 |
-
'gas': 250000,
|
485 |
-
'gasPrice': web3.to_wei('5','gwei'),
|
486 |
-
'nonce': nonce,
|
487 |
-
})
|
488 |
-
|
489 |
-
signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key="privatekey")
|
490 |
-
tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
|
491 |
-
print("TRX : " + web3.to_hex(tx_token))
|
492 |
-
trxfinal = web3.to_hex(tx_token)
|
493 |
-
return trxfinal
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
while True:
|
498 |
-
time.sleep(1)
|
499 |
-
|
500 |
-
if prompt_token_address:
|
501 |
-
price_now = analyser_prix(prompt_token_address)
|
502 |
-
print(st.session_state.bool1)
|
503 |
-
prompt_addres_userBNB = "0xD7eA51d434D0897DE93400b43341FB3115585111"
|
504 |
-
prixNative = analyser_prixBNB(prompt_token_address)
|
505 |
-
|
506 |
-
if st.session_state.bool1:
|
507 |
-
print("CHECK PRICE TRADE 1")
|
508 |
-
if price_now > st.session_state.price1:
|
509 |
-
print("Trade Sell 1 : ")
|
510 |
-
#st.session_state.trx1 = sellToken(st.session_state.amount1, prompt_addres_userBNB, prompt_token_address, prixNative)
|
511 |
-
toggle_bool1()
|
512 |
-
reset_value(1)
|
513 |
-
st.write("Trade 1 done")
|
514 |
-
|
515 |
-
st.experimental_rerun()
|
516 |
-
|
517 |
-
if st.session_state.bool2:
|
518 |
-
print("CHECK PRICE TRADE 2")
|
519 |
-
if price_now > st.session_state.price2:
|
520 |
-
print("Trade Sell 2 : ")
|
521 |
-
#st.session_state.trx2 = sellToken(st.session_state.amount2, prompt_addres_userBNB, prompt_token_address, prixNative)
|
522 |
-
toggle_bool2()
|
523 |
-
st.write("Trade 2 done")
|
524 |
-
reset_value(2)
|
525 |
-
|
526 |
-
st.experimental_rerun()
|
527 |
-
|
528 |
-
if st.session_state.bool3:
|
529 |
-
print("CHECK PRICE TRADE 3")
|
530 |
-
if price_now > st.session_state.price3:
|
531 |
-
print("Trade Sell 3 : ")
|
532 |
-
#st.session_state.trx3 = sellToken(st.session_state.amount3, prompt_addres_userBNB, prompt_token_address, prixNative)
|
533 |
-
toggle_bool3()
|
534 |
-
reset_value(3)
|
535 |
-
|
536 |
-
st.experimental_rerun()
|
537 |
-
|
538 |
-
if st.session_state.bool4:
|
539 |
-
print("CHECK PRICE TRADE 4")
|
540 |
-
if price_now < st.session_state.price4 and st.session_state.price4 > 0:
|
541 |
-
print("Trade BUY 4 : ")
|
542 |
-
#st.session_state.trx4 = buyToken(st.session_state.amount4, prompt_addres_userBNB, prompt_token_address, prixNative)
|
543 |
-
toggle_bool4()
|
544 |
-
reset_value(4)
|
545 |
-
st.experimental_rerun()
|
546 |
-
|
547 |
-
if st.session_state.bool5:
|
548 |
-
print("CHECK PRICE TRADE 5")
|
549 |
-
if price_now < st.session_state.price5 and st.session_state.price5 > 0:
|
550 |
-
print("Trade BUY 5 : ")
|
551 |
-
#st.session_state.trx5 = buyToken(st.session_state.amount5, prompt_addres_userBNB, prompt_token_address, prixNative)
|
552 |
-
toggle_bool5()
|
553 |
-
reset_value(5)
|
554 |
-
st.experimental_rerun()
|
555 |
-
|
556 |
-
if st.session_state.bool6:
|
557 |
-
print("CHECK PRICE TRADE 6")
|
558 |
-
if price_now < st.session_state.price6 and st.session_state.price6 > 0:
|
559 |
-
print("Trade BUY 6 : ")
|
560 |
-
#st.session_state.trx6 = buyToken(st.session_state.amount6, prompt_addres_userBNB, prompt_token_address, prixNative)
|
561 |
-
toggle_bool6()
|
562 |
-
reset_value(6)
|
563 |
-
st.experimental_rerun()
|
564 |
-
|
565 |
-
time.sleep(1)
|
566 |
-
|
567 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|