-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm1lib_dropped.py
59 lines (50 loc) · 1.79 KB
/
m1lib_dropped.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
# These functions are either no longer being used or have been replaced
# by a more efficient methodology.
#Function: orderPV()
#Usage: Purchases a M1 Portfolio based on the USD value (amount) and the accType
#Returns: True if purchase successful
def orderPV(amount, accType):
print ("Beginning Portfolio Purchase")
selectAccount(accType)
if amount < 0:
ticksell = 1
amount = amount * -1
if amount < 10:
DebugCommand("Orders under $10 cannot be processed")
return False
#try:
# driver.find_element_by_xpath("""//*[contains(text(), 'Buy/Sell')]""").click()
#except:
# pass
time.sleep(4)
try:
if ticksell == 1:
startSell()
usernameField = driver.find_element_by_name("cashFlow")
usernameField.send_keys(amount)
except:
DebugCommand("Could not access cashFlow element")
return False
confirmOrder()
if (verifyPV(accType) == True):
return True
#Function: CheckOpenOrder
#Usage: Returns Order value depending on accType
#Returns: Logs order information, "0" if pending order, "1" else
#TODO
def checkOpenPV(accType):
DebugCommand("Checking orders against Portfolio: " + accType)
selectAccount(accType)
try:
orderCompletion = driver.find_element_by_xpath("""//*[contains(text(), 'Pending')]""").text
DebugCommand(str(orderCompletion))
if "buy" in orderCompletion:
#RETURNS A BUY ORDER
print("PENDING BUY:" + str(re.findall(r"[-+]?\d*\.\d+|[-+]?\d+", orderCompletion)[0]))
return 0
elif "sell" in orderCompletion:
#RETURNS A SELL ORDER
print("PENDING SELL:" + str(re.findall(r"[-+]?\d*\.\d+|[-+]?\d+", orderCompletion)[0]))
return 0
except:
return 1