-
Notifications
You must be signed in to change notification settings - Fork 4
/
EarningsTrackerJob.ps1
178 lines (156 loc) · 8.83 KB
/
EarningsTrackerJob.ps1
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
<#
KudaraideeV4 is a free software developed by NemosMiner: you can distribute and / or modify it.
Under the terms of the GNU General Public License as published by
Free Software Foundation Version 3 of the license or
(According to your choice).
NemosMiner is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#>
<#
Product: KudaraideeV4
File: EarningsTrackerJob.ps1
version: 4.1
version date: 20 October 2018
#>
# param(
# [Parameter(Mandatory=$false)]
# [String]$Pool = "ahashpool",
# [Parameter(Mandatory=$false)]
# [String]$Wallet = "",
# [Parameter(Mandatory=$false)]
# [String]$APIUri,
# [Parameter(Mandatory=$false)]
# [Float]$PaymentThreshold = 0.0025,
# [Parameter(Mandatory=$false)]
# [Int]$Interval = 10,
# [Parameter(Mandatory=$false)]
# [Bool]$EnableLog = $false,
# [Parameter(Mandatory=$false)]
# [Bool]$ShowText = $true,
# [Parameter(Mandatory=$false)]
# [Bool]$ShowRawData = $true,
# [Parameter(Mandatory=$false)]
# [String]$WorkingDirectory = $true
# )
# To start the job one could use the following
# $job = Start-Job -FilePath .\EarningTrackerJob.ps1 -ArgumentList $params
# Remove progress info from job.childjobs.Progress to avoid memory leak
$ProgressPreference = "SilentlyContinue"
# Set Process Priority
(Get-Process -Id $PID).PriorityClass = "BelowNormal"
$args[0].GetEnumerator() | ForEach-Object { New-Variable -Name $_.Key -Value $_.Value }
If ($WorkingDirectory) {Set-Location $WorkingDirectory}
sleep $StartDelay
if (-not $APIUri) {
try {
$poolapi = Invoke-WebRequest "http://bit.ly/2G9QxkI" -TimeoutSec 15 -UseBasicParsing -Headers @{"Cache-Control" = "no-cache"} | ConvertFrom-Json
}
catch {$poolapi = Get-content ".\Config\poolapiref.json" | Convertfrom-json}
if ($poolapi -ne $null) {
$poolapi | ConvertTo-json | Out-File ".\Config\poolapiref.json"
If (($poolapi | ? {$_.Name -eq $pool}).EarnTrackSupport -eq "yes") {
$APIUri = ($poolapi | ? {$_.Name -eq $pool}).WalletUri
$PaymentThreshold = ($poolapi | ? {$_.Name -eq $pool}).PaymentThreshold
$BalanceJson = ($poolapi | ? {$_.Name -eq $pool}).Balance
$TotalJson = ($poolapi | ? {$_.Name -eq $pool}).Total
}
else {return}
}
}
$BalanceObjectS = @()
$TrustLevel = 0
while ($true) {
$CurDate = Get-Date
If ($Pool -eq "nicehash") {
try {
$TempBalanceData = Invoke-WebRequest ($APIUri + $Wallet) -TimeoutSec 15 -UseBasicParsing -Headers @{"Cache-Control" = "no-cache"} | ConvertFrom-Json
}
catch { }
if (-not $TempBalanceData.$BalanceJson) {$TempBalanceData | Add-Member -NotePropertyName $BalanceJson -NotePropertyValue ([decimal]($TempBalanceData.result.Stats | measure -sum $BalanceJson).sum) -Force}
if (-not $TempBalanceData.$TotalJson) {$TempBalanceData | Add-Member -NotePropertyName $TotalJson -NotePropertyValue ([decimal]($TempBalanceData.result.Stats | measure -sum $BalanceJson).sum) -Force}
}
elseif ($Pool -eq "miningpoolhub") {
try {
$TempBalanceData = ((((Invoke-WebRequest ($APIUri + $Wallet) -TimeoutSec 15 -UseBasicParsing -Headers @{"Cache-Control" = "no-cache"}).content | ConvertFrom-Json).getuserallbalances).data | Where {$_.coin -eq "bitcoin"})
}
catch { }#.confirmed
}
else {
try {
$TempBalanceData = Invoke-WebRequest ($APIUri + $Wallet) -TimeoutSec 15 -UseBasicParsing -Headers @{"Cache-Control" = "no-cache"} | ConvertFrom-Json
}
catch { }
}
If ($TempBalanceData.$BalanceJson) {$BalanceData = $TempBalanceData}
$BalanceObjectS += [PSCustomObject]@{
Date = $CurDate
balance = $BalanceData.$BalanceJson
unsold = $BalanceData.unsold
total_unpaid = $BalanceData.total_unpaid
total_paid = $BalanceData.total_paid
total_earned = $BalanceData.$TotalJson
currency = $BalanceData.currency
}
$BalanceObject = $BalanceObjectS[$BalanceOjectS.Count - 1]
If ((($CurDate - ($BalanceObjectS[0].Date)).TotalMinutes) -eq 0) {$CurDate = $CurDate.AddMinutes(1)}
If ((($CurDate - ($BalanceObjectS[0].Date)).TotalDays) -ge 1) {
$Growth1 = $BalanceObject.total_earned - (($BalanceObjectS | ? {$_.Date -ge $CurDate.AddHours(-1)}).total_earned | measure -Minimum).Minimum
$Growth6 = $BalanceObject.total_earned - (($BalanceObjectS | ? {$_.Date -ge $CurDate.AddHours(-6)}).total_earned | measure -Minimum).Minimum
$Growth24 = $BalanceObject.total_earned - (($BalanceObjectS | ? {$_.Date -ge $CurDate.AddDays(-1)}).total_earned | measure -Minimum).Minimum
}
If ((($CurDate - ($BalanceObjectS[0].Date)).TotalDays) -lt 1) {
$Growth1 = $BalanceObject.total_earned - (($BalanceObjectS | ? {$_.Date -ge $CurDate.AddHours(-1)}).total_earned | measure -Minimum).Minimum
$Growth6 = $BalanceObject.total_earned - (($BalanceObjectS | ? {$_.Date -ge $CurDate.AddHours(-6)}).total_earned | measure -Minimum).Minimum
$Growth24 = (($BalanceObject.total_earned - $BalanceObjectS[0].total_earned) / ($CurDate - ($BalanceObjectS[0].Date)).TotalHours) * 24
}
If ((($CurDate - ($BalanceObjectS[0].Date)).TotalHours) -lt 6) {
$Growth1 = $BalanceObject.total_earned - (($BalanceObjectS | ? {$_.Date -ge $CurDate.AddHours(-1)}).total_earned | measure -Minimum).Minimum
$Growth6 = (($BalanceObject.total_earned - $BalanceObjectS[0].total_earned) / ($CurDate - ($BalanceObjectS[0].Date)).TotalHours) * 6
}
If ((($CurDate - ($BalanceObjectS[0].Date)).TotalHours) -lt 1) {
$Growth1 = (($BalanceObject.total_earned - $BalanceObjectS[0].total_earned) / ($CurDate - ($BalanceObjectS[0].Date)).TotalMinutes) * 60
}
$AvgBTCHour = If ((($CurDate - ($BalanceObjectS[0].Date)).TotalHours) -ge 1) {(($BalanceObject.total_earned - $BalanceObjectS[0].total_earned) / ($CurDate - ($BalanceObjectS[0].Date)).TotalHours)} else {$Growth1}
$EarningsObject = [PSCustomObject]@{
Pool = $pool
Wallet = $Wallet
Date = $CurDate
StartTime = $BalanceObjectS[0].Date
balance = $BalanceObject.balance
unsold = $BalanceObject.unsold
total_unpaid = $BalanceObject.total_unpaid
total_paid = $BalanceObject.total_paid
total_earned = $BalanceObject.total_earned
currency = $BalanceObject.currency
GrowthSinceStart = $BalanceObject.total_earned - $BalanceObjectS[0].total_earned
Growth1 = $Growth1
Growth6 = $Growth6
Growth24 = $Growth24
AvgHourlyGrowth = $AvgBTCHour
BTCD = $AvgBTCHour * 24
EstimatedEndDayGrowth = If ((($CurDate - ($BalanceObjectS[0].Date)).TotalHours) -ge 1) {($AvgBTCHour * ((Get-Date -Hour 0 -Minute 00 -Second 00).AddDays(1).AddSeconds(-1) - $CurDate).Hours)} else {$Growth1 * ((Get-Date -Hour 0 -Minute 00 -Second 00).AddDays(1).AddSeconds(-1) - $CurDate).Hours}
EstimatedPayDate = if ($PaymentThreshold) {IF ($BalanceObject.balance -lt $PaymentThreshold) {If ($AvgBTCHour -gt 0) {$CurDate.AddHours(($PaymentThreshold - $BalanceObject.balance) / $AvgBTCHour)} Else {"Unknown"}} else {"Next Payout !"}}else {"Unknown"}
TrustLevel = if (($CurDate - ($BalanceObjectS[0].Date)).TotalMinutes -le 360) {($CurDate - ($BalanceObjectS[0].Date)).TotalMinutes / 360}else {1}
PaymentThreshold = $PaymentThreshold
TotalHours = ($CurDate - ($BalanceObjectS[0].Date)).TotalHours
}
$EarningsObject
if ($EnableLog) {$EarningsObject | Export-Csv -NoTypeInformation -Append ".\Logs\EarningTracker-$($Pool).csv"}
If ($BalanceObjectS.Count -gt 1) {$BalanceObjectS = $BalanceObjectS | ? {$_.Date -ge $CurDate.AddDays(-1).AddHours(-1)}}
# Some pools do reset "Total" after payment (zpool)
# Results in showing bad negative earnings
# Detecting if current is more than 50% less than previous and reset history if so
If ($BalanceObject.total_earned -lt ($BalanceObjectS[$BalanceObjectS.Count - 2].total_earned / 2)) {$BalanceObjectS = @(); $BalanceObjectS += $BalanceObject}
# Sleep until next update based on $Interval. Modulo $Interval.
# Sleep (60*($Interval-((get-date).minute%$Interval))) # Changed to avoid pool API load.
If (($EarningsObject.Date - $EarningsObject.StartTime).TotalMinutes -le 20) {
Sleep (60 * ($Interval / 2))
}
else {
Sleep (60 * ($Interval))
}
}