-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientpy3.py
More file actions
120 lines (89 loc) · 2.94 KB
/
clientpy3.py
File metadata and controls
120 lines (89 loc) · 2.94 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import socket
import sys
def run(user, password, *commands):
HOST, PORT = "codebb.cloudapp.net", 17429
data=user + " " + password + "\n" + "\n".join(commands) + "\nCLOSE_CONNECTION\n"
returnArray = []
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((HOST, PORT))
sock.sendall(bytes(data, "utf-8"))
sfile = sock.makefile()
rline = sfile.readline()
while rline:
returnArray.append(rline.strip())
rline = sfile.readline()
return (returnArray)
def subscribe(user, password):
HOST, PORT = "codebb.cloudapp.net", 17429
data=user + " " + password + "\nSUBSCRIBE\n"
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((HOST, PORT))
sock.sendall(bytes(data, "utf-8"))
sfile = sock.makefile()
rline = sfile.readline()
while rline:
print(rline.strip())
rline = sfile.readline()
def getSecurities():
usr = 'LimitlessDrive'
pw = 'stopeatinginvisiblecows123'
x = run(usr,pw,"SECURITIES")
y = x[0].split()
stockDict = {}
latestKey = ""
for i in range(1, len(y)):
if i % 4 == 1:
latestKey = y[i]
stockDict[latestKey] = ""
else:
stockDict[latestKey] = stockDict[latestKey] + (y[i]) + " "
for i in sorted(stockDict):
stockDict[i] = stockDict[i].split()
return stockDict
def getMySecurities():
usr = 'LimitlessDrive'
pw = 'stopeatinginvisiblecows123'
x = run(usr,pw, "MY_SECURITIES")
y = x[0].split()
stockDict = {}
latestKey = ""
for i in range(1, len(y)):
latestKey = y[i-1]
if i % 3 == 2:
if int(y[i]) > 0:
stockDict[latestKey] = y[i]
return stockDict
def getTop3(names, divs):
maxDiv = []
for i in range(3):
m = int(divs.index(max(divs)))
maxDiv.append(names[m])
divs.pop(m)
names.pop(m)
return maxDiv
def getCash():
usr = 'LimitlessDrive'
pw = 'stopeatinginvisiblecows123'
x = run(usr,pw, "MY_CASH")
y = x[0].split()
return float(y[1])
def maxBid(ticker):
parameter = "ORDERS " + ticker
maxBid = 0;
allOrders = run('LimitlessDrive', 'stopeatinginvisiblecows123', parameter)
separated = allOrders[0].split()
for i in range(1, len(separated)):
if separated[i] == 'BID':
if float (separated[i+2]) > maxBid:
maxBid = float (separated[i+2])
return round(maxBid, 3)
def minAsk(ticker):
parameter = "ORDERS " + ticker
minAsk = 100000000
allOrders = run('LimitlessDrive', 'stopeatinginvisiblecows123', parameter)
separated = allOrders[0].split()
for i in range(1, len(separated)):
if separated[i] == 'ASK':
if float (separated[i+2]) < minAsk:
minAsk = float (separated[i+2])
return round(minAsk, 3)