I'm having a really hard time getting my script to run continuously. For whatever reason, it just stops after a few minutes or a few hours. I did some reading and potentially found that it might be to do with SetTimer. Any help is much appreciated I'm expecting I'll need to give some more information, just let me know what and I'll do my best to provide it ASAP.
Code: Select all
#Include C:\AutohotKey\Chrome.ahk_v1.2\Chrome.ahk
;Variables-----------------------------------------------------------------------
InputBuffer=0
Found=0
Address=0
y1=0
y2=0
y3=0
CAD=1000
InitialRate=0
Invested=0
Running=0
SamplePointer=1
AvgPointer=1
SampleRingBufferSize=10
AvgRingBufferSize=10
AvgBuffer=0
GUICounter=0
;Arrays--------------------------------------------------------------------------
PairName:=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
UsedAddresses:=[]
InputData:=[]
Rate:=[]
High:=[]
Gain:=[]
Volume:=[]
ExchangeRate:=[]
Viable:=[0,0,0,0,0,0,0,0,0,0]
Viability:=[]
Average:=[]
GrowthFactors:=[]
AverageGrowthFactor:=[]
Samples:=[]
Loop,10
{
AverageBuffer[A_Index]:=0
}
Loop,10
{
LVL1PTR:=A_Index
Loop,%RingBufferSize%
{
Average[LVL1PTR,A_Index]:=0
}
}
ChromeProfile := "C:\Users\michaelc\AppData\Local\Google\Chrome\User Data\Default"
ChromeInst := new Chrome(ChromeProfile)
FileRead,FileContents,CompoundBot.log
PageInstance := ChromeInst.GetPage()
PageInstance.Call("Page.navigate", {"url": "https www.binance.com /en/markets"}) Broken Link for safety
PageInstance.WaitForLoad()
;Gui, Add, Edit, x22 y69 w70 h20 , Edit
;Gui, Add, Edit, x22 y99 w70 h20 , Edit
;Gui, Add, Edit, x22 y129 w70 h20 , Edit
Gui, Add, Button, x22 y69 w60 h20 gRun, Run
;Gui, Add, Button, x102 y99 w120 h20 gWriteAverages, Write Averages
;Gui, Add, Button, x102 y129 w120 h20 gWriteSamples, Write Samples
Gui, Add, Text, x22 y10 w200 h15 vInvestedPairNameText,% "Invested Pair: " InvestedPairName
Gui, Add, Text, x22 y25 w200 h15 vInvestedGainText,% "Gain: " InvestedGain
Gui, Add, Text, x22 y40 w200 h15 vInvestedValueText,% "Value: " InvestedValue
Gui, Add, Edit, x250 y10 w250 h540 vLog readOnly,%FileContents%
Gui, Add, Button, x440 y555 w60 h20 gClearLog, Clear Log
Loop, 10
{
y1:=(A_Index*40)+140
y2:=(A_Index*40)+155
Gui, Add, Text, x22 y%y1% w100 h15 vPairName%A_Index%Text,% PairName%A_Index%
Gui, Add, Text, x130 y%y1% w100 h15 vHigh%A_Index%Text,% High%A_Index%
Gui, Add, Text, x130 y%y2% w100 h15 vRate%A_Index%Text,% Rate%A_Index%
Gui, Add, Text, x230 y%y1% w10 h15 vViability%A_Index%Text,% Viable[A_Index]
Gui, Add, Text, x230 y%y2% w10 h15 vAvgGrowthFactor%A_Index%Text,% AverageGrowthFactor[A_Index]
}
Gui, Show, x219 y116 h588 w520, CompoundBot
SetTimer, UpdateData, 1000
SetTimer, UpdateGUI, 3000
UpdateData:
if (Running=1)
{
Loop,10
{
UsedAddresses[A_Index]:=0
;msgbox, % UsedAddresses[A_Index]
}
Loop,10
{
InputIndex:=A_Index - 1
InputBuffer:= % PageInstance.Evaluate("document.querySelectorAll('.css-1uly3p5')['" InputIndex "'].innerText").Value
InputData:= strSplit(InputBuffer,"`n","+" "%" "/" " " "$" ",")
PairName_:=InputData[1] "/" InputData[2]
Found=0
Loop,10
{
if (PairName_=PairName[A_Index])
{
Address:=A_Index
Found=1
UsedAddresses[Address]:=1
Goto ContinueLoop
}
}
if (Found=0)
{
Loop,10
{
if (PairName[A_Index]=0)
{
Address:=A_Index
PairName[Address]:=PairName_
UsedAddresses[Address]:=1
Goto ContinueLoop
}
}
}
ContinueLoop:
Rate_:=InputData[3]
IfNotInString,Rate_, x
{
ExchangeRate_:= InputData[4]
Gain_:=InputData[5]
High_:=InputData[6]
Volume_:=StrReplace(InputData[9], ",","")
}
Else
{
Rate_:=InputData[4]
ExchangeRate_:= InputData[5]
Gain_:=InputData[6]
High_:=InputData[7]
Volume_:=StrReplace(InputData[10], ",","")
}
Rate[Address]:=Rate_
High[Address]:=High_
Gain[Address]:=Gain_
ExchangeRate[Address]:=ExchangeRate_
Volume[Address]:=Volume_
Samples[Address,SamplePointer]:= Rate_
Viability[Address]:=Rate_/High_
if (Viability[Address]>0.99)
{
Viable[Address]:=1
ViablePairFound:=1
}
}
SamplePointer++
loop,10
{
Address:=A_Index
if (UsedAddresses[Address]=0)
{
PairName[Address]:=0
}
}
if (ViablePairFound=1)
{
if (Invested=0)
{
Goto Invest
}
if (Invested=1)
{
Goto Monitor
}
}
}
Return
Invest:
HighestVolume=1000
loop,10
{
if (Viable[A_Index]=1)
{
if (Volume[A_Index]>HighestVolume)
{
HighestVolume:=Volume[A_Index]
HighestVolumeAddress:=A_Index
InitialRate:=Rate[HighestVolumeAddress]
}
}
}
InvestedPairName:=PairName[HighestVolumeAddress]
SubmissionTime:=A_Now
FormatTime, SubmissionTime, ,dd/MM/yy h:mm:ss tt
FileAppend, %InvestedPairName% bought at %SubmissionTime% / Start Value: %CAD%`n`n, CompoundBot.log
FileRead,FileContents,Compoundbot.log
GuiControl, , Log, %FileContents%
Invested:=1
return
Monitor:
InvestedGain:=Rate[HighestVolumeAddress]/InitialRate
InvestedValue:=CAD*InvestedGain
if (Viability[HighestVolumeAddress]<0.97)
{
Viable[Address]:=0
CAD:=CAD*InvestedGain
ViablePairFound=0
Invested=0
SubmissionTime:=A_Now
FormatTime, SubmissionTime, ,dd/MM/yy h:mm:ss tt
FileAppend, %InvestedPairName% sold at %SubmissionTime% / End Value: %CAD% / Final Outcome: %InvestedGain%`n`n, CompoundBot.log
FileRead,FileContents,Compoundbot.log
GuiControl, , Log, %FileContents%
InvestedPairName:=0
InvestedGain:=0
}
Return
UpdateGUI:
Loop, 10
{
GuiControl, ,InvestedPairNameText,% "Invested Pair: " InvestedPairName
GuiControl, ,InvestedGainText,% "Invested Gain: " InvestedGain
GuiControl, ,InvestedValueText,% "Invested Value: $" InvestedValue
GuiControl, ,PairName%A_Index%Text, % PairName[A_Index]
GuiControl, ,Rate%A_Index%Text, % "Rate: " Rate[A_Index]
GuiControl, ,High%A_Index%Text, % "High: " High[A_Index]
GuiControl, ,Viability%A_Index%Text, % Viable[A_Index]
GuiControl, ,AvgGrowthFactor%A_Index%Text, % AverageGrowthFactor[A_Index]
}
Return
Run:
if (Running=0)
{
Running=1
}
else
{
Running=0
}
Return
GuiClose:
ExitApp
return
ClearLog:
MsgBox, 4,, Are you sure you want to clear the log?
IfMsgBox, Yes
file := FileOpen("C:\AutoHotKey\Chrome.ahk_v1.2\CompoundBot.log", "w") ;this wipes out all text in the file and overwrites it as a blank .txt file
file.close() ;this closes the file
FileRead,FileContents,CompoundBot.log
GuiControl, , Log, %FileContents%
return
IfMsgBox, No
return