forked from tutulino/Megaminer
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMiner.ps1
281 lines (239 loc) · 13.2 KB
/
Miner.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
param(
[Parameter(Mandatory = $false)]
[String]$MiningMode = $null,
[Parameter(Mandatory = $false)]
[string]$PoolsName = $null,
[Parameter(Mandatory = $false)]
[string]$CoinsName = $null
)
. .\Include.ps1
#check parameters
if (($MiningMode -eq "MANUAL") -and ($PoolsName.count -gt 1)) {Write-Warning "ONLY ONE POOL CAN BE SELECTED ON MANUAL MODE"}
#--------------Load config.ini file
$Currency = Get-ConfigVariable "Currency"
$Location = Get-ConfigVariable "Location"
$FarmRigs = Get-ConfigVariable "FarmRigs"
$LocalCurrency = Get-ConfigVariable "LocalCurrency"
if (-not $LocalCurrency) {
#for old config.ini compatibility
$LocalCurrency = switch ($location) {
'EU' {"EUR"}
'US' {"USD"}
'ASIA' {"USD"}
'GB' {"GBP"}
default {"USD"}
}
}
#needed for anonymous pools load
$CoinsWallets = @{}
switch -regex -file config.ini {
"^\s*WALLET_(\w+)\s*=\s*(.*)" {
$name, $value = $matches[1..2]
$CoinsWallets[$name] = $value.Trim()
}
}
$UserName = Get-ConfigVariable "UserName"
$SelectedOption = ""
#-----------------Ask user for mode to mining AUTO/MANUAL to use, if a pool is indicated in parameters no prompt
Clear-Host
Print-HorizontalLine ""
Print-HorizontalLine "SELECT OPTION"
Print-HorizontalLine ""
$Modes = @()
$Modes += [PSCustomObject]@{"Option" = 0; "Mode" = 'Automatic'; "Explanation" = 'Automatically choose most profitable coin based on pools current statistics'}
$Modes += [PSCustomObject]@{"Option" = 1; "Mode" = 'Automatic24h'; "Explanation" = 'Automatically choose most profitable coin based on pools 24 hour statistics'}
$Modes += [PSCustomObject]@{"Option" = 2; "Mode" = 'Manual'; "Explanation" = 'Manual coin selection'}
if ($FarmRigs) {
$Modes += [PSCustomObject]@{"Option" = 3; "Mode" = 'Farm Monitoring'; "Explanation" = 'I want to see my rigs state'}
}
$Modes | Format-Table Option, Mode, Explanation
If ($MiningMode -eq "") {
$SelectedOption = Read-Host -Prompt 'SELECT ONE OPTION:'
$MiningMode = $Modes[$SelectedOption].Mode
Write-Host "SELECTED OPTION: $MiningMode"
} else { Write-Host "SELECTED BY PARAMETER OPTION: $MiningMode" }
if ($MiningMode -ne "FARM MONITORING") {
#-----------------Ask user for pool/s to use, if a pool is indicated in parameters no prompt
$Pools = Get-Pools -Querymode "Info" | Where-Object ("ActiveOn" + $MiningMode + "Mode") -eq $true | Sort-Object name
$Pools | Add-Member Option "0"
$counter = 0
$Pools | ForEach-Object {
$_.Option = $counter
$counter++}
#Clear-Host
Print-HorizontalLine ""
Print-HorizontalLine "SELECT POOL/S TO MINE"
Print-HorizontalLine ""
$Pools | Format-Table Option, name, rewardtype, disclaimer
If (-not $PoolsName) {
if ($MiningMode -eq "Manual") {
$SelectedOption = Read-Host -Prompt 'SELECT ONE OPTION:'
while ($SelectedOption -like '*,*') {
$SelectedOption = Read-Host -Prompt 'SELECT ONLY ONE OPTION:'
}
} else {
$SelectedOption = Read-Host -Prompt 'SELECT OPTION/S (separated by comma). 999 for all pools:'
}
if ($SelectedOption -eq "999") {
$PoolsName = $Pools.name -join ',' -replace "\s+"
} else {
$PoolsName = ($SelectedOption -split ',' | ForEach-Object {$Pools[$_].name}) -join ',' -replace "\s+"
}
Write-Host "SELECTED OPTION: $PoolsName"
} else {
Write-Host "SELECTED BY PARAMETER: $PoolsName"
}
#-----------------Ask user for coins----------------------------------------------------
if ($MiningMode -eq "manual") {
If (-not $CoinsName) {
#Load coins from pools
$CoinsPool = Get-Pools -Querymode "Menu" -PoolsFilterList $PoolsName -location $Location | Select-Object Info, Symbol, Algorithm, Workers, PoolHashRate, Blocks_24h, Price -unique | Sort-Object info
$CoinsPool | Add-Member Option "0"
$CoinsPool | Add-Member YourHashRate ([Double]0.0)
$CoinsPool | Add-Member BTCPrice ([Double]0.0)
$CoinsPool | Add-Member Reward ([Double]0.0)
$CoinsPool | Add-Member BtcProfit ([Double]0.0)
$CoinsPool | Add-Member LocalProfit ([Double]0.0)
$CoinsPool | Add-Member LocalPrice ([Double]0.0)
'Calling Coindesk API' | Write-Host
$CDKResponse = try { Invoke-RestMethod -Uri "https://api.coindesk.com/v1/bpi/currentprice/$LocalCurrency.json" -UseBasicParsing -TimeoutSec 5 | Select-Object -ExpandProperty BPI } catch { $null; Write-Host "Not responding" }
if (($CoinsPool | Where-Object Price -gt 0).count -gt 0) {
$Counter = 0
foreach ($Coin in $CoinsPool) {
$Coin.Option = $Counter
$counter++
$Coin.YourHashRate = (Get-BestHashRateAlgo $Coin.Algorithm).HashRate
$Coin.BtcProfit = $Coin.price * $Coin.YourHashRate
$Coin.LocalProfit = $CDKResponse.$LocalCurrency.rate_float * [double]$Coin.BtcProfit
}
} else {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
'Calling CoinMarketCap API' | Write-Host
$CMCResponse = try { Invoke-RestMethod -Uri "https://api.coinmarketcap.com/v1/ticker/?limit=0" -UseBasicParsing -TimeoutSec 10 } catch { $null; Write-Host "Not responding" }
'Calling Bittrex API' | Write-Host
$BTXResponse = try { Invoke-RestMethod -Uri "https://bittrex.com/api/v1.1/public/getmarketsummaries" -UseBasicParsing -TimeoutSec 10 | Select-Object -ExpandProperty 'result' } catch { $null; Write-Host "Not responding" }
'Calling Cryptopia API' | Write-Host
$CRYResponse = try { Invoke-RestMethod -Uri "https://www.cryptopia.co.nz/api/GetMarkets/BTC" -UseBasicParsing -TimeoutSec 10 | Select-Object -ExpandProperty 'data' } catch { $null; Write-Host "Not responding" }
#Add main page coins
$WtmUrl = 'https://whattomine.com/coins.json?' +
'bk14=true&factor[bk14_hr]=10&factor[bk14_p]=0&' + #Decred
'cn=true&factor[cn_hr]=10&factor[cn_p]=0&' + #CryptoNight
'cn7=true&factor[cn7_hr]=10&factor[cn7_p]=0&' + #CryptoNightV7
'cnh=true&factor[cnh_hr]=10&factor[cnh_p]=0&' + #CryptoNightHeavy
'eq=true&factor[eq_hr]=10&factor[eq_p]=0&' + #Equihash
'eth=true&factor[eth_hr]=10&factor[eth_p]=0&' + #Ethash
'grof=true&factor[gro_hr]=10&factor[gro_p]=0&' + #Groestl
'l2z=true&factor[l2z_hr]=10&factor[l2z_p]=0&' + #Lyra2z
'lbry=true&factor[lbry_hr]=10&factor[lbry_p]=0&' + #Lbry
'lre=true&factor[lrev2_hr]=10&factor[lrev2_p]=0&' + #Lyra2v2
'n5=true&factor[n5_hr]=10&factor[n5_p]=0&' + #Nist5
'ns=true&factor[ns_hr]=10&factor[ns_p]=0&' + #NeoScrypt
'pas=true&factor[pas_hr]=10&factor[pas_p]=0&' + #Pascal
'phi=true&factor[phi_hr]=10&factor[phi_p]=0&' + #PHI
'phi2=true&factor[phi2_hr]=10&factor[phi2_p]=0&' + #PHI2
'skh=true&factor[skh_hr]=10&factor[skh_p]=0&' + #Skunk
'x11gf=true&factor[x11g_hr]=10&factor[x11g_p]=0&' + #X11gost
'x16r=true&factor[x16r_hr]=10&factor[x16r_p]=0&' + #X16r
'xn=true&factor[xn_hr]=10&factor[xn_p]=0' #Xevan
'Calling WhatToMine API' | Write-Host
$WTMResponse = try { Invoke-RestMethod -Uri $WtmUrl -UseBasicParsing -TimeoutSec 10 | Select-Object -ExpandProperty coins } catch { $null; Write-Host "Not responding" }
}
$Counter = 0
foreach ($Coin in $CoinsPool) {
$Coin.Option = $Counter
$counter++
$Coin.YourHashRate = (Get-BestHashRateAlgo $Coin.Algorithm).HashRate
if ($ManualMiningApiUse -eq $true -and ![string]::IsNullOrEmpty($Coin.Symbol)) {
$PriceCMC = [decimal]($CMCResponse | Where-Object Symbol -eq $Coin.Symbol | ForEach-Object {if ($(Get-CoinUnifiedName $_.Id) -eq $Coin.Info) {$_.price_btc} })
$PriceBTX = [decimal]($BTXResponse | Where-Object MarketName -eq ('BTC-' + $Coin.Symbol) | Select-Object -ExpandProperty Last)
$PriceCRY = [decimal]($CRYResponse | Where-Object Label -eq ($Coin.Symbol + '/BTC') | Select-Object -ExpandProperty LastPrice)
if ($PriceCMC -gt 0) {
$Coin.BTCPrice = $PriceCMC
} elseif ($PriceBTX -gt 0) {
$Coin.BTCPrice = $PriceBTX
} elseif ($PriceCRY -gt 0) {
$Coin.BTCPrice = $PriceCRY
}
Remove-Variable PriceCMC
Remove-Variable PriceBTX
Remove-Variable PriceCRY
#Data from WTM
if ($WTMResponse -ne $null) {
$WtmCoin = $WTMResponse.PSObject.Properties.Value | Where-Object tag -eq $Coin.Symbol | ForEach-Object {if ($(Get-AlgoUnifiedName $_.algorithm) -eq $Coin.Algorithm) {$_}}
if ($WtmCoin -ne $null) {
$WTMFactor = switch ($Coin.Algorithm) {
"Bitcore" { 1000000 }
"Blake2s" { 1000000 }
"CnLiteV7" { 1 }
"CnV7" { 1 }
"CnHeavy" { 1 }
"Equihash" { 1 }
"Ethash" { 1000000 }
"Keccak" { 1000000 }
"KeccakC" { 1000000 }
"Lyra2v2" {1000}
"Lyra2z" { 1000000 }
"NeoScrypt" { 1000 }
"Phi" { 1000000 }
"Phi2" { 1000000 }
"Skunk" { 1000000 }
"X16r" { 1000000 }
"X16s" { 1000000 }
"X17" { 1000 }
"Yescrypt" { 1 }
"Zero" { 1 }
default { $null }
}
if ($WTMFactor) {
$Coin.Reward = [double]([double]$WtmCoin.estimated_rewards * ([double]$Coin.YourHashRate / [double]$WTMFactor))
$Coin.BtcProfit = [double]([double]$WtmCoin.Btc_revenue * ([double]$Coin.YourHashRate / [double]$WTMFactor))
}
}
}
$Coin.LocalProfit = $CDKResponse.$LocalCurrency.rate_float * $Coin.BtcProfit
$Coin.LocalPrice = $CDKResponse.$LocalCurrency.rate_float * $Coin.BtcPrice
}
}
# Clear-Host
Print-HorizontalLine ""
Print-HorizontalLine "SELECT COIN TO MINE"
Print-HorizontalLine ""
$CoinsPool | Format-Table -Wrap (
@{Label = "Opt."; Expression = {$_.Option}; Align = 'right'} ,
@{Label = "Name"; Expression = {$_.Info}; Align = 'left'} ,
@{Label = "Symbol"; Expression = {$_.symbol}; Align = 'left'},
@{Label = "Algorithm"; Expression = {$_.algorithm}; Align = 'left'},
@{Label = "HashRate"; Expression = {(ConvertTo-Hash ($_.YourHashRate)) + "/s"}; Align = 'right'},
@{Label = "BTCPrice"; Expression = {if ($_.BTCPrice -gt 0) {[math]::Round($_.BTCPrice, 6).ToString("n6")}}; Align = 'right'},
@{Label = $LocalCurrency + "Price"; Expression = { [math]::Round($_.LocalPrice, 2)}; Align = 'right'},
@{Label = "Reward"; Expression = {if ($_.Reward -gt 0 ) {[math]::Round($_.Reward, 3)}}; Align = 'right'},
@{Label = "mBTCProfit"; Expression = {if ($_.BtcProfit -gt 0 ) {($_.BtcProfit * 1000).ToString("n5")}}; Align = 'right'},
@{Label = $LocalCurrency + "Profit"; Expression = {if ($_.LocalProfit -gt 0 ) {[math]::Round($_.LocalProfit, 2)}}; Align = 'right'}
)
$SelectedOption = Read-Host -Prompt 'SELECT ONE OPTION:'
while ($SelectedOption -like '*,*') {
$SelectedOption = Read-Host -Prompt 'SELECT ONLY ONE OPTION:'
}
$CoinsName = $CoinsPool[$SelectedOption].Info -replace '_', ',' #for dual mining
$AlgosName = $CoinsPool[$SelectedOption].Algorithm -replace '_', ',' #for dual mining
Write-Host SELECTED OPTION:: $CoinsName - $AlgosName
} else {
Write-Host SELECTED BY PARAMETER :: $CoinsName
}
}
#-----------------Launch Command
$Params = @{
MiningMode = $MiningMode
PoolsName = $PoolsName -split ','
}
if ($MiningMode -eq 'Manual') {
$Params.Algorithm = $AlgosName
if ($CoinsName) {$Params.CoinsName = $CoinsName}
}
$Params | Format-List
Pause
& .\Core.ps1 @Params
} else {
#FARM MONITORING
& .\Includes\FarmMonitor.ps1
}