-
Notifications
You must be signed in to change notification settings - Fork 3
/
handle_transactions.py
78 lines (61 loc) · 2.29 KB
/
handle_transactions.py
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
import time
import argparse
from binance import Client
from binance.enums import *
# #
# Command line argument parser
# #
parser = argparse.ArgumentParser(
description='Optional bot arguments.')
parser.add_argument("--time_to_sell", type=int,
help="Specify how long until you want the bot to sell the dogecoin")
args = parser.parse_args()
# Send a buy order request
def doge_order_request(client):
# Get DOGE price
doge_price = client.get_symbol_ticker(symbol="DOGEUSDT")
# Calculate how much DOGE $25 can buy
buy_quantity = round(25 / float(doge_price['price']))
# Create & Process Order
try:
client.create_test_order(
symbol='DOGEUSDT',
side=Client.SIDE_BUY,
type=Client.ORDER_TYPE_MARKET,
quantity=buy_quantity
)
print('✅ Bought', buy_quantity, 'DOGE at', doge_price['price'] + "\n")
# Determine how long to wait until selling
tts_value = args.time_to_sell
sleep_sec = tts_value * 60
if sleep_sec >= 240:
print("🟡 Waiting " + str(tts_value) + " minute/s until selling")
time.sleep(sleep_sec)
# Send sell request after tts has finished
doge_sell_request(client)
elif sleep_sec < 240:
print("🟡 Waiting " + str(tts_value) + " minute/s until selling")
time.sleep(sleep_sec)
# Send sell request after tts has finished
doge_sell_request(client)
# Sleep the difference in time so the program always waits 4 minutes before scanning tweets again
time.sleep(240 - sleep_sec)
else:
return
except:
return
# Send a sell order at market price. Market orders are transactions meant to execute as quickly as possible at the current market price.
def doge_sell_request(client):
# Get DOGE price
doge_price = client.get_symbol_ticker(symbol="DOGEUSDT")
# Calculate how much DOGE $25 can sell
sell_quantity = round(25 / float(doge_price['price']))
# Create & Process Order
try:
client.order_market_sell(
symbol='DOGEUSDT',
quantity=sell_quantity
)
print('📈 Sold', sell_quantity, 'DOGE at', doge_price['price'] + '\n')
except:
return