-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mt4.au3
143 lines (103 loc) · 4.25 KB
/
mt4.au3
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
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ScreenCapture.au3>
;#include <GUIListViewEx.au3>
#include <GuiComboBoxEx.au3>
#include <GuiComboBox.au3>
#include <HTTP.au3>
#include <JSON.au3>
;~ #include 'scriptingdic.au3'
;~ #include <Array.au3> ; Needed only for _ArrayDisplay, and not required by the lib
;~ Global $priceObj = _InitDictionary()
Func ComboBox_SelectString($winTitle, $winText, $control, $option)
Local $hWnd = ControlGetHandle($winTitle, $winText, $control)
Local $index = _GUICtrlComboBox_FindString($hWnd, $option)
If $index = -1 Then
SetError(1)
Return False
EndIf
;_GUICtrlComboBox_ShowDropDown($hWnd, True)
;_GUICtrlComboBox_SetCurSel($hWnd, $index)
;_GUICtrlComboBox_ShowDropDown($hWnd)
If $index = 0 Then
; If the item is the first in the list, use hotkeys to navigate to it
_GUICtrlComboBox_ShowDropDown($hWnd, True)
ControlSend($winTitle, $winText, $hWnd, "{PGUP}")
_GUICtrlComboBox_ShowDropDown($hWnd)
Else
; Select the item right before the target index, then send down
_GUICtrlComboBox_ShowDropDown($hWnd, True)
_GUICtrlComboBox_SetCurSel($hWnd, $index - 1)
ControlSend($winTitle, $winText, $hWnd, "{DOWN}")
_GUICtrlComboBox_ShowDropDown($hWnd)
EndIf
Return True
EndFunc ;==>ComboBox_SelectString
Func Example($verbose)
; Retrieve the position as well as height and width of the active window.
Local $hWin = WinWait("[CLASS:MetaQuotes::MetaTrader::4.00]", "", 10)
Local $hwnd = ControlGetHandle($hWin, "", "[CLASS:ToolbarWindow32; INSTANCE:4]")
; WinActivate($hWin)
;~ Send("{down}") ;;;select a random item
;~ ConsoleWrite("Window handle: " & $hWin & @LF)
;~ ConsoleWrite("Control handle: " & $hwnd & @LF)
Local $tradeData = _HTTP_Get("http://localhost/data")
local $tradeObj = Json_Decode($tradeData)
;~ ; test
;~ $priceObj.Add("1.10756", True)
Local $i = 0
While 1
Local $id = '[' & $i & '].'
Local $symbol = Json_Get($tradeObj, $id & 'symbol')
If @error Then ExitLoop
Local $price = Json_Get($tradeObj, $id & 'price')
Local $type = Json_Get($tradeObj, $id & 'type')
Local $volume = Json_Get($tradeObj, $id & 'size')
Local $orderType = ""
If $type == "sell" Then
$orderType = "Sell Limit"
Else
$orderType = "Buy Limit"
Endif
ControlClick($hwnd, "", "","left", 1, 280, 10)
Local $hOrderWin = WinWait("Order", "", 10)
Local $hVolume = ControlGetHandle($hOrderWin, "", "[CLASS:Edit; INSTANCE:1]")
;~ ConsoleWrite("Order handle: " & $hOrderWin & @LF)
;~ ControlSetText($hOrderWin, "", "[CLASS:Edit; INSTANCE:1]", $volume)
ComboBox_SelectString($hOrderWin, "", "[CLASS:ComboBox; INSTANCE:2]", $volume)
ComboBox_SelectString($hOrderWin, "", "[CLASS:ComboBox; INSTANCE:1]", $symbol)
ComboBox_SelectString($hOrderWin, "", "[CLASS:ComboBox; INSTANCE:3]", "Pending Order")
ComboBox_SelectString($hOrderWin, "", "[CLASS:ComboBox; INSTANCE:5]", $orderType)
ControlSetText($hOrderWin, "", "[CLASS:Edit; INSTANCE:6]", $price)
$mPrice = ControlGetHandle($hOrderWin, "", "[CLASS:Edit; INSTANCE:6]")
ControlClick($mPrice, "", "","left", 2, 60, 10)
ControlSend($hOrderWin, "", "[CLASS:Edit; INSTANCE:6]", $price)
;~ Send($price)
;~ trigger increase then decrease to change data of price
;~ $udPrice = ControlGetHandle($hOrderWin, "", "[CLASS:msctls_updown32; INSTANCE:3]");
;~ ControlClick($udPrice, "", "","left", 1, 9, 2)
;~ ControlClick($udPrice, "", "","left", 1, 9, 14)
Sleep(1000)
;~ click place then done
Local $hPlace = ControlGetHandle($hOrderWin, "", "[CLASS:Button; INSTANCE:16]")
;~ ConsoleWrite("Place handle: " & $hPlace & @LF)
ControlClick($hPlace, "", "","left", 1, 5, 5)
;~ update command
_HTTP_Post("http://localhost/data", "price=" & URLEncode($price))
ConsoleWrite("symbol: " & $symbol & " type: " & $orderType & " volume: " & $volume & " price: " & $price & @LF)
;~ close button ok if there is
Local $hOK = ControlGetHandle($hOrderWin, "", "[CLASS:Button; INSTANCE:22]")
ControlClick($hOK, "", "","left", 1, 5, 5)
Sleep(500)
$i += 1
WEnd
Sleep(2000)
Example($verbose)
EndFunc ;==>Example
;~ While 1
;~ Sleep(2000)
;~ Example(17, 0, 0)
;~ Example(1, 1, 0)
;~ WEnd
Example(0)