forked from nemosminer/NemosMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEarningsTrackerJob.ps1
154 lines (137 loc) · 8.06 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
<#
This file is part of NemosMiner
Copyright (c) 2018 MrPlus
NemosMiner is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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/>.
#>
# param(
# [Parameter(Mandatory=$false)]
# [String]$Pool = "ahashpool",
# [Parameter(Mandatory=$false)]
# [String]$Wallet = "",
# [Parameter(Mandatory=$false)]
# [String]$APIUri,
# [Parameter(Mandatory=$false)]
# [Float]$PaymentThreshold = 0.01,
# [Parameter(Mandatory=$false)]
# [Int]$Interval = 10,
# [Parameter(Mandatory=$false)]
# [String]$OutputFile = ".\Logs\"+$Pool+"balancetracking.csv",
# [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
# 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://nemosminer.x10host.com/poolapiref.json" -UseBasicParsing -Headers @{"Cache-Control" = "no-cache"} | ConvertFrom-Json
$poolapi = Invoke-WebRequest "http://nemosminer.x10host.com/poolapiref.json" -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 {
$BalanceData = Invoke-WebRequest ($APIUri + $Wallet) -UseBasicParsing -Headers @{"Cache-Control" = "no-cache"} | ConvertFrom-Json
}
catch { }
if (-not $BalanceData.$BalanceJson) {$BalanceData | Add-Member -NotePropertyName $BalanceJson -NotePropertyValue ($BalanceData.result.Stats | measure -sum $BalanceJson).sum -Force}
if (-not $BalanceData.$TotalJson) {$BalanceData | Add-Member -NotePropertyName $TotalJson -NotePropertyValue ($BalanceData.result.Stats | measure -sum $BalanceJson).sum -Force}
}
elseif ($Pool -eq "miningpoolhub") {
try {
#$BalanceData = ((((Invoke-WebRequest ($APIUri + $Wallet) -UseBasicParsing -Headers @{"Cache-Control" = "no-cache"}).content | ConvertFrom-Json).getuserallbalances).data | Where {$_.coin -eq "bitcoin"})
$BalanceData = ((((Invoke-WebRequest ($APIUri + $Wallet) -UseBasicParsing -Headers @{"Cache-Control" = "no-cache"}).content | ConvertFrom-Json).getuserallbalances).data | Where {$_.coin -eq "litecoin"})
}
catch { }#.confirmed
}
else {
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$TempBalanceData = Invoke-WebRequest ($APIUri + $Wallet) -UseBasicParsing -Headers @{"Cache-Control" = "no-cache"} | ConvertFrom-Json
}
catch {}
}
If ($TempBalanceData.$BalanceJson) {$BalanceData = $TempBalanceData}
$BalanceObjectS += [PSCustomObject]@{
Date = $CurDate
balance = [decimal]$BalanceData.$BalanceJson
unsold = [decimal]$BalanceData.unsold
total_unpaid = [decimal]$BalanceData.total_unpaid
total_paid = [decimal]$BalanceData.total_paid
total_earned = [decimal]$BalanceData.$TotalJson
currency = $BalanceData.currency
}
$BalanceObject = $BalanceObjectS[$BalanceOjectS.Count - 1]
If ((($CurDate - ($BalanceObjectS[0].Date)).TotalMinutes) -eq 0) {$CurDate = $CurDate.AddMinutes(1)}
$Growth1 = If ((($CurDate - ($BalanceObjectS[0].Date)).TotalHours) -ge 1) {$BalanceObject.total_earned - (($BalanceObjectS | ? {$_.Date -ge $CurDate.AddHours(-1)}).total_earned | measure -Minimum).Minimum} Else {(($BalanceObject.total_earned - $BalanceObjectS[0].total_earned) / ($CurDate - ($BalanceObjectS[0].Date)).TotalMinutes) * 60}
$Growth6 = If ((($CurDate - ($BalanceObjectS[0].Date)).TotalHours) -ge 6) {$BalanceObject.total_earned - (($BalanceObjectS | ? {$_.Date -ge $CurDate.AddHours(-6)}).total_earned | measure -Minimum).Minimum} Else {$Growth1 * 6}
$Growth24 = If ((($CurDate - ($BalanceObjectS[0].Date)).TotalDays) -ge 1) {$BalanceObject.total_earned - (($BalanceObjectS | ? {$_.Date -ge $CurDate.AddDays(-1)}).total_earned | measure -Minimum).Minimum} Else {$Growth1 * 24}
$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
AvgDailyGrowth = $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
}
$EarningsObject
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))
}
}