File size: 45,454 Bytes
4a4792a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236c187
4a4792a
 
236c187
4a4792a
 
 
 
 
 
 
 
 
 
236c187
4a4792a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236c187
4a4792a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236c187
4a4792a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236c187
4a4792a
 
 
 
 
 
 
236c187
 
4a4792a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236c187
4a4792a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236c187
4a4792a
 
 
 
 
 
236c187
 
4a4792a
 
 
 
 
 
 
 
 
 
 
236c187
4a4792a
236c187
4a4792a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
import requests
import time
from web3 import Web3
from time import gmtime, strftime
from st_keyup import st_keyup
import datetime
import streamlit as st
import json

# Initialise les valeurs des booléens
if "bool1" not in st.session_state:
    st.session_state.bool1 = False
if "bool2" not in st.session_state:
    st.session_state.bool2 = False
if "bool3" not in st.session_state:
    st.session_state.bool3 = False
if "bool4" not in st.session_state:
    st.session_state.bool4 = False
if "bool5" not in st.session_state:
    st.session_state.bool5 = False
if "bool6" not in st.session_state:
    st.session_state.bool6 = False
if "bool_abi" not in st.session_state:
    st.session_state.bool_abi = False
    
    # Initialise les valeurs des prix et montants
if "price1" not in st.session_state:
    st.session_state.price1 = ""
if "price2" not in st.session_state:
    st.session_state.price2 = ""
if "price3" not in st.session_state:
    st.session_state.price3 = ""
if "price4" not in st.session_state:
    st.session_state.price4 = ""
if "price5" not in st.session_state:
    st.session_state.price5 = ""
if "price6" not in st.session_state:
    st.session_state.price6 = ""   
    
if "amount1" not in st.session_state:
    st.session_state.amount1 = ""
if "amount2" not in st.session_state:
    st.session_state.amount2 = ""
if "amount3" not in st.session_state:
    st.session_state.amount3 = ""
if "amount4" not in st.session_state:
    st.session_state.amount4 = ""
if "amount5" not in st.session_state:
    st.session_state.amount5 = ""
if "amount6" not in st.session_state:
    st.session_state.amount6 = ""
if "abi" not in st.session_state:
    st.session_state.abi = ""    
    
    
    # Initialise les valeurs des prix et montants
if "trx1" not in st.session_state:
    st.session_state.trx1 = "no trx"
if "trx2" not in st.session_state:
    st.session_state.trx2 = "no trx"
if "trx3" not in st.session_state:
    st.session_state.trx3 = "no trx"
if "trx4" not in st.session_state:
    st.session_state.trx4 = "no trx"
if "trx5" not in st.session_state:
    st.session_state.trx5 = "no trx"
if "trx6" not in st.session_state:
    st.session_state.trx6 = "no trx"   
        
# Fonction pour modifier la valeur du booléen 1
def toggle_bool1():
    st.session_state.bool1 = not st.session_state.bool1
    time.sleep(1)
# Fonction pour modifier la valeur du booléen 2
def toggle_bool2():
    st.session_state.bool2 = not st.session_state.bool2
    time.sleep(1)
# Fonction pour modifier la valeur du booléen 3
def toggle_bool3():
    st.session_state.bool3 = not st.session_state.bool3
    time.sleep(1)
def toggle_bool4():
    st.session_state.bool4 = not st.session_state.bool4
    time.sleep(1)
def toggle_bool5():
    st.session_state.bool5 = not st.session_state.bool5
    time.sleep(1)   
def toggle_bool6():
    st.session_state.bool6 = not st.session_state.bool6
    time.sleep(0.1)
    
st.write(
    """
    <style>
    body {
        background-color: green !important;
        color: white;
    }
    </style>
    """,
    unsafe_allow_html=True
)
    
st.title('🔗💬 TrollTrade -  Buy/Sell BSC')
st.write('TrollTrade is a powerful trading bot designed to help users of the PancakeSwap platform improve their trading strategy. ')
prompt_address_user_container = st.empty() #situation de l'espace de trading
prompt_address_user_container.write("Wallet Adress : 0xD7eA51d434D0897DE93400b43341FB3115585111")
prompt_address_userBNB = st.text_input('Give your Wallet Address') 
prompt_address_user = st.text_input('Give your Private Key') 
st.write("----------------")
    
