Jump to content

Recommended Posts

Posted (edited)

Hi, im seeking to retrieve information from a website and place it in a listview, the idea is that the most recent values are in the column 2, and then at the subsequent data retrievals the values from the most recent column, go into the one next to it to the right, and the ones that were in that 3rd column go to the 4th column as to make some sort of history.

This is what i got so far

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Binance.ico
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Comment=By:careca
#AutoIt3Wrapper_Res_Description=Get Binance BTC Pairs Spikes
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Icon_Add=Binance.ico
;#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;=============================================================================
#Region ;Include + Opt
#include <IE.au3>
#include <Inet.au3>
#include <File.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <WinAPIGdi.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>
#include <TrayConstants.au3>
#include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#include <GuiScrollBars.au3>
#include <StaticConstants.au3>
#include <AutoItConstants.au3>
#include <WindowsConstants.au3>
#include "ExtMsgBox.au3"
#include "GUIListViewEx.au3"
Opt("TrayMenuMode", 3)
Opt("TrayIconHide", 0)
;Opt("GUIResizeMode", 1)
Opt("TrayIconDebug", 1)
Opt("TrayAutoPause", 0)
;Opt("MouseCoordMode", 2)
Opt("GUIOnEventMode", 1)
;Opt("MustDeclareVars", 1)
Opt("GUIEventOptions", 1)
Opt("TrayOnEventMode", 1)
Opt("ExpandEnvStrings", 1)
#EndRegion ;Include + Opt
;=============================================================================
#Region ;GuiVars + FileInstall
Global $GUI, $Button_1, $hGraphic, $hGraphic2, $sString, $hFont, $aInfo, $hFormat, $hBrush, $hImage, $hImageR, $hFamily, $tLayout, $IndexDay, $RefreshItem, $wpos
Global $ExitItem, $Label, $Label1, $oIE, $oDoc, $oElement1, $oElement2, $StringMid, $Split1, $Split2, $Trim, $Number, $ID, $Pic, $String, $SetString, $CfgFldr
Global $IniRIStart, $IniRIEnd, $IniRVStart, $IniRVEnd, $Ping, $clistview, $iLV_Index, $cLV, $Pair, $Value, $1stStart = 1, $iniArray, $CheckBoxRead, $InputRead
Global $Day = 0, $WS, $StartWinCheck, $BookTicker, $SplitCoins, $SplitPairData, $WinState = 0, $Iteration = 1, $aArray_Base[1500][2]
Global Const $AC_SRC_ALPHA = 1
Global $i_x1 = 0, $i_y1 = 0, $i_x3 = 25, $i_y3 = 25
Global $aMousePos, $aMousePos2, $iMouseOver = 0
Global $InstallDir = @LocalAppDataDir & '\ipma'
Global $aProcessList = ProcessList(@ScriptName)
If $aProcessList[0][0] >= 2 Then Exit
FileInstall("Binance.ico", $InstallDir & '\Binance.ico', 1)
#EndRegion ;GuiVars + FileInstall
;=============================================================================
#Region ;GUI
TraySetIcon("Binance.ico")
$GUI = GUICreate('Binance', 800, 520, -1, -1, -1) ;, $WS_EX_TOOLWINDOW) ; $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
GUISetBkColor(0x444444)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Minimize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Restore")
GUISetIcon("Binance.ico")
;=============================================================================
Local $CheckBox = GUICtrlCreateCheckbox('Activate Check', 630, 20)
Local $InputBox = GUICtrlCreateInput('', 630, 40, 100)
;$CfgFldr = TrayCreateItem("Config Folder")
;TrayItemSetOnEvent(-1, "CfgFolder")
$ExitItem = TrayCreateItem("Close")
TrayItemSetOnEvent(-1, "Quit")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "Window")
TraySetState(1)
TraySetClick(8)
GUISetState(@SW_SHOW)
;WinSetOnTop($GUI, '', 1)
#EndRegion ;GUI
;=============================================================================
#Region ;Triggers / Listview
;=============================================================================
;$clistview = GUICtrlCreateListView("", 20, 30, 690, 450, BitOR($LVS_DEFAULT, $WS_BORDER), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
;=============================================================================
#Region ;ListView
$clistview = GUICtrlCreateListView("", 10, 10, 600, 500, -1, $LVS_EX_GRIDLINES) ; + $LVS_EX_FULLROWSELECT + $LVS_EX_INFOTIP)
;GUICtrlSetTip($clistview, 'Right Click for options', "Tip", 1)
;GUICtrlSetState($clistview, $GUI_DROPACCEPTED)
GUICtrlSetFont($clistview, 9, 600, 0, '', 5)
_GUICtrlListView_AddColumn($clistview, "Pair", 100)
_GUICtrlListView_AddColumn($clistview, "Latest", 100)
_GUICtrlListView_AddColumn($clistview, "Previous1", 100)
;_GUICtrlListView_AddColumn($clistview, "Previous2", 100)
;_GUICtrlListView_AddColumn($clistview, "Previous3", 100)
_GUICtrlListView_AddColumn($clistview, "Difference", 100)
_GUIScrollBars_Init($clistview)
_GUIScrollBars_EnableScrollBar($clistview, $SB_HORZ, $ESB_DISABLE_RIGHT)
#EndRegion ;ListView
;=============================================================================
;Global $iLV_Index = _GUIListViewEx_Init($clistview, $cLV, 1, 0xFF0000, True, 32)
;=============================================================================
#EndRegion ;Triggers / Listview
AdlibRegister("CheckPairs", 5000)
;=============================================================================
Func CheckPairs()
    $BookTicker = _INetGetSource("https://www.binance.com/api/v3/ticker/bookTicker", True)
    $BookTicker = StringTrimLeft($BookTicker, 2)
    $SplitCoins = StringSplit($BookTicker, "},{", 1)
    For $c = 1 To $SplitCoins[0]
        ;Sleep(10)
        If StringInStr($SplitCoins[$c], 'BTC","') <> 0 Then
            $SplitPairData = StringSplit($SplitCoins[$c], ",", 1)
            $Pair = StringReplace(StringTrimLeft($SplitPairData[1], 10), '"', '')
            $Value = StringReplace(StringTrimLeft($SplitPairData[2], 12), '"', '')
            ;ConsoleWrite($Pair & ' - ' & $Value & @CRLF)
            If $Value <> 0.00000000 Then
                $aArray_Base[$c][0] = $Pair
                $aArray_Base[$c][1] = $Value
            EndIf
        EndIf
    Next
    ;_ArraySort($aArray_Base, 0, 0, 0, 0, 0)
    ;_ArrayDisplay($aArray_Base)
    ;=============================================================================
    For $d = 0 To _GUICtrlListView_GetItemCount($clistview)
        _GUICtrlListView_SetItemText($clistview, $d, _GUICtrlListView_GetItemText($clistview, $d, 1), 2)
    Next
    ;=============================================================================
    For $ArrS = 1 To UBound($aArray_Base) - 1
        ;Sleep(10)
        If $1stStart = 1 Then
            If $aArray_Base[$ArrS][0] <> '' Then
                ;GUICtrlCreateListViewItem($aArray_Base[$ArrS][0] & '|' & $aArray_Base[$ArrS][1] & '|' & 'prev1' & '|' & 'prev2' & '|' & 'prev3' & '|' & 'Difference', $clistview)
                GUICtrlCreateListViewItem($aArray_Base[$ArrS][0] & '|' & $aArray_Base[$ArrS][1] & '|' & 'prev1' & '|' & 'Difference', $clistview)
            EndIf
        Else
            If $aArray_Base[$ArrS][0] <> '' Then
                _GUICtrlListView_SetItemText($clistview, $ArrS - 1, $aArray_Base[$ArrS][0], 0)
                _GUICtrlListView_SetItemText($clistview, $ArrS - 1, $aArray_Base[$ArrS][1], 1)
            EndIf
        EndIf
    Next
    ;=============================================================================
    $InputRead = GUICtrlRead($InputBox)
    $CheckBoxRead = GUICtrlRead($CheckBox, 0)
    For $d = 0 To _GUICtrlListView_GetItemCount($clistview) - 1
        $Current = _GUICtrlListView_GetItemText($clistview, $d, 1)
        $Prev1 = _GUICtrlListView_GetItemText($clistview, $d, 2)
        $Result = Round(($Current - $Prev1) / (($Current + $Prev1) / 2) * 100, 2)
        _GUICtrlListView_SetItemText($clistview, $d, $Result & '%', 3)
        If $CheckBoxRead = 1 And $InputRead <> '' Then
            If $Result >= $InputRead And $Result <> 200 Then
                $GetPair = StringTrimRight(_GUICtrlListView_GetItemText($clistview, $d, 0), 3)
                Local $sMsg = "The pair :" & $d & " - " & $GetPair & @CRLF & "Increased by " & $Result & '%'
                Local $iRetValue = _ExtMsgBox($EMB_ICONINFO, "Go to the pair page.|Ignore.", "Select", $sMsg, 20)
                If $iRetValue = 1 Then
                    ShellExecute('https://www.binance.com/en/trade/' & $GetPair & '_BTC?layout=pro')
                ElseIf $iRetValue = 2 Then
                    ;MsgBox(64 + 262144, 'Failed', '.' & @CRLF & 'Will close')
                EndIf
            EndIf
        EndIf
    Next
    ;=============================================================================
    $1stStart = 0
    Return
