forked from MultiPoolMiner/MultiPoolMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiningPoolHub-Algo.ps1
96 lines (83 loc) · 3.71 KB
/
MiningPoolHub-Algo.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
using module ..\Include.psm1
param(
[TimeSpan]$StatSpan,
[PSCustomObject]$Config #to be removed
)
$PoolName = Get-Item $MyInvocation.MyCommand.Path | Select-Object -ExpandProperty BaseName
if (-not $Config.Pools.$PoolName.User) {
Write-Log -Level Verbose "Cannot mine on pool ($PoolName) - no username specified. "
return
}
$PoolAPIUri = "http://miningpoolhub.com/index.php?page=api&action=getautoswitchingandprofitsstatistics&$(Get-Date -Format "yyyy-MM-dd_HH-mm")"
$PoolRegions = "europe", "us-east", "asia"
$RetryCount = 3
$RetryDelay = 2
while (-not ($APIResponse.return) -and $RetryCount -gt 0) {
try {
if (-not $APIResponse.return) { $APIResponse = Invoke-RestMethod $PoolAPIUri -UseBasicParsing -TimeoutSec 3 -ErrorAction Stop }
}
catch { }
if (-not $APIResponse.return) {
Start-Sleep -Seconds $RetryDelay
$RetryCount--
}
}
if (-not $APIResponse) {
Write-Log -Level Warn "Pool API ($PoolName) has failed. "
return
}
if ($APIResponse.return.count -le 1) {
Write-Log -Level Warn "Pool API ($PoolName) returned nothing. "
return
}
Write-Log -Level Verbose "Processing pool data ($PoolName). "
$APIResponse.return | ForEach-Object {
$PoolEntry = $_
$PoolHosts = [String[]]($PoolEntry.all_host_list.split(";"))
$CoinName = Get-CoinName $PoolEntry.current_mining_coin
$CurrencySymbol = [String]$PoolEntry.current_mining_coin_symbol
$Algorithm_Norm = Get-AlgorithmFromCurrencySymbol $CurrencySymbol
if (-not $Algorithm_Norm) { $Algorithm_Norm = Get-Algorithm $PoolEntry.algo }
if ($Algorithm_Norm -eq "Sia") { $Algorithm_Norm = "SiaClaymore" } #temp fix
$Divisor = 1000000000
$Stat = Set-Stat -Name "$($PoolName)_$($Algorithm_Norm)_Profit" -Value ($_.profit / $Divisor) -Duration $StatSpan -ChangeDetection $true
if ($PoolHosts.Count -gt 1) { $Regions = $PoolRegions } else { $Regions = $Config.Region } #Do not create multiple pool objects if there is only one host
$Regions | ForEach-Object {
$Region = $_
$Region_Norm = Get-Region ($Region -replace "^us-east$", "us")
[PSCustomObject]@{
Algorithm = $Algorithm_Norm
CoinName = $CoinName
CurrencySymbol = $CurrencySymbol
Price = $Stat.Live
StablePrice = $Stat.Week
MarginOfError = $Stat.Week_Fluctuation
Protocol = "stratum+tcp"
Host = [String]($PoolHosts | Sort-Object -Descending { $_ -ilike "$Region*" } | Select-Object -First 1)
Port = [Int]$PoolEntry.algo_switch_port
User = "$($Config.Pools.$PoolName.User).$($Config.Pools.$PoolName.Worker)"
Pass = "x"
Region = $Region_Norm
SSL = $false
Updated = $Stat.Updated
Fee = [Decimal](0.9 / 100)
}
[PSCustomObject]@{
Algorithm = $Algorithm_Norm
CoinName = $CoinName
CurrencySymbol = $CurrencySymbol
Price = $Stat.Live
StablePrice = $Stat.Week
MarginOfError = $Stat.Week_Fluctuation
Protocol = "stratum+ssl"
Host = [String]($PoolHosts | Sort-Object -Descending { $_ -ilike "$Region*" } | Select-Object -First 1)
Port = [Int]$PoolEntry.algo_switch_port
User = "$($Config.Pools.$PoolName.User).$($Config.Pools.$PoolName.Worker)"
Pass = "x"
Region = $Region_Norm
SSL = $true
Updated = $Stat.Updated
Fee = [Decimal](0.9 / 100)
}
}
}