Scripts/Get-CoinbaseSingleProduct.ps1


Function Get-CoinbaseSingleProduct {

    <#
 
    .SYNOPSIS
 
    Get information on a single product.
 
    .DESCRIPTION
 
    Get information on a single product.
 
    .PARAMETER Product
 
    Product Id
 
    .EXAMPLE
 
    Get-CoinbaseSingleProduct -Product BTC-USD
 
    .EXAMPLE
 
    Get-CoinbaseSingleProduct -Product BTC-USD, ETH-USD
 
    .NOTES
 
    .LINK
 
    #>


    [CmdletBinding ()]

    Param ()

    DynamicParam {

        $ParameterNamePair = 'Product'
        $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\Pairs.txt" )
        $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($ArraySet)
        $AttributeCollection.Add($ValidateSetAttribute)
        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterNamePair, [String[]], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterNamePair, $RuntimeParameter)

        Return $RuntimeParameterDictionary

    }

    BEGIN {

        $Products = $PSBoundParameters[$ParameterNamePair]

        Function Show-Output ($Values) {

            [PSCustomObject]@{

                Name = $Values.Display_Name
                Id = $Values.Id
                BaseCurrency = $Values.Base_Currency
                QuoteCurrency = $Values.Quote_currency
                QuoteIncrement = $Values.Quote_Increment
                BaseIncrement = $Values.Base_Increment
                MinimumMarketFunds = $Values.Min_Market_Funds
                MarginEnabled = $Values.Margin_Enabled
                PostOnly = $Values.Post_Only
                LimitOnly = $Values.Limit_Only
                CancelOnly = $Values.Cancel_Only
                TradingDisabled = $Values.Trading_Disabled
                StableCoin = $Values.FX_StableCoin
                MaximumSlippagePercentage = $Values.Max_Slippage_Percentage
                AuctionMode = $Values.Auction_Mode
                HighBidLimitPercentage = $Values.High_Bid_Limit_Percentage
                Status = $Status

            }

        }

    }

    PROCESS {

        Try {

            $Headers = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]'
            $Headers.Add('Content-Type', 'application/json')

            ForEach ($Coin In $Products) {

                $Response = Invoke-RestMethod "https://api.exchange.coinbase.com/products/$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 {}

}