Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;default icons here %SystemRoot%\system32\SHELL32.dll
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #include <Inet.au3>
- #include <JSON.au3>
- #include <File.au3>
- #include <FontConstants.au3>
- #include <GUIConstantsEx.au3>
- #Region ### START Koda GUI section ### Form=
- Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
- Opt("TrayIconHide", 0)
- $stock_watcher = GUICreate("stock_watcher", 97, 93, 473, 309, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE,$WS_EX_TOOLWINDOW))
- ;GUICtrlSetFont(-1, 9, $FW_NORMAL, $GUI_FONTUNDER, "Comic Sans Ms 2pt") ;
- ;GUISetFont(8, $FW_NORMAL, $GUI_FONTUNDER, "Comic Sans Ms")
- $Total = GUICtrlCreateLabel("Result", 1, 0, 41, 17)
- GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
- $total_val = GUICtrlCreateLabel("0", 48, 0, 42, 17)
- GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
- $amont = GUICtrlCreateInput("amount", 0, 32, 41, 21)
- GUICtrlSetTip( -1, "amount")
- GUICtrlSetOnEvent(-1, "setamount")
- $prce = GUICtrlCreateInput("price", 48, 32, 49, 21) ;buy price
- GUICtrlSetTip( -1, "price")
- GUICtrlSetOnEvent(-1, "setprice")
- $last_deal = GUICtrlCreateLabel("last deal", 2, 15, 43, 17)
- $last_deal_val = GUICtrlCreateLabel("0", 48, 15, 42, 17)
- $long = GUICtrlCreateRadio("long", 0, 54, 41, 17)
- GUICtrlSetOnEvent(-1, "setlong")
- $short = GUICtrlCreateRadio("short", 48, 54, 49, 17)
- GUICtrlSetOnEvent(-1, "setshort")
- $stp = GUICtrlCreateInput("0.01", 0, 72, 41, 21)
- GUICtrlSetTip( -1, "step")
- $stp_price = GUICtrlCreateInput("5.7", 48, 72, 49, 21)
- GUICtrlSetTip( -1, "step price")
- GUICtrlSetOnEvent(-1, "setstepprice")
- GUISetState(@SW_SHOW)
- GUISetOnEvent($GUI_EVENT_CLOSE, "stop")
- GUIRegisterMsg($WM_COMMAND, "ED_WM_COMMAND")
- ControlFocus($stock_watcher, "", $Total)
- ;HotKeySet("{ESC}", "nullfunc")
- #EndRegion ### END Koda GUI section ###
- global $dfile = "data";
- loaddata();
- Global $iter = 100;
- Global $lastdeal = 0;
- global $step_price = ControlGetText($stock_watcher, "", $stp_price)
- global $amount = ControlGetText($stock_watcher, "", $amont)
- global $price = ControlGetText($stock_watcher, "", $prce)
- global $way = 0;
- If GUICtrlRead($long) = 1 Then
- $way = 1
- ElseIf GUICtrlRead($short) = 1 Then
- $way = -1
- EndIf
- global $step = 0.01
- global $step_price = 5.7
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $amont
- Case $price
- EndSwitch
- Sleep(1000)
- if $iter < 9 Then
- $iter = $iter + 1
- Else
- $iter = 0
- update()
- EndIf
- WEnd
- Func ED_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
- #forceref $hWnd, $iMsg
- Local $iCode = BitShift($wParam, 16)
- Switch $lParam
- Case GUICtrlGetHandle($prce)
- Switch $iCode
- Case $EN_SETFOCUS
- if ControlGetText($stock_watcher, "", $prce) = "price" then
- ControlSetText($stock_watcher, "", $prce, "")
- EndIf
- Case $EN_KILLFOCUS
- ;GUICtrlSetData($hLabel, "Edit does not have focus")
- EndSwitch
- Case GUICtrlGetHandle($amont)
- Switch $iCode
- Case $EN_SETFOCUS
- if ControlGetText($stock_watcher, "", $amont) = "amount" then
- ControlSetText($stock_watcher, "", $amont, "")
- EndIf
- Case $EN_KILLFOCUS
- ;GUICtrlSetData($hLabel, "Edit does not have focus")
- EndSwitch
- EndSwitch
- Return $GUI_RUNDEFMSG
- EndFunc ;==>ED_WM_COMMAND
- Func setamount()
- $amount = ControlGetText($stock_watcher, "", $amont)
- ControlFocus($stock_watcher, "", $Total)
- savedata("amount",$amount);
- EndFunc
- Func setprice()
- $price = ControlGetText($stock_watcher, "", $prce)
- ControlFocus($stock_watcher, "", $Total)
- savedata("price",$price);
- EndFunc
- Func setlong()
- $way = 1
- savedata("way","1");
- EndFunc
- Func setshort()
- $way = -1
- savedata("way","-1");
- EndFunc
- Func setstepprice()
- $step_price = ControlGetText($stock_watcher, "", $stp_price)
- EndFunc
- Func stop()
- exit
- EndFunc
- Func nullfunc()
- EndFunc
- Func update()
- if $way = 0 Then
- return;
- EndIf
- local $d = _INetGetSource('http://www.cmegroup.com/CmeWS/mvc/Quotes/FutureContracts/XNYM/G?quoteCodes=clk8') ;NYMEX:CLK2018
- Local $objJson = json_Decode($d)
- Local $lastdeal_new = json_Get($objJson, '["quotes"][0]["last"]');.Keys[0]
- if $lastdeal <> $lastdeal_new Then
- $lastdeal = $lastdeal_new
- ControlSetText("stock_watcher", "", $last_deal_val, $lastdeal)
- EndIf
- local $res
- if $way = 1 Then
- $res = ((($lastdeal - $price) / $step) * $step_price) * $amount
- ElseIf $way = -1 Then
- $res = ((($price - $lastdeal) / $step) * $step_price) * $amount
- EndIf
- ControlSetText("stock_watcher", "", $total_val, $res)
- EndFunc
- Func savedata($line,$nd)
- Local $aRetArray, $d
- _FileReadToArray($dfile, $aRetArray)
- for $i=1 to $aRetArray[0]
- $d = StringSplit($aRetArray[$i], ";")
- if $d[1]=$line Then
- $aRetArray[$i] = $d[1]&";"&$nd
- ConsoleWrite($aRetArray[$i]&@CRLF);
- EndIf
- Next
- _FileWriteFromArray($dfile, $aRetArray, $FRTA_COUNT , Default, @CRLF)
- EndFunc
- Func loaddata()
- Local $aRetArray
- _FileReadToArray($dfile, $aRetArray)
- ;_ArrayDisplay($aRetArray, "1D array - count", Default, 8)
- local $d = StringSplit($aRetArray[1], ";")
- ControlSetText($stock_watcher, $d[2], $amont, $d[2])
- $d = StringSplit($aRetArray[2], ";")
- ControlSetText($stock_watcher, $d[2], $prce, $d[2])
- $d = StringSplit($aRetArray[3], ";")
- if $d[2]="1" then
- GUICtrlSetState ($long, $GUI_CHECKED)
- ElseIf $d[2]="-1" Then
- GUICtrlSetState ($short, $GUI_CHECKED)
- EndIf
- EndFunc
Add Comment
Please, Sign In to add comment