-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTZController.py
More file actions
263 lines (205 loc) · 6.88 KB
/
Copy pathTZController.py
File metadata and controls
263 lines (205 loc) · 6.88 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
from pynput.mouse import Button, Controller as mController
from pynput.keyboard import Key, Controller as kController
import clipboard
from enum import Enum
import time
class MOUSE_POS(Enum):
"""
Mouse position enumerater
Config specific input or button's cursor position
"""
TITLE_TICKER = (1365, 23)
INPUT_TICKER = (1286, 57)
INPUT_PRICE = (1273, 492)
INPUT_QUANTITY = (1270, 462)
INPUT_QUANTITY_COPY = (1331, 496)
BTN_POSITION = (1282, 529)
BTN_BUY = (1287, 551)
BTN_SELL = (1371, 549)
BTN_SHORT = (1466, 545)
BTN_COVER = (1560, 549)
BTN_CANCEL = (1369, 527)
CDT_INPUT_TICKER = (71, 50)
CDT_1st_ACTION_SEL = (122, 140)
CDT_1st_ACTION_BUY = (85, 158)
CDT_1st_ACTION_SHORT = (81, 195)
CDT_1st_INPUT_QTY = (182, 142)
CDT_1st_TYPE_SEL = (326, 141)
CDT_1st_TYPE_LIMIT = (299, 176)
CDT_1st_INPUT_PRICE = (193, 173)
CDT_2nd_ACTION_SEL = (120, 259)
CDT_2nd_ACTION_SELL = (76, 296)
CDT_2nd_ACTION_COVER = (83, 331)
CDT_2nd_INPUT_QTY = (191, 262)
CDT_2nd_TYPE_SEL = (326, 260)
CDT_2nd_TYPE_RANGE = (290, 385)
CDT_2nd_INPUT_HIGH_PRICE = (407, 297)
CDT_2nd_INPUT_LOW_PRICE = (518, 296)
CDT_BTN_SEND = (93, 356)
CDT_BTN_CANCEL = (245, 355)
class TZController:
__ms = mController()
__kb = kController()
_origin_pos = None
def __init__(self):
return
'''
Some basic functions
'''
def __time_break(self):
time.sleep(0.1)
def _click(self, pos):
self.__ms.position = pos.value
self.__ms.click(Button.left)
self.__time_break()
def _dbl_clk(self, pos):
self.__ms.position = pos.value
self.__ms.click(Button.left, 2)
self.__time_break()
def _r_click(self, pos):
self.__ms.position = pos.value
self.__ms.click(Button.right)
self.__time_break()
def _typein(self, text):
self.__kb.type(text)
self.__time_break()
self.__kb.press(Key.enter)
self.__kb.release(Key.enter)
self.__time_break()
'''
Regular Order Actions
'''
def ticker(self, symbol):
'''
Change ticker for regular order & chartingd window
'''
self._dbl_clk( MOUSE_POS.TITLE_TICKER )
self._typein(symbol)
def price(self, price):
'''
Set order price
'''
self._dbl_clk( MOUSE_POS.INPUT_PRICE )
self._typein(str(price))
self._click( MOUSE_POS.TITLE_TICKER )
def qty(self, qty):
'''
Set order quantity
'''
self._dbl_clk( MOUSE_POS.INPUT_QUANTITY )
self._typein(str(qty))
self._click( MOUSE_POS.TITLE_TICKER )
def lmt(self, qty, price):
'''
Prepare lmt order with qty/price
'''
self.qty(qty)
self.price(price)
def buy(self):
'''
Click BUY button
'''
self._click( MOUSE_POS.BTN_BUY )
def sell(self):
'''
Click SELL button
'''
self._click( MOUSE_POS.BTN_SELL )
def short(self):
'''
Click SHORT button
'''
self._click( MOUSE_POS.BTN_SHORT )
def cover(self):
'''
Click COVER button
'''
self._click( MOUSE_POS.BTN_COVER )
def cancel(self):
'''
Click CANCEL button
'''
elf.__ms.position = MOUSE_POS.BTN_CANCEL.value
self.__ms.click(Button.left)
'''
Conditional Order Actions
'''
def cdt_ticker(self, symbol):
'''
Change ticker in Condition order window
Ensure condition order window opening
'''
self._dbl_clk( MOUSE_POS.CDT_INPUT_TICKER )
self._typein(symbol)
def cdt_buy_then_sell(self, target, stop, price, qty):
'''
Conditional order 1
'''
self._click( MOUSE_POS.CDT_1st_ACTION_SEL )
self._click( MOUSE_POS.CDT_1st_ACTION_BUY )
self._click( MOUSE_POS.CDT_1st_TYPE_SEL )
self._click( MOUSE_POS.CDT_1st_TYPE_LIMIT )
self._dbl_clk( MOUSE_POS.CDT_1st_INPUT_QTY )
self._typein(str(qty))
self._dbl_clk( MOUSE_POS.CDT_1st_INPUT_PRICE )
self._typein(str(price))
'''
Conditional order 2
'''
self._click( MOUSE_POS.CDT_2nd_ACTION_SEL )
self._click( MOUSE_POS.CDT_2nd_ACTION_SELL )
self._click( MOUSE_POS.CDT_2nd_TYPE_SEL )
self._click( MOUSE_POS.CDT_2nd_TYPE_RANGE )
self._dbl_clk( MOUSE_POS.CDT_2nd_INPUT_QTY )
self._typein(str(qty))
self._dbl_clk( MOUSE_POS.CDT_2nd_INPUT_HIGH_PRICE )
self._typein(str(target)) # higher price as target
self._dbl_clk( MOUSE_POS.CDT_2nd_INPUT_LOW_PRICE )
self._typein(str(stop)) # lower price as stop
def cdt_short_then_cover(self, target, stop, price, qty):
'''
Conditional order 1
'''
self._click( MOUSE_POS.CDT_1st_ACTION_SEL )
self._click( MOUSE_POS.CDT_1st_ACTION_SHORT )
self._click( MOUSE_POS.CDT_1st_TYPE_SEL )
self._click( MOUSE_POS.CDT_1st_TYPE_LIMIT )
self._dbl_clk( MOUSE_POS.CDT_1st_INPUT_QTY )
self._typein(str(qty))
self._dbl_clk( MOUSE_POS.CDT_1st_INPUT_PRICE )
self._typein(str(price))
'''
Conditional order 2
'''
self._click( MOUSE_POS.CDT_2nd_ACTION_SEL )
self._click( MOUSE_POS.CDT_2nd_ACTION_COVER )
self._click( MOUSE_POS.CDT_2nd_TYPE_SEL )
self._click( MOUSE_POS.CDT_2nd_TYPE_RANGE )
self._dbl_clk( MOUSE_POS.CDT_2nd_INPUT_QTY )
self._typein(str(qty))
self._dbl_clk( MOUSE_POS.CDT_2nd_INPUT_HIGH_PRICE )
self._typein(str(stop)) # higher price as stop
self._dbl_clk( MOUSE_POS.CDT_2nd_INPUT_LOW_PRICE )
self._typein(str(target)) # lower price as target
def cdt_send(self):
self._click( MOUSE_POS.CDT_BTN_SEND )
def cdt_cancel(self):
self._click( MOUSE_POS.CDT_BTN_CANCEL )
'''
Get
'''
def cur_pos(self):
'''
Return current position size for current ticker
'''
self._dbl_clk( MOUSE_POS.INPUT_QUANTITY )
self._r_click( MOUSE_POS.INPUT_QUANTITY )
self._click( MOUSE_POS.INPUT_QUANTITY_COPY )
return clipboard.paste()
def get_mouse_pos(self):
'''
Put your mouse on certain input or button,
Run this function to get its position,
Copy & paste it to config
'''
print('The current pointer position is {0}'.format(mController().position))