-
Notifications
You must be signed in to change notification settings - Fork 2
/
coreFunctions.py
323 lines (274 loc) · 7.82 KB
/
coreFunctions.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
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#! python2
from __future__ import division
import pyautogui
import time
import pyperclip
pyautogui.Pause = 2
pyautogui.FailSafe = True
def start():
"function to automatically start trade tiger"
pyautogui.moveTo(0,765) #move to start button
pyautogui.click()
pyautogui.moveTo(100,76)
time.sleep(1)
#pyautogui.scroll(-300)
pyautogui.typewrite('trade')
time.sleep(2)
pyautogui.click(1155,267)
#pyautogui.PAUSE
time.sleep(15)
def login(loginId,membership_pass,trading_pass):
"loginId, membership_pass and trading_pass are strings to be passed "
pyautogui.hotkey('ctrl','l')
time.sleep(1)
pyautogui.click(740,340) # click on login id field
pyautogui.typewrite(loginId)
pyautogui.typewrite('\t')
time.sleep(0.25)
pyautogui.typewrite('\t')
pyautogui.typewrite(membership_pass)
pyautogui.typewrite('\t')
pyautogui.typewrite(trading_pass)
pyautogui.press('enter')
time.sleep(30)
def setup_marketwatch(script):
"script is a string that is to be traded on the bse .the script is the security symbol, example 'AAPL'"
pyautogui.press('f12')
time.sleep(1)
pyautogui.hotkey('ctrl','i')
time.sleep(0.5)
pyautogui.moveTo(881,300,duration = 0.5) #arrow to select the exchange - comment out if you want to trade NSE
pyautogui.click() #coment out for trading NSE
pyautogui.moveTo(870,344,duration = 0.5) #comment out if you want to trade NSE
pyautogui.click()
pyautogui.moveTo(787,333) #to type the name of the script
pyautogui.click()
pyautogui.press('backspace')
pyautogui.typewrite(script)
pyautogui.moveTo(648,385,duration=0.5) # select the first script in the list
#pyautogui.click(duration=0.5)
pyautogui.moveTo(656,547,duration=0.5) #add button
pyautogui.click()
pyautogui.moveTo(898,240) #close button
pyautogui.click()
""" fields in data
Exchange, -index = 68
Script_name,
pct_change,
Last_traded_qty,
Current,
Bid_qty,
Bid_price,
Offer_price,
Offer_qty,
Open,
High,
Low,
Close,
Last_updated_time,
Last_traded_time,
Last_traded_date,
Qty,
Total_buy_qty,
Total_sell_qty,
OI_difference,
Company_name,
#now index from last
Pivo_sup_3
Pivo_sup_2
Pivo_sup_1
Pivot
Pivot_res_1
Pivot_res_2
Pivot_res_3
P_quantity
P_close
P_low
P_High
P_open
"""
def get_data(coordinate):
pyautogui.moveTo(20,coordinate)
pyautogui.click()
pyautogui.hotkey('ctrl','c')
raw = pyperclip.paste()
raw = raw.split()
data =[]
for i in range(70,81):
data.append(eval(raw[i]))
for i in range(84,88):
data.append(eval(raw[i]))
for i in range(-12,-1):
data.append(raw[i])
fields = ['pct_change',
'Last_traded_qty',
'Current',
'Bid_qty',
'Bid_price',
'Offer_price',
'Offer_qty',
'Open',
'High',
'Low',
'Close',
'Pivo_sup_3',
'Pivo_sup_2',
'Pivo_sup_1',
'Pivot',
'Pivot_res_1',
'Pivot_res_2',
'Pivot_res_3',
'P_quantity',
'P_close',
'P_low',
'P_High',
'P_open']
final_data_dict = dict(zip(fields,data))
return final_data_dict
def buy(coordinate,current_price,quantity):
"only maxtrade -still need editing"
pyautogui.moveTo(20,coordinate)
pyautogui.click()
pyautogui.hotkey('shift','f1')
time.sleep(0.5)
pyautogui.moveTo(780,373) #quantity box
pyautogui.click()
pyautogui.press('delete')
pyautogui.typewrite(quantity)
pyautogui.moveTo(1060,406,duration=0.5) #order extension arrow
pyautogui.click()
pyautogui.moveTo(1060,493) #select brkt +tsl
pyautogui.click()
time.sleep(0.5)
"""
book_profit =
stop_loss =
limit_loss =
"""
pyautogui.moveTo(400,540,duration=0.5) #book profit area
pyautogui.clcik()
pyautogui.press('delete')
pyautogui.typewrite(book_profit)
pyautogui.moveTo(500,540,duration = 0.5) #stop loss area
pyautogui.click()
pyautogui.press('delete')
pyautogui.typewrite(stop_loss)
pyautogui.moveTo(600,540,duration=0.5) #limit loss area
pyautogui.clcik()
pyautogui.press('delete')
pyautogui.typewrite(limit_loss)
pyautogui.moveTo(880,540,duration = 0.5) #place buton
pyautogui.click()
time.sleep(0.5)
pyautogui.moveTo(530,470,duration = 0.5) #confirm button
pyautogui.click()
def sell(coordinate,current_price,quantity):
"only maxtrade -still need editing"
pyautogui.moveTo(20,coordinate)
pyautogui.click()
pyautogui.hotkey('shift','f2')
time.sleep(0.5)
pyautogui.moveTo(780,373) #quantity box
pyautogui.click()
pyautogui.press('delete')
pyautogui.typewrite(quantity)
pyautogui.moveTo(1060,406,duration=0.5) #order extension arrow
pyautogui.click()
pyautogui.moveTo(1060,493) #select brkt +tsl
pyautogui.click()
time.sleep(0.5)
"""
book_profit =
stop_loss =
limit_loss =
"""
pyautogui.moveTo(400,540,duration=0.5) #book profit area
pyautogui.clcik()
pyautogui.press('delete')
pyautogui.typewrite(book_profit)
pyautogui.moveTo(500,540,duration = 0.5) #stop loss area
pyautogui.click()
pyautogui.press('delete')
pyautogui.typewrite(stop_loss)
pyautogui.moveTo(600,540,duration=0.5) #limit loss area
pyautogui.clcik()
pyautogui.press('delete')
pyautogui.typewrite(limit_loss)
pyautogui.moveTo(880,540,duration = 0.5) #place buton
pyautogui.click()
time.sleep(0.5)
pyautogui.moveTo(530,470,duration = 0.5) #confirm button
pyautogui.click()
def short(coordinate,current_price,quantity):
"only maxtrade -still need editing"
pyautogui.moveTo(20,coordinate)
pyautogui.click()
pyautogui.hotkey('ctrl','e')
time.sleep(0.5)
pyautogui.moveTo(780,373) #quantity box
pyautogui.click()
pyautogui.press('delete')
pyautogui.typewrite(quantity)
pyautogui.moveTo(570,433,duration = 0.5) #product type arrow
pyautogui.click()
pyautogui.moveTo(567,481,duration = 0.5) #bigtrade selctor
pyautogui.click()
pyautogui.moveTo(1060,406,duration=0.5) #order extension arrow
pyautogui.click()
pyautogui.moveTo(1060,493) #select brkt +tsl
pyautogui.click()
time.sleep(0.5)
"""
book_profit =
stop_loss =
limit_loss =
"""
pyautogui.moveTo(400,540,duration=0.5) #book profit area
pyautogui.clcik()
pyautogui.press('delete')
pyautogui.typewrite(book_profit)
pyautogui.moveTo(500,540,duration = 0.5) #stop loss area
pyautogui.click()
pyautogui.press('delete')
pyautogui.typewrite(stop_loss)
pyautogui.moveTo(600,540,duration=0.5) #limit loss area
pyautogui.clcik()
pyautogui.press('delete')
pyautogui.typewrite(limit_loss)
pyautogui.moveTo(880,540,duration = 0.5) #place buton
pyautogui.click()
time.sleep(0.5)
pyautogui.moveTo(530,470,duration = 0.5) #confirm button
pyautogui.click()
clear_positions():
"""Settle all longs and shorts"""
confirm_order():
"""check after six seconds if the order went throgh and return status and cancel if order not filled"""
time.sleep(6)
pyautogui.moveTo(226,34,duration = 0.5) #reports button
pyautogui.click()
pyautogui.moveTo(40,,65,duration = 0.5) #orders button
pyautogui.click()
time.sleep(0.5)
pyautogui.moveTo(290,280,duration = 0.5) #latest order
pyautogui.click()
pyautogui.hotkey('ctrl','c')
raw_str = pyperclip.paste()
raw_arr = raw_str.split()
status = raw_arr[14] #need to check
if status == 'Fully Executed':
return 1
else:
pyautogui.moveTo(790,215,duration = 0.5) #cancel button
pyautogui.click()
time.sleep(0.5)
pyautogui.moveTo(530,470,duration = 0.5) #confirm button
pyautogui.click()
"need to chck additional procedures"
return 0
#start()
#time.sleep(5)
#setup_marketwatch('ICICIBANK')
#time.sleep(5)
#x = get_data(238)
#print x