Created
January 14, 2018 02:21
-
-
Save lmoxiel/262a641859f0eaa77afaeaf64c379c02 to your computer and use it in GitHub Desktop.
BitcoinFees for Azure Functions and Slack Bot Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Christopher Jackson | |
# Generate a range of Bitcoin Transaction fees based on speed | |
# 1/7/2018 | |
$satoshi = 0.00000001 | |
$size = 226 | |
$btcprice = 16750 | |
$json = $(Invoke-WebRequest -Uri https://bitcoinfees.earn.com/api/v1/fees/list -UseBasicParsing).Content | ConvertFrom-Json | |
$fees = $json.fees | |
$length = $($fees | Where maxMinutes -lt 10000).Length | |
$very_slow = $fees | Where maxMinutes -lt 10000 | Select -First 3 | Sort-Object -Property maxMinutes -Unique -Descending | |
$slow = $fees | Where maxMinutes -lt 10000 | Select -Skip $($length * 0.2) -First 3 | Sort-Object -Property maxMinutes -Unique -Descending | |
$medium = $fees | Where maxMinutes -lt 10000 | Select -Skip $($length * 0.5) -First 3 | Sort-Object -Property maxMinutes -Unique -Descending | |
$fast = $fees | Where maxMinutes -lt 10000 | Select -Skip 6 -Last 3 | Sort-Object -Property maxMinutes -Unique -Descending | |
# Speed Network Fee (BTC) Network Fee (USD) Wait time (Hours) | |
$Result = ForEach ($speed in @($very_slow, $slow, $medium, $fast)) { | |
ForEach ($s in $speed) { | |
$s | Select @{N="Network Fee (BTC)";E={"{0:N7}" -f $($s.maxFee * $size * $satoshi)}}, | |
@{N="Network Fee (USD)";E={"{0:C2}" -f $($s.maxFee * $size * $satoshi * $btcprice)}}, | |
@{N="Wait Time (Hours)";E={"{0:N1}" -f ($s.maxMinutes / 60)}} | |
} | |
} | |
$request = Get-Content $req -Raw | |
$request -match "user_name=(\w+)" | |
$user = $Matches[0] | |
$user = $user.Split("=")[1] | |
$body = "{""response_type"": ""in_channel"",""text"":""``````$($Result | Out-String)```````nGood luck @$user""}" | |
Invoke-WebRequest -Uri https://hooks.slack.com/services/<your service key> -Method POST -ContentType "application/json" -Body $body -UseBasicParsing | |
#Out-File -Encoding Ascii -FilePath $res -inputObject "$($Result | Out-String)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment