-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtestBot.py
54 lines (33 loc) · 921 Bytes
/
testBot.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
import sys
sys.path.insert(0, '../')
import random
from traderbot import TraderBot
robot = TraderBot()
stockArray = robot.getSymbols()
print "Stock Array", stockArray
size = len(stockArray)
print "Array Size", size
randomStockIdx = random.randint(0, size - 1)
randomStock = stockArray[randomStockIdx]
print "random stock ticker:", randomStock
price = robot.getPrice(randomStock)
print "stock price:", price
money = robot.getFunds()
maxShares = 100
confirmation = robot.buy(randomStock, maxShares)
if (confirmation == 1):
print "buy confirmed"
else:
print "buy failed"
portfolio = robot.getPortfolio()
print "Portfolio before selling:"
print portfolio
confirmation = robot.sell(randomStock, maxShares)
if (confirmation == 1):
print "sell confirmed"
else:
print "sell failed"
portfolio = robot.getPortfolio()
print "Portfolio before selling:"
for array in portfolio:
print array