forked from OddPudding/Binance-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot1
64 lines (53 loc) · 2 KB
/
bot1
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
from binance.client import Client
from binance.enums import *
import time
api_key = ''
api_secret = ''
tradePair = 'BTCBUSD'
client = Client(api_key, api_secret)
# Initial values
lastrade = 'BTC'
lasprice = 45351.94
winRate = 1.035
while True:
# Price & Server Time
price = client.get_ticker(symbol='BTCBUSD')
coitime = client.get_server_time()
coitime = time.strftime('%m/%d/%Y %H:%M:%S',
time.gmtime(coitime['serverTime']/1000.))
# SELL BTC (since last trade is BTC)
if lastrade == 'BTC':
balance = client.get_asset_balance(asset='BTC')
coiNumber = format(float(balance['free']),'.4f')
coiprice = format(float(price['askPrice']), '.2f')
if float(coiprice) > lasprice * winRate:
stat = 'sell'
order = client.order_limit_sell(
symbol='BTCBUSD',
quantity= float(coiNumber),
price= coiprice)
lastrade = 'BUSD'
lasprice = coiprice
time.sleep(30) # Wait 0.5 minutes to do the trade
else:
stat = 'hold BTC'
# BUY BTC (since last trade is BUSD)
elif lastrade == 'BUSD':
balance = client.get_asset_balance(asset='BUSD')
coiNumber = format(float(balance['free']),'.4f')
coiprice = format(float(price['askPrice']), '.2f')
test = float(coiNumber)/float(coiprice)
if float(coiprice) * winRate < lasprice:
stat = 'buy'
order = client.order_limit_buy(
symbol='BTCBUSD',
quantity=format(test, '.4f'),
price= coiprice)
lastrade = 'BTC'
lasprice = coiprice
time.sleep(30) # Wait 0.5 minutes to do the trade
else:
stat = 'hold BUSD'
# Print the values
print(coitime + ' ' + balance['free'] + ' ' + price['askPrice'] + ' ' + stat)
time.sleep(60) # Repeat the code every minute