st.title('🔗💬 let s go trade...')
prompt_token_address = st.text_input('Choose the BSC Token Adress') 
tokenAdress_container = st.empty() #situation de l'espace de trading
tokenAdress_container.write("Token Adress : 0x922722e9ef614ec9a3e94b78496e92abfbb5a624")


st.write("----------------")
output_container2 = st.empty()
output_container = st.empty()
output_container3 = st.empty()
output_container_symbole = st.empty()
output_container2.write("Time : " + strftime("%Y-%m-%d %H:%M:%S"))
output_container_symbole.write("Symbole : ")
output_container.write("Price : ")

trade7_container = st.empty() #ammount of token
trade8_container = st.empty() #ammount of token BNB
trade7_container.write("Ammount Token :  ")
trade8_container.write("Ammount BNB:  ")
output_container.write("Price  : ")
output_container2.write("Time : " + strftime("%Y-%m-%d %H:%M:%S"))
st.write("----------------")

st.write("When Sell?")

# Crée des champs de saisie pour les prix et les montants
col1, col2, col3 = st.columns(3)
with col1:
    st.write("Trade 1")
    st.session_state.price1 = st.text_input("Price 1", st.session_state.price1)
    st.session_state.amount1 = st.text_input("Amount 1", st.session_state.amount1)
    st.write("Boolean 1:")
    if st.button("START/STOP - 1"):
        toggle_bool1()
         # Réexécute uniquement cette partie du code
        st.experimental_rerun()
    st.write("Trade : " + ("True" if st.session_state.bool1 else "False"))

with col2:
    st.write("Trade 2")
    st.session_state.price2 = st.text_input("Price 2", st.session_state.price2)
    st.session_state.amount2 = st.text_input("Amount 2", st.session_state.amount2)
    st.write("Boolean 2:")
    if st.button("START/STOP - 2"):
        toggle_bool2()
        st.experimental_rerun()
    st.write("Trade : " + ("True" if st.session_state.bool2 else "False"))
    
with col3:
    st.write("Trade 3")
    st.session_state.price3 = st.text_input("Price 3", st.session_state.price3)
    st.session_state.amount3 = st.text_input("Amount 3", st.session_state.amount3)
    st.write("Boolean 2:")
    if st.button("START/STOP - 3"):
        toggle_bool3()
        st.experimental_rerun()
    st.write("Trade : " + ("True" if st.session_state.bool3 else "False"))

st.write("----------------")

st.write("When Buy ?")

col4 ,col5 ,col6 = st.columns(3)
with col4:
    st.write("Trade 4")
    st.session_state.price4 = st.text_input("Price 4", st.session_state.price4)
    st.session_state.amount4= st.text_input("Amount 4 ", st.session_state.amount4)
    st.write("Boolean 4:")
    if st.button("START/STOP - 4"):
        toggle_bool4()
        st.experimental_rerun()
    st.write("Trade : " + ("True" if st.session_state.bool4 else "False"))

with col5:
    st.write("Trade 5")
    st.session_state.price5 = st.text_input("Price 5", st.session_state.price5)
    st.session_state.amount5 = st.text_input("Amount 5", st.session_state.amount5)
    st.write("Boolean 5 :")
    if st.button("START/STOP - 5"):
        toggle_bool5()
        st.experimental_rerun()
    st.write("Trade : " + ("True" if st.session_state.bool5 else "False"))
    
with col6:
    st.write("Trade 6")
    st.session_state.price6 = st.text_input("Price 6", st.session_state.price6)
    st.session_state.amount6 = st.text_input("Amount 6", st.session_state.amount6)
    st.write("Boolean 6 :")
    if st.button("START/STOP -6"):
        toggle_bool6()
        st.experimental_rerun()
    st.write("Trade : " + ("True" if st.session_state.bool6 else "False"))
 

st.write("----------------")
   
    
# Affiche les informations sur les trades dans un tableau
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),
              ("Trade Sell 2", st.session_state.price2, st.session_state.amount2,  "True" if st.session_state.bool2 else "False", st.session_state.trx2),
              ("Trade Sell 3", st.session_state.price3, st.session_state.amount3,  "True" if st.session_state.bool3 else "False", st.session_state.trx3),
              ("Trade Buy 1", st.session_state.price4, st.session_state.amount4,  "True" if st.session_state.bool4 else "False", st.session_state.trx4),
              ("Trade Buy 2", st.session_state.price5, st.session_state.amount5,  "True" if st.session_state.bool5 else "False", st.session_state.trx5),
              ("Trade Buy 3", st.session_state.price6, st.session_state.amount6,  "True" if st.session_state.bool6 else "False", st.session_state.trx6)]
