This repository has been archived by the owner on Apr 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
driver.py
94 lines (82 loc) · 2.44 KB
/
driver.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
'''
MarketWatch API
April 17, 2017
Probably ready for use.
'''
from MarketWatch import *
import os
def printOrder(order):
print("Order: %d" % order.id)
print("Ticker: %s" % order.ticker)
print("Quantity: %d" % order.quantity)
print("Order Type: %s" % order.orderType)
print("Price Type: %s" % order.priceType)
if (order.price != None):
print("Price: $%.2f" % order.price)
print("\n")
email = ''
password = ''
game = ''
try:
email = os.environ['MARKETWATCH_EMAIL']
password = os.environ['MARKETWATCH_PASSWORD']
game = os.environ['MARKETWATCH_GAME']
print('Your credentials have been successfully read from your env variables.')
except KeyError:
print('You have not set your MarketWatch credentials in your env variables.\n'
+ 'Please input your credentials for this session now.')
email = input('Email: ')
password = input('Password: ')
game = input('Game: ')
print('Your credentials have been successfully saved for just this session.')
api = MarketWatch(email, password, game, True)
'''
api.cancelAllOrders()
orders = api.getOrders()
for item in orders:
printOrder(item)
print(api.validateTicker("APPL"))
print(api.validateTicker("APPLKLJDZF"))
print(api.validateTicker("AAPL"))
print(api.validateTicker("JNUG"))
print(api.validateTicker("SNAP"))
print(api.validateTicker("GOOG"))
orders = {
"JNUG": 1,
"IBM": 2,
"SNAP": 3,
"GOOG": 4
}
for i in orders:
print(i + ': ' + str(orders[i]))
response = api.cover(i, orders[i])
if (response['succeeded']):
print("Successfully submitted order.")
else:
print("Order failed.")
print(response)
api.buy("SNAP", 1)
api.sell("SNAP", 1)
api.short("SNAP", 1)
api.cover("SNAP", 1)
print("")
api.buy("SNAP", 1, Term.DAY)
api.sell("SNAP", 1, Term.DAY)
api.short("SNAP", 1, Term.DAY)
api.cover("SNAP", 1, Term.DAY)
print("")
api.buy("SNAP", 1, Term.INDEFINITE, PriceType.MARKET)
api.sell("SNAP", 1, Term.INDEFINITE, PriceType.MARKET)
api.short("SNAP", 1, Term.INDEFINITE, PriceType.MARKET)
api.cover("SNAP", 1, Term.INDEFINITE, PriceType.MARKET)
print("")
api.buy("SNAP", 1, Term.INDEFINITE, PriceType.LIMIT, 1)
api.sell("SNAP", 1, Term.INDEFINITE, PriceType.LIMIT, 1)
api.short("SNAP", 1, Term.INDEFINITE, PriceType.LIMIT, 1)
api.cover("SNAP", 1, Term.INDEFINITE, PriceType.LIMIT, 1)
print("")
api.buy("SNAP", 1, Term.INDEFINITE, PriceType.STOP, 1)
api.sell("SNAP", 1, Term.INDEFINITE, PriceType.STOP, 1)
api.short("SNAP", 1, Term.INDEFINITE, PriceType.STOP, 1)
api.cover("SNAP", 1, Term.INDEFINITE, PriceType.STOP, 1)
'''