EndFunc   ;==>CheckPairs
;=============================================================================
Do ;Main
    Sleep(100)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
;======================================================================================
Func CfgFolder()
    TrayItemSetState($CfgFldr, $TRAY_UNCHECKED)
    ShellExecute($InstallDir)
EndFunc   ;==>CfgFolder
;=============================================================================
#Region ;Window
;======================================================================================
Func Window()
    If $WinState = 0 Then
        GUISetState(@SW_SHOW, $GUI)
        $WinState = 1
    Else
        GUISetState(@SW_HIDE, $GUI)
        $WinState = 0
    EndIf
EndFunc   ;==>Window
;=============================================================================
Func Minimize()
    WinSetState('', '', @SW_MINIMIZE)
EndFunc   ;==>Minimize
;=============================================================================
Func Restore()
    WinSetState('', '', @SW_RESTORE)
EndFunc   ;==>Restore
;=============================================================================
Func Quit()
    TrayItemSetState($ExitItem, $TRAY_UNCHECKED)
    AdlibUnRegister("CheckPairs")
    _GDIPlus_Shutdown()
    $StartWinCheck = TrayItemGetState($WS)
    If $StartWinCheck = 65 Then
        ;IniWrite($cfg, 'Options', 'StartWithWin', 1)
    ElseIf $StartWinCheck = 68 Then
        ;IniWrite($cfg, 'Options', 'StartWithWin', 0)
    EndIf
    ;FileDelete('tmp4.ini')
    ;FileDelete('tmp3.ini')
    ;FileDelete('tmp2.ini')
    ;FileDelete('tmp1.ini')
    Exit
