-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpublicBot.py
103 lines (88 loc) · 3.53 KB
/
publicBot.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
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
import random
#I'll need to change this to incorporate
from traderbot import TraderBot
robot = TraderBot()
stockArray = robot.getSymbols()
#initial loop
for ticker in stockArray:
portfolio = robot.getPortfolio()
if (portfolio[ticker] != 0):
#selling distribution:
#25 percent at market price
#10 percent at 10 percent above market price
#10 percent at 10 percent below market price
#5 percent at 5 percent below market price
marketFraction = 0.25
aboveMarket = 0.10
tenBelowMarket = 0.10
fiveBelowMarket = 0.05
price = robot.getPrice(ticker)
result = robot.ask((int)(portfolio[ticker] *marketFraction) , price, ticker)
if result == 'Accepted':
print "trade accepted"
elif result == 'Unsuccesful':
print "trade declined"
elif result == 'Pending':
print "trade pending"
else:
print "not a recognizable order state"
result = robot.ask((int)(portfolio[ticker]*aboveMarket), price*1.10, ticker)
if result == 'Accepted':
print "trade accepted"
elif result == 'Unsuccesful':
print "trade declined"
elif result == 'Pending':
print "trade pending"
else:
print "not a recognizable order state"
result = robot.ask((int)(portfolio[ticker]*tenBelowMarket), price*0.9, ticker)
if result == 'Accepted':
print "trade accepted"
elif result == 'Unsuccesful':
print "trade declined"
elif result == 'Pending':
print "trade pending"
else:
print "not a recognizable order state"
result = robot.ask((int)(portfolio[ticker]*fiveBelowMarket), price*0.95, ticker)
if result == 'Accepted':
print "trade accepted"
elif result == 'Unsuccesful':
print "trade declined"
elif result == 'Pending':
print "trade pending"
else:
print "not a recognizable order state"
while True:
for ticker in stockArray:
portfolio = robot.getPortfolio()
if (portfolio[ticker] != 0):
trueValue = robot.getTrueValue(ticker)
price = robot.getPrice(ticker)
increment = abs(trueValue - price)/3
#bid for 10 percent of the total stock @ market value
#bid for 4 percent of total stock @ below market value
#bid for 3 percent of total stock @ above market value
#bid for 2 percent of total stock @ significantly above market value
#bid for 1 percent of total stock @ true value
if trueValue/price >1.05:
stockToBuy = 0.2 * robot.getSellVolume(ticker)
robot.bid((int)(stockToBuy/2), price, ticker)
stockToBuy/= 2
robot.bid((int)(stockToBuy*0.4), price - increment, ticker)
robot.bid((int)(stockToBuy*0.3), price + increment, ticker)
robot.bid((int)(stockToBuy*0.2), price + 2 * increment, ticker)
robot.bid((int)(stockToBuy*0.1), price + 3 * increment, ticker)
#ask for 10 percent of the total stock @ market value
#ask for 4 percent of total stock @ above market value
#ask for 3 percent of total stock @ below market value
#ask for 2 percent of total stock @ significantly below market value
#ask for 1 percent of total stock @ true value
if trueValue/price < 0.95:
stockToSell = 0.3 * portfolio[ticker]
robot.ask((int)(stockToSell/2), price, ticker)
stockToSell/= 2
robot.ask((int)(stockToSell*0.4), price + increment, ticker)
robot.ask((int)(stockToSell*0.3), price - increment, ticker)
robot.ask((int)(stockToSell*0.2), price - 2 * increment, ticker)
robot.ask((int)(stockToSell*0.1), price - 3 * increment, ticker)