· 4 years ago · Jul 31, 2021, 10:28 PM
1from binance.client import Client
2
3try:
4 client = Client(input('Your API Key: '), input('Your secret key: '))
5except Exception as e:
6 print('Error: ', e)
7
8
9# Step 1:
10try:
11 for i in client.get_account()['balances']:
12 print('[*]', i['asset'], '(free:', i['free'], 'locked: ', i['locked']+')\n')
13except Exception as e:
14 print('Error: ', e)
15
16
17# Step 3:
18if input('Would you like to trade any currencies? ') == 'y':
19 coin1 = input('What currency would you like to sell? ')
20 coin2 = input('What currency would you like to buy? ')
21 amount = float(input('How much '+coin1+' would you like to sell? '))
22 print('\n')
23 if coin1 == 'BTC':
24 try:
25 client.order_market_sell(symbol=coin2+'BTC', quantity=amount)
26 except Exception as e:
27 print('Error: ', e)
28 else:
29 print('Trade complete.')
30 elif coin2 == 'BTC':
31 try:
32 client.order_market_buy(symbol=coin1+'BTC', quantity=amount)
33 except Exception as e:
34 print('Error: ', e)
35 else:
36 print('Trade complete.')
37 else:
38 try:
39 client.order_market_buy(symbol=coin1+'BTC', quantity=amount)
40 client.order_market_sell(symbol=coin2+'BTC', quantity=amount)
41 except Exception as e:
42 print('Error: ', e)
43 else:
44 print('Trade complete.')
45
46
47# Step 4:
48while True:
49 if input('Would you like to do a withdrawal? ') != 'y':
50 break
51 amount = float(input('How much would you like to withdraw? '))
52 asset = input('What asset would you like to withdraw? ')
53 address = input('Where would you like to send the money? ')
54 try:
55 client.withdraw(asset=asset, address=address, amount=amount)
56 except Exception as e:
57 print('Error: ', e)
58 print('Please try again.')
59 else:
60 print('Withdrawal complete.')
61