st.write("Table of trades:")
with st.container():
    col1, col2, col3, col4, col5 = st.columns(5)
    col1.write("Trade")
    col2.write("Price")
    col3.write("Amount")
    col4.write("Status")
    col5.write("TRX")
    for data in table_data:
        with st.container():
            col1.write(data[0])
            col2.write(data[1])
            col3.write(data[2])
            col4.write(data[3])
            col5.write(data[4])
 
url = "https://api.dexscreener.com/latest/dex/tokens/"
w3 = Web3(Web3.HTTPProvider('https://bsc-dataseed1.binance.org:443'))


def modify_price(pricex, symbol, total, BNB):
    price = pricex
    print("edit price")
    trade7_container.write("Ammount Token : " + str(total) + " " + symbol)
    trade8_container.write("Ammount BNB : " + str(BNB) + " " + "BNB")
    output_container.write("Price : " + pricex + " USD")
    output_container_symbole.write("Symbole  : " + symbol)
    output_container2.write("Time : " + strftime("%Y-%m-%d %H:%M:%S"))
    time.sleep(1)

def analyser_amount_token(myaddress, token):
    bsc = "https://bsc-dataseed.binance.org:443"
    web3 = Web3(Web3.HTTPProvider(bsc))
    contract_a = your_contract_adress_retrieval_function(token)

    if 'bool_abi' not in st.session_state:
        st.session_state.bool_abi = False
        bool_abii = False
        abi = ""
    else:
        bool_abii = st.session_state.bool_abi
        abi = get_abi(token, bool_abii)

    
    if abi == "":
        return 0
    contract = web3.eth.contract(address=contract_a, abi=abi)
    totalSupply = contract.functions.totalSupply().call()

    address = web3.toChecksumAddress(myaddress)
    balance12 = contract.functions.balanceOf(myaddress).call()
    print(balance12)
    balance1 = web3.fromWei(balance12,"ether")
    return balance1

def analyser_amount_BNB(myaddress):
    bsc = "https://bsc-dataseed.binance.org/"

    web3 = Web3(Web3.HTTPProvider(bsc))

    balance = web3.eth.get_balance(myaddress)
    print(balance)
    
    result = web3.fromWei(balance, "ether")
    print(result)
    return result

def analyser_prix(adress_token):
    url2 = url + adress_token
    while True:
        try:
            response = requests.get(url2)
            price = response.json()['pairs'][0]['priceUsd']
            priceBNB = response.json()['pairs'][0]['priceNative']
            price_change_5m = response.json()['pairs'][0]['priceChange']['m5']
            price_change_1h = response.json()['pairs'][0]['priceChange']['h1']
            price_change_6h = response.json()['pairs'][0]['priceChange']['h6']
            price_change_24h = response.json()['pairs'][0]['priceChange']['h24']
            symbole = response.json()['pairs'][0]["baseToken"]["symbol"]
            # call the function and pass the initial value of x            
            if prompt_address_userBNB.strip():
                 addressUser = prompt_address_userBNB.strip()
            else:
                 addressUser = "0xD7eA51d434D0897DE93400b43341FB3115585111"
            
            amount_user = analyser_amount_token(addressUser,adress_token)
            amount_BNB = analyser_amount_BNB(addressUser)
            
            modify_price(price, symbole,amount_user,amount_BNB)

            #modify_token_address(prompt_token_address)
            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))
            time.sleep(1)

            return price
        except requests.exceptions.RequestException as e:
            print("Erreur lors de la récupération des données: ", e)
            time.sleep(1)

def analyser_prixBNB(adress_token):
    url2 = url + adress_token
    print(url2)
    while True:
        try:
            response = requests.get(url2)
            priceBNB = response.json()['pairs'][0]['priceNative']
            return priceBNB
        except requests.exceptions.RequestException as e:
            print("Erreur lors de la récupération des données: ", e)
            time.sleep(1)

def get_abi(token, bool_abi_h):
    # Vérifier si l'ABI est déjà stocké dans les variables de session
    print(bool_abi_h)
    print("abi")

    if bool_abi_h:
        print("IF")
        abih = st.session_state['abi']
        return abih 
    else:
        print("ELSE")
        # Récupérer l'ABI depuis la source appropriée
        abi = your_abi_retrieval_function(token)
        print(abi)
        st.session_state['abi'] = abi
        print("yasdadasd")
        return abi
    # Retourner l'ABI
  

