Scripts/Get-CoinbaseAllProductVolume.ps1


Function Get-CoinbaseAllProductVolume {

    <#
 
    .SYNOPSIS
 
    Gets 30 day and 24 hour volume for all products and market types
 
    .DESCRIPTION
 
    Gets 30 day and 24 hour volume for all products and market types
 
    .PARAMETER
 
    .EXAMPLE
 
    Get-CoinbaseAllProductVolume
 
    .NOTES
 
    .LINK
 
    #>


    [CmdletBinding ()]

    Param ()

    BEGIN {

        Function Show-Output ($Values) {

            [PSCustomObject]@{

                Name = $Values.Display_Name
                Id = $Values.Id
                BaseCurrency = $Values.Base_Currency
                QuoteCurrency = $Values.Quote_currency
                MarketTypes = $MarketType
                SpotVolume24Hour = $Values.Spot_Volume_24Hour
                SpotVolume30Day = $Values.Spot_Volume_30Day
                RFQVolume24Hour = $Values.RFQ_Volume_24Hour
                RFQVolume30Day = $Values.RFQ_Volume_30Day
                ConversionVolume24Hour = $Values.Conversion_Volume_24Hour
                ConversionVolume30Day = $Values.Conversion_Volume_30Day
                Status = $Status

            }

        }

    }

    PROCESS {

        Try {

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

            $Response = Invoke-RestMethod 'https://api.exchange.coinbase.com/products/volume-summary' -Method 'GET' -Headers $Headers

            ForEach ($Item In $Response) {

                [String]$MarketType = $Item.Market_Types
                $MarketType = $MarketType.Replace('{', '').Replace('}', '').Replace(' ', ', ').ToUpper()
                $Status = 'Ok'

                Show-Output ($Item)

            }

        }

        Catch {

            $Status = $PSItem.Exception.Message

            Show-Output ('')

        }

    }

    END {}

}