Scripts/Get-CoinbaseCurrency.ps1
Function Get-CoinbaseCurrency { <# .SYNOPSIS Gets a single currency by Id. .DESCRIPTION Gets a single currency by Id. .PARAMETER Currency Currency Id .EXAMPLE Get-CoinbaseCurrency -Currency USD .EXAMPLE Get-CoinbaseCurrency -Currency USD, ETH .NOTES .LINK #> [CmdletBinding ()] Param () DynamicParam { $ParameterNameCurrency = 'Currency' $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute $ParameterAttribute.Mandatory = $True $ParameterAttribute.HelpMessage = 'Enter currency' $ParameterAttribute.Position = 0 $AttributeCollection.Add($ParameterAttribute) $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary $ArraySet = Get-Content -Path ("$env:ALLUSERSPROFILE\Coinbase\Currencies.txt" ) $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($ArraySet) $AttributeCollection.Add($ValidateSetAttribute) $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterNameCurrency, [String[]], $AttributeCollection) $RuntimeParameterDictionary.Add($ParameterNameCurrency, $RuntimeParameter) Return $RuntimeParameterDictionary } BEGIN { $Currencies = $PSBoundParameters[$ParameterNameCurrency] Function Show-Output ($Values) { [PSCustomObject]@{ Name = $Values.Name Id = $Values.Id Type = $Values.Details.Type DefaultNetwork = $Values.Default_Network MinimumSize = $Values.Min_Size MaximumPrecision = $Values.Max_Precision Status = $Status } } } PROCESS { Try { $Headers = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]' $Headers.Add('Content-Type', 'application/json') ForEach ($Coin In $Currencies) { $Response = Invoke-RestMethod "https://api.exchange.coinbase.com/currencies/$Coin" -Method 'GET' -Headers $Headers ForEach ($Item In $Response) { $Status = 'Ok' Show-Output ($Item) } Start-Sleep -Milliseconds 100 } } Catch { $Status = $PSItem.Exception.Message Show-Output ('') } } END {} } |