def your_contract_adress_retrieval_function(token):
    bsc = "https://bsc-dataseed.binance.org:443"
    web3 = Web3(Web3.HTTPProvider(bsc))
    url_eth = "https://api.bscscan.com/api"
    contract_address = web3.toChecksumAddress(token)
    return contract_address
tempa = 0   

def your_abi_retrieval_function(token):
    if 'bool_abi' not in st.session_state:
        st.session_state.bool_abi = True
    if not st.session_state.bool_abi:
        st.session_state.bool_abi = True

        print("returnabi_1")
        print(st.session_state.bool_abi)
        token_v = token
        print(token_v)

        bsc = "https://bsc-dataseed.binance.org:443"
        web3 = Web3(Web3.HTTPProvider(bsc))
        url_eth = "https://api.bscscan.com/api"
        contract_address = web3.toChecksumAddress(token_v)
        API_ENDPOINT = url_eth+"?module=contract&action=getabi&address="+str(contract_address)
        r = requests.get(url = API_ENDPOINT)
        response = r.json()
        abi=json.loads(response["result"])
        
        print("returnabi_2")
        return abi
        st.experimental_rerun()
    else:
        abi3 = st.session_state['abi']
        return abi3
    
def reset_value(temp):
    numtrade = temp
    if numtrade == 1:
        st.session_state.amount1 = 0
        st.session_state.price1 = 0
    if numtrade == 2:
        st.session_state.amount2 = 0
        st.session_state.price2 = 0
    if numtrade == 3:
        st.session_state.amount3 = 0
        st.session_state.price3 = 0    
    if numtrade == 4:
        st.session_state.amount4 = 0
        st.session_state.price3 = 0           
    if numtrade == 5:
        st.session_state.amount5 = 0
        st.session_state.price3 = 0           
    if numtrade == 6:
        st.session_state.amount6 = 0
        st.session_state.price3 = 0           
def sellToken(amountToken, sender_address, tokenToSell, prixNative):
    bsc = "https://bsc-dataseed.binance.org/"
    web3 = Web3(Web3.HTTPProvider(bsc))
    print(web3.is_connected())

    # Adresse du contrat du routeur PancakeSwap
    panRouterContractAddress = '0x10ED43C718714eb63d5aA57B78B54704E256024E'
    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"}]'

    # Adresse du contrat de BNB (WBNB)
    receive = web3.toChecksumAddress("0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c")

    # Configuration du contrat PancakeSwap
    contract = web3.eth.contract(address=panRouterContractAddress, abi=panabi)
    nonce = web3.eth.get_transaction_count(sender_address)
    start = time.time()

    # Conversion des adresses en format checksum
    checksum_address_sender = web3.toChecksumAddress(sender_address)
    checksum_address_tokenToSell = web3.toChecksumAddress(tokenToSell)

    # Calcul du montant total du token
    totaltoken = 1000000000000000000 * int(amountToken)

    # Calcul du montant total de BNB à recevoir
    totalBNB = (float(prixNative) * float(amountToken) * 0.99 - float(0.000737585))

    # Création de la transaction pour l'échange de tokens contre BNB
    pancakeswap2_txn = contract.functions.swapExactTokensForETH(
        totaltoken,  # Montant du token à vendre
        0,  # Montant minimum de BNB à recevoir (0 pour ignorer)
        [checksum_address_tokenToSell, receive],  # Adresses du contrat du token et du contrat BNB
        checksum_address_sender,  # Adresse de l'acheteur
        (int(time.time()) + 10000)  # Timestamp + 10000 (durée de validité de la transaction)
    ).build_transaction({
        'from': checksum_address_sender,
        'gas': 250000,
        'gasPrice': web3.toWei('5', 'gwei'),
        'nonce': nonce,
    })

    # Signature et envoi de la transaction
    signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key="xxx")
    tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
    print("TRX : " + web3.to_hex(tx_token))
    trxfinal = web3.to_hex(tx_token)
    return trxfinal
                          