EndFunc   ;==>Quit
#EndRegion ;Window
;=============================================================================

Or maybe suggestions on how to do this in a better way.

EDIT: Kinda made it work, but its very inefficient, maybe i should drop the ini writing and reading, it's slow.

EDIT2: This works, but it's still clunky, causes a bit of a spike on the cpu of 10% or so at each cycle.

Thanks in advance

Edited by careca
updated code
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted (edited)

Hi, that's a good idea, the problem I'm not able to go around, is that there are empty elements in the array,

so if I import the whole array as is, there will be many empty entries. 

I will look into it some more.

EDIT: this seems to do the work, thank you

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Binance.ico
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Comment=By:careca
#AutoIt3Wrapper_Res_Description=Get Binance BTC Pairs Spikes
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Icon_Add=Binance.ico
;#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;=============================================================================
#Region ;Include + Opt
#include <IE.au3>
#include <Inet.au3>
#include <File.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include <WinAPIGdi.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>
#include <TrayConstants.au3>
#include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#include <GuiScrollBars.au3>
#include <StaticConstants.au3>
#include <AutoItConstants.au3>
#include <WindowsConstants.au3>
#include "ExtMsgBox.au3"
#include "GUIListViewEx.au3"
Opt("TrayMenuMode", 3)
Opt("TrayIconHide", 0)
;Opt("GUIResizeMode", 1)
Opt("TrayIconDebug", 1)
Opt("TrayAutoPause", 0)
;Opt("MouseCoordMode", 2)
Opt("GUIOnEventMode", 1)
;Opt("MustDeclareVars", 1)
Opt("GUIEventOptions", 1)
Opt("TrayOnEventMode", 1)
Opt("ExpandEnvStrings", 1)
#EndRegion ;Include + Opt
;=============================================================================
#Region ;GuiVars + FileInstall
Global $GUI, $Button_1, $hGraphic, $hGraphic2, $sString, $hFont, $aInfo, $hFormat, $hBrush, $hImage, $hImageR, $hFamily, $tLayout, $IndexDay, $RefreshItem, $wpos
Global $ExitItem, $Label, $Label1, $oIE, $oDoc, $oElement1, $oElement2, $StringMid, $Split1, $Split2, $Trim, $Number, $ID, $Pic, $String, $SetString, $CfgFldr
Global $IniRIStart, $IniRIEnd, $IniRVStart, $IniRVEnd, $Ping, $clistview, $iLV_Index, $cLV, $Pair, $Value, $1stStart = 1, $iniArray, $CheckBoxRead, $InputRead
Global $Day = 0, $WS, $StartWinCheck, $BookTicker, $SplitCoins, $SplitPairData, $WinState = 0, $Iteration = 1, $aArray_Base[257][2], $ArrLoop = 0
Global Const $AC_SRC_ALPHA = 1
Global $i_x1 = 0, $i_y1 = 0, $i_x3 = 25, $i_y3 = 25
Global $aMousePos, $aMousePos2, $iMouseOver = 0
Global $InstallDir = @LocalAppDataDir & '\ipma'
Global $aProcessList = ProcessList(@ScriptName)
If $aProcessList[0][0] >= 2 Then Exit
FileInstall("Binance.ico", $InstallDir & '\Binance.ico', 1)
#EndRegion ;GuiVars + FileInstall
;=============================================================================
#Region ;GUI
TraySetIcon("Binance.ico")
$GUI = GUICreate('Binance', 800, 520, -1, -1, -1)
GUISetBkColor(0x444444)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Minimize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Restore")
GUISetIcon("Binance.ico")
;=============================================================================
Local $CheckBox = GUICtrlCreateCheckbox('Activate Check', 630, 20)
Local $InputBox = GUICtrlCreateInput('', 630, 40, 100)
$ExitItem = TrayCreateItem("Close")
TrayItemSetOnEvent(-1, "Quit")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "Window")
TraySetState(1)
TraySetClick(8)
GUISetState(@SW_SHOW)
#EndRegion ;GUI
;=============================================================================
#Region ;ListView
$clistview = GUICtrlCreateListView("", 10, 10, 600, 500, -1, $LVS_EX_GRIDLINES) ; + $LVS_EX_FULLROWSELECT + $LVS_EX_INFOTIP)
GUICtrlSetFont($clistview, 9, 600, 0, '', 5)
_GUICtrlListView_AddColumn($clistview, "Pair", 100)
_GUICtrlListView_AddColumn($clistview, "Latest", 100)
_GUICtrlListView_AddColumn($clistview, "Previous1", 100)
_GUICtrlListView_AddColumn($clistview, "Difference", 100)
_GUIScrollBars_Init($clistview)
_GUIScrollBars_EnableScrollBar($clistview, $SB_HORZ, $ESB_DISABLE_RIGHT)
#EndRegion ;ListView
AdlibRegister("CheckPairs", 10000)
;=============================================================================
Func CheckPairs()
    ;=============================================================================
    $BookTicker = _INetGetSource("https://www.binance.com/api/v3/ticker/bookTicker", True)
    $BookTicker = StringTrimLeft($BookTicker, 2)
    $SplitCoins = StringSplit($BookTicker, "},{", 1)
    For $c = 1 To $SplitCoins[0]
        If StringInStr($SplitCoins[$c], 'BTC","') <> 0 Then
            $SplitPairData = StringSplit($SplitCoins[$c], ",", 1)
            $Pair = StringReplace(StringTrimLeft($SplitPairData[1], 10), '"', '')
            $Value = StringReplace(StringTrimLeft($SplitPairData[2], 12), '"', '')
            If $Value <> 0.00000000 Then
                $aArray_Base[$ArrLoop][0] = $Pair
                $aArray_Base[$ArrLoop][1] = $Value
                $ArrLoop = $ArrLoop + 1
            EndIf
        EndIf
    Next
    $ArrLoop = 0
    ;=============================================================================
    _ArraySort($aArray_Base, 0, 0, 0, 0, 0)
    ;=============================================================================
    If $1stStart = 1 Then ;Only at first start
        _GUICtrlListView_AddArray($clistview, $aArray_Base)
    EndIf
    ;=============================================================================
    For $d = 0 To _GUICtrlListView_GetItemCount($clistview) ;Copy items to the second column
        _GUICtrlListView_SetItemText($clistview, $d, _GUICtrlListView_GetItemText($clistview, $d, 1), 2)
    Next
    ;=============================================================================
    For $ArrS = 1 To UBound($aArray_Base) - 1 ;Write the updated values
        _GUICtrlListView_SetItemText($clistview, $ArrS - 1, $aArray_Base[$ArrS][0], 0)
        _GUICtrlListView_SetItemText($clistview, $ArrS - 1, $aArray_Base[$ArrS][1], 1)
    Next
    ;=============================================================================
    $InputRead = GUICtrlRead($InputBox)
    $CheckBoxRead = GUICtrlRead($CheckBox, 0)
    For $d = 0 To _GUICtrlListView_GetItemCount($clistview) - 1
        $Current = _GUICtrlListView_GetItemText($clistview, $d, 1)
        $Prev1 = _GUICtrlListView_GetItemText($clistview, $d, 2)
        $Result = Round(($Current - $Prev1) / (($Current + $Prev1) / 2) * 100, 2)
        _GUICtrlListView_SetItemText($clistview, $d, $Result & '%', 3)
        If $CheckBoxRead = 1 And $InputRead <> '' Then
            If $Result >= $InputRead And $Result <> 200 Then
                _WinAPI_Beep(500, 1000)
                $GetPair = StringTrimRight(_GUICtrlListView_GetItemText($clistview, $d, 0), 3)
                Local $sMsg = "The pair :" & $d & " - " & $GetPair & @CRLF & "Increased by " & $Result & '%'
                Local $iRetValue = _ExtMsgBox($EMB_ICONINFO, "Go to the pair page.|Ignore.", "Select", $sMsg, 20)
                If $iRetValue = 1 Then
                    ShellExecute('https://www.binance.com/en/trade/' & $GetPair & '_BTC?layout=pro')
                ElseIf $iRetValue = 2 Then
                    ;MsgBox(64 + 262144, 'Failed', '.' & @CRLF & 'Will close')
                EndIf
            EndIf
        EndIf
    Next
    ;=============================================================================
    $1stStart = 0
    Return
EndFunc   ;==>CheckPairs
;=============================================================================
Do ;Main
    Sleep(100)
Until GUIGetMsg() = $GUI_EVENT_CLOSE
;=============================================================================
#Region ;Window
;======================================================================================
Func Window()
    If $WinState = 0 Then
        GUISetState(@SW_SHOW, $GUI)
        $WinState = 1
    Else
        GUISetState(@SW_HIDE, $GUI)
        $WinState = 0
    EndIf
EndFunc   ;==>Window
;=============================================================================
Func Minimize()
    WinSetState('', '', @SW_MINIMIZE)
EndFunc   ;==>Minimize
;=============================================================================
Func Restore()
    WinSetState('', '', @SW_RESTORE)
EndFunc   ;==>Restore
;=============================================================================
Func Quit()
    TrayItemSetState($ExitItem, $TRAY_UNCHECKED)
    AdlibUnRegister("CheckPairs")
    Exit
EndFunc   ;==>Quit
#EndRegion ;Window
;=============================================================================

 

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...