· 4 years ago · Aug 01, 2021, 09:22 AM
1try:
2 from binance.client import Client
3except ModuleNotFoundError as e:
4 print("moduless not installed. Autoinstallation running now:")
5 import os
6 os.system("pip install python-binance")
7 os.system("pip install binance")
8 print("Instalation done, Aborting now. Please re-run the program")
9 import sys
10 sys.exit(1)
11try:
12 client = Client(input('Your API Key: '), input('Your secret key: '), testnet=True)
13except Exception as e:
14 print('Error: ', e)
15
16
17# Step 1:
18try:
19 for i in client.get_account()['balances']:
20 if float(i["free"]) > 0.000001 or float(i["locked"]) > 0.00001:
21 print('[*]', i['asset'], '(free:', i['free'], 'locked: ', i['locked']+')\n')
22except Exception as e:
23 print('Error: ', e)
24
25
26# Step 3:
27if input('Would you like to trade any currencies? ') == 'y':
28 coin1 = input('What currency would you like to sell? ')
29 coin2 = input('What currency would you like to buy? ')
30 amount = float(input('How much '+coin1+' would you like to sell? '))
31 print('\n')
32 if coin1 == 'BTC':
33 try:
34 client.order_market_sell(symbol=coin2+'BTC', quantity=amount)
35 except Exception as e:
36 print('Error: ', e)
37 else:
38 print('Trade complete.')
39 elif coin2 == 'BTC':
40 try:
41 client.order_market_buy(symbol=coin1+'BTC', quantity=amount)
42 except Exception as e:
43 print('Error: ', e)
44 else:
45 print('Trade complete.')
46 else:
47 try:
48 client.order_market_buy(symbol=coin1+'BTC', quantity=amount)
49 client.order_market_sell(symbol=coin2+'BTC', quantity=amount)
50 except Exception as e:
51 print('Error: ', e)
52 else:
53 print('Trade complete.')
54
55
56# Step 4:
57while True:
58 if input('Would you like to do a withdrawal? ') != 'y':
59 break
60 amount = float(input('How much would you like to withdraw? '))
61 asset = input('What asset would you like to withdraw? ')
62 address = input('Where would you like to send the money? ')
63 try:
64 client.withdraw(asset=asset, address=address, amount=amount)
65 except Exception as e:
66 print('Error: ', e)
67 print('Please try again.')
68 else:
69 print('Withdrawal complete.')