def buyToken(amountToken, sender_address, tokenToBuy, prixNative):
    
    bsc = "https://bsc-dataseed.binance.org/"
    web3 = Web3(Web3.HTTPProvider(bsc))
    print(web3.is_connected())
    #pancakeswap router     #pancakeswap router abi 
    panRouterContractAddress = '0x10ED43C718714eb63d5aA57B78B54704E256024E'
    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"}]'
    #balance = web3.eth.get_balance(sender_address)
    
    #humanReadable = web3.from_wei(balance,'ether')
    
    #Contract Address of Token we want to buy
    spend = web3.toChecksumAddress("0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c")  #wbnb contract
    
    #Setup the PancakeSwap contract
    contract = web3.eth.contract(address=panRouterContractAddress, abi=panabi)
    nonce = web3.eth.get_transaction_count(sender_address)
    start = time.time()
    print(sender_address)
    checksum_address_sender = web3.toChecksumAddress(sender_address)
    checksum_address_tokenToBuy = web3.toChecksumAddress(tokenToBuy)
    print(checksum_address_sender)
    totaltoken = 1000000000000000000 * int(amountToken)
    totalBNB = (float(prixNative) * float(amountToken) * 1.01 + float(0.000737585))
    pancakeswap2_txn = contract.functions.swapETHForExactTokens(
    totaltoken, # set to 0, or specify minimum amount of tokeny you want to receive - consider decimals!!!
     # set to 0, or specify minimum amount of tokeny you want to receive - consider decimals!!!
    [spend,checksum_address_tokenToBuy],
    checksum_address_sender,
    (int(time.time()) + 10000)
    ).build_transaction({
    'from': checksum_address_sender,
    'value': web3.toWei(totalBNB,'ether'),#This is the Token(BNB) amount you want to Swap from
    'gas': 250000,
    'gasPrice': web3.toWei('5','gwei'),
    'nonce': nonce,
    })
        
    signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key="privatekey")
    tx_token = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
    print("TRX : " + web3.to_hex(tx_token))
    trxfinal = web3.to_hex(tx_token)
    return trxfinal
 
    

while True:
    time.sleep(1)

    if prompt_token_address:
        price_now = analyser_prix(prompt_token_address)
        print(st.session_state.bool1)
        prompt_addres_userBNB = "0xD7eA51d434D0897DE93400b43341FB3115585111"
        prixNative = analyser_prixBNB(prompt_token_address)
        
        if st.session_state.bool1:
            print("CHECK PRICE TRADE 1")
            if price_now > st.session_state.price1:
                print("Trade Sell 1 : ")
                #st.session_state.trx1 = sellToken(st.session_state.amount1, prompt_addres_userBNB, prompt_token_address, prixNative)
                toggle_bool1()
                reset_value(1)
                st.write("Trade 1 done")

                st.experimental_rerun()
                
        if st.session_state.bool2:
            print("CHECK PRICE TRADE 2")
            if price_now > st.session_state.price2:
                print("Trade Sell 2 : ")
                #st.session_state.trx2 = sellToken(st.session_state.amount2, prompt_addres_userBNB, prompt_token_address, prixNative)
                toggle_bool2()
                st.write("Trade 2 done")
                reset_value(2)

                st.experimental_rerun()
 
        if st.session_state.bool3:
            print("CHECK PRICE TRADE 3")
            if price_now > st.session_state.price3:
                print("Trade Sell 3 : ")
                #st.session_state.trx3 = sellToken(st.session_state.amount3, prompt_addres_userBNB, prompt_token_address, prixNative)
                toggle_bool3()
                reset_value(3)

                st.experimental_rerun()
 
        if st.session_state.bool4:
            print("CHECK PRICE TRADE 4")
            if price_now < st.session_state.price4 and st.session_state.price4 > 0:
                print("Trade BUY 4 : ")
                #st.session_state.trx4 = buyToken(st.session_state.amount4, prompt_addres_userBNB, prompt_token_address, prixNative)
                toggle_bool4()
                reset_value(4)
                st.experimental_rerun()
                
        if st.session_state.bool5:
            print("CHECK PRICE TRADE 5")
            if price_now < st.session_state.price5 and st.session_state.price5 > 0:
                print("Trade BUY 5 : ")
               #st.session_state.trx5 =  buyToken(st.session_state.amount5, prompt_addres_userBNB, prompt_token_address, prixNative)
                toggle_bool5()
                reset_value(5)
                st.experimental_rerun()
                
        if st.session_state.bool6:
            print("CHECK PRICE TRADE 6")
            if price_now < st.session_state.price6 and st.session_state.price6 > 0:
                print("Trade BUY 6 : ")
                #st.session_state.trx6 = buyToken(st.session_state.amount6, prompt_addres_userBNB, prompt_token_address, prixNative)
                toggle_bool6()
                reset_value(6)
                st.experimental_rerun()   
                                   
    time.sleep(1)