BittrexAPI.psm1

<#
.Synopsis
Use to cancel an open order using the Order UUID. Currently this API call returns NOTHING on a success. Even though the API call suggests a return should happen.
.DESCRIPTION
/market/cancel
Used to cancel a buy or sell order.
 
Parameters
parameter required description
uuid required uuid of buy or sell order
 
.EXAMPLE
$openOrders = Get-OpenOrder
 
$openOrders
 
Uuid :
OrderUuid : 47b8d028-19ef-4c8a-ac82-246422cec214
Exchange : BTC-EMC2
OrderType : LIMIT_SELL
Quantity : 200.00000000
QuantityRemaining : 200.00000000
Limit : 0.00004610
CommissionPaid : 0.00000000
Price : 0.00000000
PricePerUnit :
Opened : 2017-11-30T15:41:33.94
Closed :
CancelInitiated : False
ImmediateOrCancel : False
IsConditional : False
Condition : NONE
ConditionTarget :
 
Remove-OpenOrder -OrderUuid 47b8d028-19ef-4c8a-ac82-246422cec214
Cancellation of /market/cancel?uuid=47b8d028-19ef-4c8a-ac82-246422cec214 is successful.
 
.EXAMPLE
$openOrders = Get-OpenOrder
 
$openOrders
 
Uuid :
OrderUuid : 47b8d028-19ef-4c8a-ac82-246422cec214
Exchange : BTC-EMC2
OrderType : LIMIT_SELL
Quantity : 200.00000000
QuantityRemaining : 200.00000000
Limit : 0.00004610
CommissionPaid : 0.00000000
Price : 0.00000000
PricePerUnit :
Opened : 2017-11-30T15:41:33.94
Closed :
CancelInitiated : False
ImmediateOrCancel : False
IsConditional : False
Condition : NONE
ConditionTarget :
 
#be AWARE that if there are multiple orders in the $openOrders collection you will cancel them all...
$openOrders | Remove-OpenOrder
Cancellation of /market/cancel?uuid=47b8d028-19ef-4c8a-ac82-246422cec214 is successful.
 
Get-OpenOrders
{nothing returned} # expected since we did cancel the order
 
#>

function Remove-OpenOrder
{
    [CmdletBinding()]
    Param
    (
        # Specify the OrderUUID to cancel.
        [Parameter(Mandatory=$true,
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]        
        [string]       
        $OrderUuid
       
    )
    
    Begin
    {
        $continueProcessing = $true
        $cancelledOrdersCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $marketcancel = Invoke-BittrexRequest -APIURI "/market/cancel?uuid=$($OrderUuid)" -apiAuth (Get-BittrexAPIKeys)
            $cancelledOrdersCollection += $marketcancel
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $cancelledOrdersCollection
        }
    }
}
<#
.Synopsis
Save the private protected KEY/SECRET values in the registry in an encrypted format. This keeps the KEY/SECRET from being stored in plain text in the script.
#>

function Set-BittrexKeyPin
{
    [CmdletBinding()]
    Param
    (
        # Provide and use a PIN for extra Encryption/Decryption security. Will prompt once per Powershell Window for use.
        [Parameter(Mandatory=$true,
                   Position=0)]
        [string]
        $PIN
    )

    Begin
    {
        $continueProcessing = $true
        if ( $PIN.Length -gt 0 ) 
        {
            Set-Variable -Name KeyPin -Value $PIN -Scope Global
            try {
                $authInfo = Get-BittrexAPIKeys -PIN $PIN
                Write-Output "The PIN was accepted"
            } catch {
                Write-Error "Please provide the correct PIN before calling other BittrexAPI module functions."
            }
        } else {
            Write-Warning "Please provide a PIN"
        }        
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Use to get an order by order UUID.
.DESCRIPTION
/account/getorder
Used to retrieve a single order by uuid.
 
Parameters
parameter required description
uuid required the uuid of the buy or sell order
 
.EXAMPLE
Get-Order -OrderUuid 110d2b99-3fe2-4713-998d-e2670ec26422
 
.EXAMPLE
$orderHistory = Get-OrderHistory -Market BTC-LTC
 
$orderHistory | Select-Object -Property OrderUuid,Exchange,OrderType
 
OrderUuid Exchange OrderType
--------- -------- ---------
110d2b99-3fe2-4713-998d-e2670ec26422 BTC-LTC LIMIT_SELL
4147080c-479a-4ea3-a173-427783d5c8e9 BTC-LTC LIMIT_SELL
5c9e2e72-6127-4aa8-be14-c9b792e639fe BTC-LTC LIMIT_SELL
c61bf764-956e-48f8-8ede-ad121d3ea393 BTC-LTC LIMIT_SELL
 
$orders = $orderHistory | Get-Order
 
$orders | Select-Object -Property OrderUuid,CommissionPaid
 
OrderUuid CommissionPaid
--------- --------------
110d2b99-3fe2-4713-998d-e2670ec26422 0.00002295
4147080c-479a-4ea3-a173-427783d5c8e9 0.00000815
5c9e2e72-6127-4aa8-be14-c9b792e639fe 0.00000706
c61bf764-956e-48f8-8ede-ad121d3ea393 0.00001072
 
#>

function Get-Order
{
    [CmdletBinding()]
    Param
    (
        # Specify the OrderUUID to cancel.
        [Parameter(Mandatory=$true,
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        [string]        
        $OrderUuid
       
    )
    
    Begin
    {
        $continueProcessing = $true
        $orderCollection = @()               
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            Write-Verbose "Looking Up: $($OrderUuid)"
            $order = Invoke-BittrexRequest -APIURI "/account/getorder?uuid=$($orderUuid)" -apiAuth (Get-BittrexAPIKeys)
            $orderCollection += $order
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $orderCollection
        }
    }
}
<#
.Synopsis
Retrieve the latest trades that have occured for the specified market.
.DESCRIPTION
/public/getmarkethistory
Used to retrieve the latest trades that have occured for a specific market.
 
Parameters
parameter required description
market required a string literal for the market (ex: BTC-LTC)
 
.EXAMPLE
$marketHistory = Get-MarketHistory -Market BTC-EMC2
 
$marketHistory.count
200
 
.EXAMPLE
$marketHistory = $markets | Get-MarketHistory
 
$markets | Select-Object -Property MarketName
 
MarketName
----------
BTC-EMC2
BTC-EMC
 
 
$marketHistory | Select-Object -Property Market | Sort-Object -Property Market -Unique
 
Market
----------
BTC-EMC
BTC-EMC2
#>

function Get-MarketHistory
{
    [CmdletBinding()]
    Param
    (
       
    )
    DynamicParam
    {
        $ParameterName = "Market"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true        
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $ParameterAlias = New-Object System.Management.Automation.AliasAttribute -ArgumentList "MarketName"
        $AttributeCollection.Add($ParameterAlias)

        $arrSet = foreach ( $market in Get-MarketsForParameter ) { Write-Output $market.MarketName.ToString() }
        if ( $arrSet.Count -gt 0 )
        {
            $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

            $AttributeCollection.Add($ValidateSetAttribute)
        }
        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary
    
    }
    Begin
    {
        $continueProcessing = $true
        $marketHistoryCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $Market = $PSBoundParameters[$ParameterName]        
            $marketParam = "?market=$($Market)"
            $markethistory = Invoke-BittrexRequest -APIURI "/public/getmarkethistory$($marketParam)" -apiAuth (Get-BittrexAPIKeys)
            foreach ( $mh in $markethistory ) 
            {
                $mh_item = "" | Select-Object  Market,Id,TimeStamp,Quantity,Price,Total,FillType,OrderType
                $mh_item.Market = $Market
                $mh_item.Id = $mh.Id
                $mh_item.TimeStamp = $mh.TimeStamp
                $mh_item.Quantity = $mh.Quantity
                $mh_item.Price = $mh.Price
                $mh_item.Total = $mh.Total
                $mh_item.FillType = $mh.FillType
                $mh_item.OrderType = $mh.OrderType
                $marketHistoryCollection += $mh_item
            }
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $marketHistoryCollection
        }
    }
}
<#
.Synopsis
Use to calculate your max coins you can purchase with your available funds.
.DESCRIPTION
This calculation doesn't depend on the purchase currency.
.EXAMPLE
Get-MaxCoinsForPurchase -SourceCurrency BTC -Rate 0.00000025 -ShowBuyCommand
9.2967
#Buy-Limit -Rate 0.00000025 -Quantity 9.2967 -Market
 
Buy-Limit -Rate 0.00000025 -Quantity 9.2967 -Market BTC-EMC2
Invoke-BittrexRequest : Bittrex API returned an error: MIN_TRADE_REQUIREMENT_NOT_MET
At C:\Users\Chris\Documents\WindowsPowerShell\Modules\BittrexAPI\BittrexAPI.psm1:1592 char:26
+ ... orderbook = Invoke-BittrexRequest -APIURI "/market/buylimit$($marketP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-BittrexRequest
  
 
 
#>

function Get-MaxCoinsForPurchase
{
    [CmdletBinding()]
    Param
    (
     # Quantity To Purchase
        [Parameter(Mandatory=$true,
                   Position=0)]
        [ValidateSet('BTC','ETH','USDT')]
        [string]       
        $SourceCurrency
        ,
        # Rate at Which To Purchase
        [Parameter(Mandatory=$true,
                   Position=1)]        
        [double]
        $Rate
        ,
        # Show a commented Buy-Limit command
        [Parameter(Mandatory=$false,
                   Position=2)]        
        [switch]
        $ShowBuyCommand
        
    )
    
    Begin
    {
        $continueProcessing = $true
        $sourceBalance = (Get-Balances | Where-Object { $_.Currency -eq "$($SourceCurrency)" }).Available 
        $sourceAvailable = $sourceBalance - ($sourceBalance * .0025)
        $maxBuy = [Math]::Round(($sourceAvailable / $Rate),7)
        Write-Output $maxBuy
        if ( $ShowBuyCommand -eq $true ) 
        {
            $buyLine = "#Add-BuyLimit -Rate {0:n8} -Quantity $($maxBuy) -Market" -f $Rate
            Write-Output $buyLine
        }
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Used internally to populate the Dynamic Parameter named Currency
.DESCRIPTION
.EXAMPLE
#>

function Get-CurrenciesForParameter
{
    [CmdletBinding()]
    Param
    (
       
    )
    
    Begin
    {
        $continueProcessing = $true
        if ( ( $Global:LastRetrievedCacheCurrency -eq $null ) -or ((Get-Date) - $Global:LastRetrievedCacheCurrency).TotalMinutes -gt 10 )
        {
            $currencies = Invoke-BittrexRequest -APIURI "/public/getcurrencies" -apiAuth (Get-BittrexAPIKeys) -IsPublic | Select-Object -Property Currency | Sort-Object -Property Currency
            $lastRetrieved = Get-Date
            Set-Variable -Name CurrencyCache -Value $currencies -Scope Global
            Set-Variable -Name LastRetrievedCacheCurrency -Value $lastRetrieved -Scope Global
        } else {
            $currencies = $Global:CurrencyCache
        }
        Write-Output $currencies
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Return a decrypted string value from a provided registry key.
The registry key must contain an encrypted value, encrypted by the System.Security.Cryptography.ProtectedData::Protect method.
#>

function Get-EncryptedValueFromRegistry
{
    [CmdletBinding()]
    Param
    (
        # Key name to read from
        [Parameter(Mandatory=$true,
                   Position=0)]
        [string]       
        $RegistryKey
        ,                
        # Optional PIN for Salt
        [Parameter(Mandatory=$false,
                   Position=1)]
        [string]
        $PIN = ""

    )

    Begin
    {
        $continueProcessing = $true
        $readValue = (Get-ItemProperty -Path "HKCU:\Software\BittrexPSModule" -Name $RegistryKey -ErrorAction SilentlyContinue).($RegistryKey)
        $decryptedValue = Decrypt-Value -ValueToDecrypt $readValue -PIN $PIN
        Write-output $decryptedValue
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Get a list of all your historical deposits, optionally by currency.
.DESCRIPTION
/account/getdeposithistory
Used to retrieve your deposit history.
 
Parameters
parameter required description
currency optional a string literal for the currecy (ie. BTC). If omitted, will return for all currencies
 
.EXAMPLE
$depositHistory = Get-DepositHistory
 
$depositHistory.count
5
 
$depositHistory | Where-Object { $_.Currency -eq "BTC" }
 
 
Id : 41545939
Amount : 0.00264030
Currency : BTC
Confirmations : 2
LastUpdated : 2017-11-20T13:52:31.36
TxId : yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
CryptoAddress : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
.EXAMPLE
$currencies = Get-Currencies | Where-Object { $_.Currency -eq "LTC" -or $_.Currency -eq "BTC" }
 
$currencies
 
 
Currency : BTC
CurrencyLong : Bitcoin
MinConfirmation : 2
TxFee : 0.00100000
IsActive : True
CoinType : BITCOIN
BaseAddress : 1N52wHoVR79PMDishab2XmRHsbekCdGquK
Notice :
 
Currency : LTC
CurrencyLong : Litecoin
MinConfirmation : 6
TxFee : 0.01000000
IsActive : True
CoinType : BITCOIN
BaseAddress : LhyLNfBkoKshT7R8Pce6vkB9T2cP2o84hx
Notice :
 
$depositHistory = $currencies | Get-DepositHistory
 
$depositHistory.Count
5
 
#>

function Get-DepositHistory
{
    [CmdletBinding()]
    Param
    (
       
    )
    DynamicParam
    {
        $ParameterName = "Currency"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $false
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $arrSet = foreach ( $currency in Get-CurrenciesForParameter ) { Write-Output $currency.Currency.ToString() }
        if ( $arrSet.Count -gt 0 )
        {
            $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

            $AttributeCollection.Add($ValidateSetAttribute)
        }
        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary
    
    }
    Begin
    {
        $continueProcessing = $true
        $depositHistoryCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $Currency = $PSBoundParameters[$ParameterName] 
            if ( $currency.Length -gt 0 )
            {       
                $currencyParam = "?currency=$($Currency)"
            } else {
                $currencyParam = ""
            }
            $depositHistory = Invoke-BittrexRequest -APIURI "/account/getdeposithistory$($currencyParam)" -apiAuth (Get-BittrexAPIKeys)
            $depositHistoryCollection += $depositHistory
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $depositHistoryCollection
        }
    }
}
<#
.Synopsis
Return the last 24 hour summary of all active exchanges on Bittrex.
.DESCRIPTION
/public/getmarketsummaries
Used to get the last 24 hour summary of all active exchanges
 
Parameters
None
.EXAMPLE
$marketSummaries = Get-MarketSummaries
 
$marketSummaries | Where-Object { $_.MarketName -eq "BTC-EMC2" }
 
 
MarketName : BTC-EMC2
High : 0.00005099
Low : 0.00003610
Volume : 35976415.10730453
Last : 0.00003949
BaseVolume : 1499.04926758
TimeStamp : 2017-11-30T00:42:32.177
Bid : 0.00003951
Ask : 0.00003989
OpenBuyOrders : 965
OpenSellOrders : 4282
PrevDay : 0.00004904
Created : 2014-12-24T00:00:00
#>

function Get-MarketSummaries
{
    [CmdletBinding()]
    Param
    (
       
    )
    
    Begin
    {
        $continueProcessing = $true
        $marketsummary = Invoke-BittrexRequest -APIURI "/public/getmarketsummaries" -apiAuth (Get-BittrexAPIKeys)
        Write-Output $marketsummary
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Use to get your open orders, optionally for a specific market.
.DESCRIPTION
/market/getopenorders
Get all orders that you currently have opened. A specific market can be requested
 
Parameters
parameter required description
market optional a string literal for the market (ie. BTC-LTC)
 
.EXAMPLE
$openOrders = Get-OpenOrders
 
$openOrders
 
 
Uuid :
OrderUuid : 47b8d028-19ef-4c8a-ac82-246422cec214
Exchange : BTC-EMC2
OrderType : LIMIT_SELL
Quantity : 200.00000000
QuantityRemaining : 200.00000000
Limit : 0.00004610
CommissionPaid : 0.00000000
Price : 0.00000000
PricePerUnit :
Opened : 2017-11-30T15:41:33.94
Closed :
CancelInitiated : False
ImmediateOrCancel : False
IsConditional : False
Condition : NONE
ConditionTarget :
 
#>

function Get-OpenOrders
{
    [CmdletBinding()]
    Param
    (
       
    )
    DynamicParam
    {
        $ParameterName = "Market"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $false
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $ParameterAlias = New-Object System.Management.Automation.AliasAttribute -ArgumentList "MarketName"
        $AttributeCollection.Add($ParameterAlias)

        $arrSet = foreach ( $market in Get-MarketsForParameter ) { Write-Output $market.MarketName.ToString() }
        $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

        $AttributeCollection.Add($ValidateSetAttribute)

        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary

    }
    Begin
    {
        $continueProcessing = $true
        $openOrdersCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $marketParam = ""
            $Market = $PSBoundParameters[$ParameterName]   
            if ( $Market.Length -gt 0 )
            {     
                $marketParam = "?market=$($Market)"
            }
            $openorders = Invoke-BittrexRequest -APIURI "/market/getopenorders$($marketParam)" -apiAuth (Get-BittrexAPIKeys)
            $openOrdersCollection += $openorders
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $openOrdersCollection
        }
    }
}
<#
.Synopsis
Save a provided string value to a specified registry key
.DESCRIPTION
Creates a key in the HKCU:\Software\BittrexPSModule and saves the provided value encrypted using the currently logged in user's security keys
#>

function Write-EncryptedValueToRegistry
{
    [CmdletBinding()]
    Param
    (
        # Registry Key Name
        [Parameter(Mandatory=$true,
                   Position=0)]
        [string]       
        $RegistryKey
        ,
        # Registry Key Value
        [Parameter(Mandatory=$true,
                   Position=1)]
        [string]
        $RegistryValue
        ,
        # Optional PIN for Salt
        [Parameter(Mandatory=$false,
                   Position=2)]
        [string]
        $PIN
    )

    Begin
    {
        $continueProcessing = $true
        $encryptedData = Encrypt-Value -ValueToEncrypt $RegistryValue -PIN $PIN
        if ( -not ( Test-Path "HKCU:\Software\BittrexPSModule" ) ) 
        {
            New-Item "HKCU:\Software\BittrexPSModule"
        }
        if ( $PIN -ne "" )
        {
            $readPinValue = (Get-ItemProperty -Path "HKCU:\Software\BittrexPSModule" -Name "RequirePIN" -ErrorAction SilentlyContinue).RequirePIN
            if ( $readPinValue -ne $null )
            {
                Remove-ItemProperty -Path "HKCU:\Software\BittrexPSModule" -Name "RequirePIN"
                New-ItemProperty -PropertyType DWord -Path "HKCU:\Software\BittrexPSModule" -Name "RequirePIN" -Value $true
            } else {
                New-ItemProperty -PropertyType DWord -Path "HKCU:\Software\BittrexPSModule" -Name "RequirePIN" -Value $true
            }
        } else {
            $readPinValue = (Get-ItemProperty -Path "HKCU:\Software\BittrexPSModule" -Name "RequirePIN" -ErrorAction SilentlyContinue).RequirePIN
            if ( $readPinValue -ne $null )
            {     
                Remove-ItemProperty -Path "HKCU:\Software\BittrexPSModule" -Name "RequirePIN"
            }
        }

        $readValue = (Get-ItemProperty -Path "HKCU:\Software\BittrexPSModule" -Name $RegistryKey -ErrorAction SilentlyContinue).($RegistryKey)
        if ( $readValue -ne $null )
        {
            Remove-ItemProperty -Path "HKCU:\Software\BittrexPSModule" -Name $RegistryKey
            New-ItemProperty -PropertyType Binary -Path "HKCU:\Software\BittrexPSModule" -Name $RegistryKey -Value $encryptedData
        } else {
            New-ItemProperty -PropertyType Binary -Path "HKCU:\Software\BittrexPSModule" -Name $RegistryKey -Value $encryptedData
        }
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            $readValue = Get-EncryptedValueFromRegistry -RegistryKey $RegistryKey -PIN $PIN
            if ( $readValue -eq $RegistryValue ) 
            {
                Write-Output $true
            } else {
                Write-Output $false
            }
        }
    }
}
<#
.Synopsis
Get the balance for a specific currency in your account.
.DESCRIPTION
/account/getbalance
Used to retrieve the balance from your account for a specific currency.
 
Parameters
parameter required description
currency required a string literal for the currency (ex: LTC)
 
.EXAMPLE
Get-Balance -Currency 'EMC2'
 
Currency : EMC2
Balance : 14.79996962
Available : 14.79996962
Pending : 0.00000000
CryptoAddress :
 
.EXAMPLE
$currencies = Get-Currencies | Where-Object { $_.Currency -eq "EMC2" -or $_.Currency -eq "BTC" }
 
$currencies
 
 
Currency : BTC
CurrencyLong : Bitcoin
MinConfirmation : 2
TxFee : 0.00100000
IsActive : True
CoinType : BITCOIN
BaseAddress : 1N52wHoVR79PMDishab2XmRHsbekCdGquK
Notice :
 
Currency : EMC2
CurrencyLong : Einsteinium
MinConfirmation : 128
TxFee : 0.20000000
IsActive : True
CoinType : BITCOIN
BaseAddress :
Notice :
 
$currencies | Get-Balance
 
 
Currency : BTC
Balance : 0.00000233
Available : 0.00000233
Pending : 0.00000000
CryptoAddress :
 
Currency : EMC2
Balance : 14.79996962
Available : 14.79996962
Pending : 0.00000000
CryptoAddress :
 
 
#>

function Get-Balance
{
    [CmdletBinding()]
    Param
    (
       
    )
    DynamicParam
    {
        $ParameterName = "Currency"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $arrSet = foreach ( $currency in Get-CurrenciesForParameter ) { Write-Output $currency.Currency.ToString() }
        if ( $arrSet.Count -gt 0 )
        {
            $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

            $AttributeCollection.Add($ValidateSetAttribute)
        }
        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary
    
    }
    Begin
    {
        $continueProcessing = $true
        $currencyBalanceCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $Currency = $PSBoundParameters[$ParameterName]        
            $currencyParam = "?currency=$($Currency)"
            $currencyBalance = Invoke-BittrexRequest -APIURI "/account/getbalance$($currencyParam)" -apiAuth (Get-BittrexAPIKeys)
            $currencyBalanceCollection += $currencyBalance
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $currencyBalanceCollection
        }
    }
}
<#
.Synopsis
Decrypt a byte array
.DESCRIPTION
System.Security.Cryptography.ProtectedData::Unprotect expects data in a byte array.
#>

function Decrypt-Value
{
    [CmdletBinding()]
    Param
    (
        # EncryptedValueToDecrypt
        [Parameter(Mandatory=$true,
                   Position=0)]
        [byte[]]       
        $ValueToDecrypt
        ,
        # PIN for Salt
        [Parameter(Mandatory=$false,
                   Position=1)]
        [string]       
        $PIN
        
    )

    Begin
    {
        Add-Type -AssemblyName System.Security
        $continueProcessing = $true
        $pinBytes = $null
        if ( $PIN.Length -gt 0 )
        {
            $pinBytes = $PIN.ToCharArray() | % {[byte] $_}
        } else {
            $pinBytes = $null
        }
        try 
        {
            $clearText = ""
            $bytes = [System.Security.Cryptography.ProtectedData]::Unprotect($ValueToDecrypt, $pinBytes, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)
            $bytes | % { $clearText += [char]$_ }
            Write-Output $clearText
        } catch {
            Write-Output ""
        }
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
When the script needs to use the API KEY/SECRET this function reads them into variables.
$apiAuth = Get-BittrexAPIKeys
use $apiAuth.Key for the key, and $apiAuth.Secret for the secret.
#>

function Get-BittrexAPIKeys
{
    [CmdletBinding()]
    Param
    (
        # Provide and use a PIN for extra Encryption/Decryption security. Will prompt once per Powershell Window for use.
        [Parameter(Mandatory=$false,
                   Position=0)]
        [string]
        $PIN = ""
    )

    Begin
    {
        $continueProcessing = $true 
        if ( ( ($Global:KeyPin).Length -gt 0 ) -and ( $PIN -eq "" ) )
        {
            $PIN = $Global:KeyPin
        }
        $apiKey = Get-EncryptedValueFromRegistry -RegistryKey "APIKEY" -PIN $PIN
        $apiSecret = Get-EncryptedValueFromRegistry -RegistryKey "APISECRET" -PIN $PIN
        $apiAuth = "" | Select-Object Key,Secret
        $apiAuth.Key = $apiKey
        $apiAuth.Secret = $apiSecret
        #Write-Output $apiKey
        #Write-Output $apiSecret
        Write-Output $apiAuth   
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Save the private protected KEY/SECRET values in the registry in an encrypted format. This keeps the KEY/SECRET from being stored in plain text in the script.
#>

function Save-BittrexAPIKeys
{
    [CmdletBinding()]
    Param
    (
        # Provide the API KEY value
        [Parameter(Mandatory=$true,
                   Position=0)]
        [string]       
        $Key
        ,
        # Provide the API SECRET value
        [Parameter(Mandatory=$true,
                   Position=1)]
        [string]
        $Secret
        ,
        # Provide and use a PIN for extra Encryption/Decryption security. Will prompt once per Powershell Window for use.
        [Parameter(Mandatory=$false,
                   Position=2)]
        [string]
        $PIN = ""
    )

    Begin
    {
        $continueProcessing = $true
        if ( Write-EncryptedValueToRegistry -RegistryKey "APIKEY" -RegistryValue $Key -PIN $PIN)
        {
            Write-Output "Saved APIKEY Successfully"
            if ( $PIN.Length -gt 0 ) 
            {
                Set-Variable -Name KeyPin -Value $PIN -Scope Global
            }
        } else {
            Write-Error "Problem Storing APIKEY"
        }
        if ( Write-EncryptedValueToRegistry -RegistryKey "APISECRET" -RegistryValue $Secret -PIN $PIN)
        {
            Write-Output "Saved APISECRET Successfully"
            if ( $PIN.Length -gt 0 )
            {
                Set-Variable -Name KeyPin -Value $PIN -Scope Global
            }
        } else {
            Write-Error "Problem Storing APISECRET"
        }
       
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Get active currencies supported on Bittrex, optionally include inactive currencies.
.DESCRIPTION
/public/getcurrencies
Used to get all supported currencies at Bittrex along with other meta data.
 
Parameters
None
.EXAMPLE
$currencies = Get-Currencies
 
$currencies | Where-Object { $_.Currency -like "*EMC*" }
 
 
Currency : EMC2
CurrencyLong : Einsteinium
MinConfirmation : 128
TxFee : 0.20000000
IsActive : True
CoinType : BITCOIN
BaseAddress :
Notice :
 
Currency : EMC
CurrencyLong : EmerCoin
MinConfirmation : 6
TxFee : 0.02000000
IsActive : True
CoinType : BITCOIN
BaseAddress :
Notice :
 
 
#>

function Get-Currencies
{
    [CmdletBinding()]
    Param
    (
        # Inclucde Inactive Currencies
        [Parameter(Mandatory=$false,
                   Position=0)]        
        [string]       
        $IncludeInactive   
    )
    
    Begin
    {
        $continueProcessing = $true
        if ( $IncludeInactive -eq $true )
        {
            $currency = Invoke-BittrexRequest -APIURI "/public/getcurrencies" -apiAuth (Get-BittrexAPIKeys)
        } else {
            $currency = Invoke-BittrexRequest -APIURI "/public/getcurrencies" -apiAuth (Get-BittrexAPIKeys) | Where-Object { $_.IsActive -eq $true }
        }        
        Write-Output $currency
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Get and/or Create a deposit address for a specific currency.
.DESCRIPTION
/account/getdepositaddress
Used to retrieve or generate an address for a specific currency. If one does not exist, the call will fail and return ADDRESS_GENERATING until one is available.
 
Parameters
parameter required description
currency required a string literal for the currency (ie. BTC)
 
.EXAMPLE
Get-DepositAddress -Currency LTC
 
Currency Address
-------- -------
LTC
 
.EXAMPLE
$currencies = Get-Currencies | Where-Object { $_.Currency -eq "LTC" -or $_.Currency -eq "BTC" }
 
$currencies
 
 
urrency : BTC
CurrencyLong : Bitcoin
MinConfirmation : 2
TxFee : 0.00100000
IsActive : True
CoinType : BITCOIN
BaseAddress : 1N52wHoVR79PMDishab2XmRHsbekCdGquK
Notice :
 
Currency : LTC
CurrencyLong : Litecoin
MinConfirmation : 6
TxFee : 0.01000000
IsActive : True
CoinType : BITCOIN
BaseAddress : LhyLNfBkoKshT7R8Pce6vkB9T2cP2o84hx
Notice :
 
$currencies | Get-DepositAddress
 
Currency Address
-------- -------
BTC bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
LTC lllllllllllllllllllllllllllllllllllll
 
#>

function Get-DepositAddress
{
    [CmdletBinding()]
    Param
    (
       
    )
    DynamicParam
    {
        $ParameterName = "Currency"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $arrSet = foreach ( $currency in Get-CurrenciesForParameter ) { Write-Output $currency.Currency.ToString() }
        if ( $arrSet.Count -gt 0 )
        {
            $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

            $AttributeCollection.Add($ValidateSetAttribute)
        }
        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary
    
    }
    Begin
    {
        $continueProcessing = $true
        $currencyAddressCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $Currency = $PSBoundParameters[$ParameterName]        
            $currencyParam = "?currency=$($Currency)"
            $depositAddress = Invoke-BittrexRequest -APIURI "/account/getdepositaddress$($currencyParam)" -apiAuth (Get-BittrexAPIKeys)
            $currencyAddressCollection += $depositAddress
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $currencyAddressCollection
        }
    }
}
<#
.Synopsis
Get the last 24 hour summary of a specific market.
.DESCRIPTION
/public/getmarketsummary
Used to get the last 24 hour summary of all active exchanges
 
Parameters
parameter required description
market required a string literal for the market (ex: BTC-LTC)
 
.EXAMPLE
$marketSummary = Get-MarketSummary -Market BTC-EMC2
 
$marketSummary
 
 
MarketName : BTC-EMC2
High : 0.00004762
Low : 0.00003610
Volume : 34229816.58875449
Last : 0.00003983
BaseVolume : 1411.25755872
TimeStamp : 2017-11-30T00:55:08.29
Bid : 0.00003930
Ask : 0.00003931
OpenBuyOrders : 1000
OpenSellOrders : 4277
PrevDay : 0.00004679
Created : 2014-12-24T00:00:00
 
.EXAMPLE
$markets = Get-Markets | Where-Object { $_.MarketName.Contains("EMC") }
 
$markets | Get-MarketSummary
 
 
MarketName : BTC-EMC2
High : 0.00004762
Low : 0.00003610
Volume : 33922990.10398286
Last : 0.00003980
BaseVolume : 1396.48543839
TimeStamp : 2017-11-30T00:58:33.943
Bid : 0.00003980
Ask : 0.00004000
OpenBuyOrders : 1021
OpenSellOrders : 4274
PrevDay : 0.00004500
Created : 2014-12-24T00:00:00
 
MarketName : BTC-EMC
High : 0.00009750
Low : 0.00009337
Volume : 185270.63854877
Last : 0.00009345
BaseVolume : 17.38097205
TimeStamp : 2017-11-30T00:54:05.377
Bid : 0.00009345
Ask : 0.00009380
OpenBuyOrders : 147
OpenSellOrders : 1445
PrevDay : 0.00009695
Created : 2016-01-06T05:28:04.553
 
#>

function Get-MarketSummary
{
    [CmdletBinding()]
    Param
    (
       
    )
    DynamicParam
    {
        $ParameterName = "Market"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $ParameterAlias = New-Object System.Management.Automation.AliasAttribute -ArgumentList "MarketName"
        $AttributeCollection.Add($ParameterAlias)
        
        $arrSet = foreach ( $market in Get-MarketsForParameter ) { Write-Output $market.MarketName.ToString() }
        $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

        $AttributeCollection.Add($ValidateSetAttribute)

        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary

    }
    Begin
    {
        $continueProcessing = $true
        $marketSummaryCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $Market = $PSBoundParameters[$ParameterName]        
            $marketParam = "?market=$($Market)"
            $marketsummary = Invoke-BittrexRequest -APIURI "/public/getmarketsummary$($marketParam)" -apiAuth (Get-BittrexAPIKeys)
            $marketSummaryCollection += $marketsummary
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $marketSummaryCollection
        }
    }
}
<#
.Synopsis
Take a string and return an encrypted byte array
.DESCRIPTION
Using the System.Security.Cryptography.ProtectedData::Protect, return an encrypted byte array.
#>

function Encrypt-Value
{
    [CmdletBinding()]
    Param
    (
        # String to Encrypt
        [Parameter(Mandatory=$false,
                   Position=0)]
        [string]       
        $ValueToEncrypt
        ,
        # PIN for Salt
        [Parameter(Mandatory=$false,
                   Position=1)]
        [string]       
        $PIN
        
    )

    Begin
    {
        $continueProcessing = $true
        Add-Type -AssemblyName System.Security
        $pinBytes = $null
        $bytes = $ValueToEncrypt.ToCharArray() | % {[byte] $_}
        if ( $PIN.Length -gt 0 )
        {
            $pinBytes = $PIN.ToCharArray() | % {[byte] $_}
        } else {
            $pinBytes = $null
        }
        $encryptedBytes = [System.Security.Cryptography.ProtectedData]::Protect($bytes,$pinBytes,[System.Security.Cryptography.DataProtectionScope]::CurrentUser)
        Write-Output $encryptedBytes
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Use to place a buy order in a Bittrex market.
.DESCRIPTION
/market/buylimit
Used to place a buy order in a specific market. Use buylimit to place limit orders. Make sure you have the proper permissions set on your API keys for this call to work
 
Parameters
parameter required description
market required a string literal for the market (ex: BTC-LTC)
quantity required the amount to purchase
rate required the rate at which to place the order.
 
.EXAMPLE
Add-BuyLimit -Rate 0.00004000 -Quantity 223.9345106 -Market BTC-EMC2
 
uuid
----
a0d0579e-529b-4a59-a278-0f8d8c88f795
 
 
.EXAMPLE
Add-BuyLimit -Rate 0.00000025 -Quantity 9.2967 -Market BTC-EMC2
Invoke-BittrexRequest : Bittrex API returned an error: MIN_TRADE_REQUIREMENT_NOT_MET
  
#>

function Add-BuyLimit
{
    [CmdletBinding()]
    Param
    (
        # Quantity To Purchase
        [Parameter(Mandatory=$true,
                   Position=1)]        
        [string]       
        $Quantity
        ,
        # Rate at Which To Purchase
        [Parameter(Mandatory=$true,
                   Position=2)]        
        [string]       
        $Rate
        ,
        # Use to just output the URL and Query string, without interacting with the exchange.
        [Parameter(Mandatory=$false,
                   Position=3)]        
        [switch]       
        $Test
    )
    DynamicParam
    {
        $ParameterName = "Market"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        $ParameterPosition = 0

        $AttributeCollection.Add($ParameterAttribute)

        $arrSet = foreach ( $market in Get-MarketsForParameter ) { Write-Output $market.MarketName.ToString() }
        $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

        $AttributeCollection.Add($ValidateSetAttribute)

        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary

    }
    Begin
    {
        $continueProcessing = $true
        $Market = $PSBoundParameters[$ParameterName]
        $marketParam = "?market=$($Market)"
        $quantityParam = "&quantity=$($Quantity)"
        $rateParam = "&rate=$($Rate)"

        if ( $Test -eq $true )
        {
            $orderbook = Invoke-BittrexRequest -APIURI "/market/buylimit$($marketParam)$($quantityParam)$($rateParam)" -apiAuth (Get-BittrexAPIKeys) -Test
        } else {
            $orderbook = Invoke-BittrexRequest -APIURI "/market/buylimit$($marketParam)$($quantityParam)$($rateParam)" -apiAuth (Get-BittrexAPIKeys)
        }
        Write-Output $orderbook
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Get the orderbook for a specified market.
.DESCRIPTION
/public/getorderbook
Used to get retrieve the orderbook for a given market
 
Parameters
parameter required description
market required a string literal for the market (ex: BTC-LTC)
type required buy, sell or both to identify the type of orderbook to return.
 
.EXAMPLE
$orderBook = Get-OrderBook -Market BTC-EMC2 -OrderType BOTH
 
($orderBook | Where-Object { $_.OrderType -eq "BUY" }).Count
587
 
($orderBook | Where-Object { $_.OrderType -eq "SELL" }).Count
1913
 
.EXAMPLE
$markets = Get-Markets | Where-Object { $_.MarketName.Contains("EMC") }
 
$orderBook = $markets | Get-OrderBook -OrderType BOTH
 
$orderBook | Select-Object -Property Market,OrderType | Sort-Object -Property Market,OrderType -Unique
 
Market OrderType
------ ---------
BTC-EMC BUY
BTC-EMC SELL
BTC-EMC2 BUY
BTC-EMC2 SELL
 
.EXAMPLE
$orderBook = $markets | Get-OrderBook -OrderType BUY
 
$orderBook | Select-Object -Property Market,OrderType | Sort-Object -Property Market,OrderType -Unique
 
Market OrderType
------ ---------
BTC-EMC BUY
BTC-EMC2 BUY
#>

function Get-OrderBook
{
    [CmdletBinding()]
    Param
    (
        # Limit the Order Type by specifying the type
        [Parameter(Mandatory=$true,
                   Position=1)]        
        [ValidateSet('BUY','SELL','BOTH')]
        [string]       
        $OrderType = "BOTH"
    )
    DynamicParam
    {
        $ParameterName = "Market"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $ParameterAlias = New-Object System.Management.Automation.AliasAttribute -ArgumentList "MarketName"
        $AttributeCollection.Add($ParameterAlias)

        $arrSet = foreach ( $market in Get-MarketsForParameter ) { Write-Output $market.MarketName.ToString() }
        $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

        $AttributeCollection.Add($ValidateSetAttribute)

        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary

    }
    Begin
    {
        $continueProcessing = $true
        $orderBookCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $Market = $PSBoundParameters[$ParameterName]
            $marketParam = "?market=$($Market)"
            $typeParam = "&type=$($OrderType.ToLower())"
            $orderbook = Invoke-BittrexRequest -APIURI "/public/getorderbook$($marketParam)$($typeParam)" -apiAuth (Get-BittrexAPIKeys)
            if ( $OrderType -eq "BOTH" )
            {
                $orderCollection = @()
                foreach ( $s in $orderbook.sell ) 
                {
                    $s_item = "" | Select-Object Market,OrderType,Quantity,Rate
                    $s_item.Market = $Market
                    $s_item.OrderType = "SELL"
                    $s_item.Quantity = $s.Quantity
                    $s_item.Rate = $s.Rate
                    $orderCollection += $s_item
                }                
                foreach ( $b in $orderbook.buy ) 
                {
                    $b_item = "" | Select-Object Market,OrderType,Quantity,Rate
                    $b_item.Market = $Market
                    $b_item.OrderType = "BUY"
                    $b_item.Quantity = $b.Quantity
                    $b_item.Rate = $b.Rate
                    $orderCollection += $b_item
                }
                $orderBookCollection += $orderCollection
            } else {
                $orderCollection = @()
                foreach ( $o in $orderbook ) 
                {
                    $o_item = "" | Select-Object Market,OrderType,Quantity,Rate
                    $o_item.Market = $Market
                    $o_item.OrderType = $OrderType
                    $o_item.Quantity = $o.Quantity
                    $o_item.Rate = $o.Rate
                    $orderCollection += $o_item
                }
                $orderBookCollection += $orderCollection
            }
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $orderBookCollection
        }
    }
}
<#
.Synopsis
Get your order history, optionally for a specific market.
.DESCRIPTION
/account/getorderhistory
Used to retrieve your order history.
 
Parameters
parameter required description
market optional a string literal for the market (ie. BTC-LTC). If ommited, will return for all markets
 
.EXAMPLE
$orderHistory = Get-OrderHistory
 
$orderHistory.Count
45
 
.EXAMPLE
$markets = Get-Markets | Where-Object { $_.MarketName -eq "BTC-LTC" -or $_.MarketName -eq "BTC-EMC2" }
 
$markets
 
 
MarketCurrency : LTC
BaseCurrency : BTC
MarketCurrencyLong : Litecoin
BaseCurrencyLong : Bitcoin
MinTradeSize : 0.02784181
MarketName : BTC-LTC
IsActive : True
Created : 2014-02-13T00:00:00
Notice :
IsSponsored :
LogoUrl : https://bittrexblobstorage.blob.core.windows.net/public/6defbc41-582d-47a6-bb2e-d0fa88663524.png
 
MarketCurrency : EMC2
BaseCurrency : BTC
MarketCurrencyLong : Einsteinium
BaseCurrencyLong : Bitcoin
MinTradeSize : 16.44736842
MarketName : BTC-EMC2
IsActive : True
Created : 2014-12-24T00:00:00
Notice :
IsSponsored :
LogoUrl : https://bittrexblobstorage.blob.core.windows.net/public/aa92fc78-8100-4adb-bbb9-05fb1b7bd166.png
 
$orderHistory = $markets | Get-OrderHistory
 
$orderHistory.Count
12
 
.EXAMPLE
Get-OrderHistory | Select-Object -First 1
 
 
OrderUuid : f49c2e39-e3a7-4381-a17c-9a6de9d83321
Exchange : BTC-EMC2
TimeStamp : 2017-11-30T16:49:16.56
OrderType : LIMIT_SELL
Limit : 0.00004500
Quantity : 200.00000000
QuantityRemaining : 0.00000000
Commission : 0.00002250
Price : 0.00900000
PricePerUnit : 0.00004500000000000000
IsConditional : False
Condition : NONE
ConditionTarget :
ImmediateOrCancel : False
Closed : 2017-11-30T16:49:33.887
 
 
#>

function Get-OrderHistory
{
    [CmdletBinding()]
    Param
    (
       
    )
    DynamicParam
    {
        $ParameterName = "Market"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $false
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $ParameterAlias = New-Object System.Management.Automation.AliasAttribute -ArgumentList "MarketName"
        $AttributeCollection.Add($ParameterAlias)

        $arrSet = foreach ( $market in Get-MarketsForParameter ) { Write-Output $market.MarketName.ToString() }
        $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

        $AttributeCollection.Add($ValidateSetAttribute)

        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary

    }
    Begin
    {
        $continueProcessing = $true
        $orderHistoryCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $Market = $PSBoundParameters[$ParameterName]  
            if ( $Market.Length -gt 0 )
            {      
                $marketParam = "?market=$($Market)"
            } else {
                $marketParam = ""
            }
            $orderHistory = Invoke-BittrexRequest -APIURI "/account/getorderhistory$($marketParam)" -apiAuth (Get-BittrexAPIKeys)
            $orderHistoryCollection += $orderHistory
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $orderHistoryCollection
        }
    }
}
<#
.Synopsis
Get the markets currently active on Bittrex. Optionally return inactive markets.
.DESCRIPTION
/public/getmarkets
Used to get the open and available trading markets at Bittrex along with other meta data.
 
Parameters
None
 
.EXAMPLE
$markets = Get-Markets
$markets | Where-Object { $_.MarketName.StartsWith("BTC") } | Select-Object -Property MarketName
MarketName
----------
BTC-LTC
BTC-DOGE
BTC-VTC
BTC-PPC
BTC-FTC
BTC-RDD
BTC-NXT
BTC-DASH
BTC-POT
BTC-BLK
BTC-EMC2
BTC-XMY
BTC-AUR
BTC-EFL
...
 
.EXAMPLE
$markets = Get-Markets | Where-Object { $_.MarketName.Contains("EMC") }
 
$markets
 
 
MarketCurrency : EMC2
BaseCurrency : BTC
MarketCurrencyLong : Einsteinium
BaseCurrencyLong : Bitcoin
MinTradeSize : 16.44736842
MarketName : BTC-EMC2
IsActive : True
Created : 2014-12-24T00:00:00
Notice :
IsSponsored :
LogoUrl : https://bittrexblobstorage.blob.core.windows.net/public/aa92fc78-8100-4adb-bbb9-05fb1b7bd166.png
 
MarketCurrency : EMC
BaseCurrency : BTC
MarketCurrencyLong : EmerCoin
BaseCurrencyLong : Bitcoin
MinTradeSize : 2.65392781
MarketName : BTC-EMC
IsActive : True
Created : 2016-01-06T05:28:04.553
Notice :
IsSponsored :
LogoUrl : https://bittrexblobstorage.blob.core.windows.net/public/449483b1-9832-4273-9d4d-dd8beb5e3f36.png
 
#>

function Get-Markets
{
    [CmdletBinding()]
    Param
    (
        # Inclucde Inactive Markets
        [Parameter(Mandatory=$false,
                   Position=0)]        
        [string]       
        $IncludeInactive
    )
    
    Begin
    {
        $continueProcessing = $true
        if ( $IncludeInactive -eq $true )
        {
            $markets = Invoke-BittrexRequest -APIURI "/public/getmarkets" -apiAuth (Get-BittrexAPIKeys)
        } else {
            $markets = Invoke-BittrexRequest -APIURI "/public/getmarkets" -apiAuth (Get-BittrexAPIKeys) | Where-Object { $_.IsActive -eq $true }
        }
        Write-Output $markets
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Get the ticker for a specifc market.
.DESCRIPTION
/public/getticker
Used to get the current tick values for a market.
 
Parameters
parameter required description
market required a string literal for the market (ex: BTC-LTC)
 
.EXAMPLE
Get-Ticker -Market BTC-EMC2
 
.EXAMPLE
$markets = Get-Markets | Where-Object { $_.MarketName.Contains("EMC") }
 
$markets | Get-Ticker
 
Market Bid Ask Last
------ --- --- ----
BTC-EMC2 0.00003927 0.00003948 0.00003948
BTC-EMC 0.00009338 0.00009345 0.00009338
 
#>

function Get-Ticker
{
    [CmdletBinding()]
    Param
    (
       
    )
    DynamicParam
    {
        $ParameterName = "Market"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $ParameterAlias = New-Object System.Management.Automation.AliasAttribute -ArgumentList "MarketName"
        $AttributeCollection.Add($ParameterAlias)

        $arrSet = foreach ( $market in Get-MarketsForParameter ) { Write-Output $market.MarketName.ToString() }
        $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

        $AttributeCollection.Add($ValidateSetAttribute)

        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary

    }
    Begin
    {
        $continueProcessing = $true        
        $tickerCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $Market = $PSBoundParameters[$ParameterName]
            $marketParam = "?market=$($Market)"
            $ticker = Invoke-BittrexRequest -APIURI "/public/getticker$($marketParam)" -apiAuth (Get-BittrexAPIKeys)
            $t_item = "" | Select-Object Market,Bid,Ask,Last
            $t_item.Market = $Market
            $t_item.Bid = $ticker.Bid
            $t_item.Ask = $ticker.Ask
            $t_item.Last = $ticker.Last
            $tickerCollection += $t_item
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $tickerCollection
        }
    }
}
<#
.Synopsis
Use to place a sell order for a Bittrex market.
.DESCRIPTION
/market/selllimit
Used to place an sell order in a specific market. Use selllimit to place limit orders. Make sure you have the proper permissions set on your API keys for this call to work
 
Parameters
parameter required description
market required a string literal for the market (ex: BTC-LTC)
quantity required the amount to purchase
rate required the rate at which to place the order
 
.EXAMPLE
$sellLimit = Add-SellLimit -Market BTC-EMC2 -Quantity 200 -Rate 0.00004610
 
$sellLimit
 
uuid
----
47b8d028-19ef-4c8a-ac82-246422cec214
 
 
$openOrders = Get-OpenOrders
 
$openOrders
 
 
Uuid :
OrderUuid : 47b8d028-19ef-4c8a-ac82-246422cec214
Exchange : BTC-EMC2
OrderType : LIMIT_SELL
Quantity : 200.00000000
QuantityRemaining : 200.00000000
Limit : 0.00004610
CommissionPaid : 0.00000000
Price : 0.00000000
PricePerUnit :
Opened : 2017-11-30T15:41:33.94
Closed :
CancelInitiated : False
ImmediateOrCancel : False
IsConditional : False
Condition : NONE
ConditionTarget :
 
#>

function Add-SellLimit
{
    [CmdletBinding()]
    Param
    (
        # Quantity To Sell
        [Parameter(Mandatory=$true,
                   Position=1)]        
        [string]       
        $Quantity
        ,
        # Rate at Which To Sell
        [Parameter(Mandatory=$true,
                   Position=2)]        
        [string]       
        $Rate
        ,
        # Use to just output the URL and Query string, without interacting with the exchange.
        [Parameter(Mandatory=$false,
                   Position=3)]        
        [switch]       
        $Test
    )
    DynamicParam
    {
        $ParameterName = "Market"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        $ParameterPosition = 0

        $AttributeCollection.Add($ParameterAttribute)

        $arrSet = foreach ( $market in Get-MarketsForParameter ) { Write-Output $market.MarketName.ToString() }
        $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

        $AttributeCollection.Add($ValidateSetAttribute)

        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary

    }
    Begin
    {
        $continueProcessing = $true
        $Market = $PSBoundParameters[$ParameterName]
        $marketParam = "?market=$($Market)"
        $quantityParam = "&quantity=$($Quantity)"
        $rateParam = "&rate=$($Rate)"

        if ( $Test -eq $true )
        {
            $orderbook = Invoke-BittrexRequest -APIURI "/market/selllimit$($marketParam)$($quantityParam)$($rateParam)" -apiAuth (Get-BittrexAPIKeys) -Test
        } else {
            $orderbook = Invoke-BittrexRequest -APIURI "/market/selllimit$($marketParam)$($quantityParam)$($rateParam)" -apiAuth (Get-BittrexAPIKeys) 
        }
        Write-Output $orderbook
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Get a listing of all your historical withdrawals, optionally by currency.
.DESCRIPTION
/account/getwithdrawalhistory
Used to retrieve your withdrawal history.
 
Parameters
parameter required description
currency optional a string literal for the currecy (ie. BTC). If omitted, will return for all currencies
 
.EXAMPLE
$withdrawalHistory = Get-WithdrawalHistory
 
$withdrawalHistory
 
PaymentUuid : c5045600-7b26-4cd0-965c-1f7d164bfb5e
Currency : EMC2
Amount : 9.80000000
Address : xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Opened : 2017-11-30T14:53:18.99
Authorized : True
PendingPayment : False
TxCost : 0.20000000
TxId : yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
Canceled : False
InvalidAddress : False
 
.EXAMPLE
@('LTC','EMC2') | Get-WithdrawalHistory
 
 
PaymentUuid : c5045600-7b26-4cd0-965c-1f7d164bfb5e
Currency : EMC2
Amount : 9.80000000
Address : xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Opened : 2017-11-30T14:53:18.99
Authorized : True
PendingPayment : False
TxCost : 0.20000000
TxId : yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
Canceled : False
InvalidAddress : False
 
 
#>

function Get-WithdrawalHistory
{
    [CmdletBinding()]
    Param
    (
       
    )
    DynamicParam
    {
        $ParameterName = "Currency"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $false
        $ParameterAttribute.ValueFromPipeline = $true
        $ParameterAttribute.ValueFromPipelineByPropertyName = $true
        $AttributeCollection.Add($ParameterAttribute)

        $ParameterPosition = 0

        $arrSet = foreach ( $currency in Get-CurrenciesForParameter ) { Write-Output $currency.Currency.ToString() }
        if ( $arrSet.Count -gt 0 )
        {
            $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

            $AttributeCollection.Add($ValidateSetAttribute)
        }
        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary
    
    }
    Begin
    {
        $continueProcessing = $true
        $withdrawalHistoryCollection = @()
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {
            $Currency = $PSBoundParameters[$ParameterName] 
            if ( $currency.Length -gt 0 )
            {       
                $currencyParam = "?currency=$($Currency)"
            } else {
                $currencyParam = ""
            }
            $withdrawalHistory = Invoke-BittrexRequest -APIURI "/account/getwithdrawalhistory$($currencyParam)" -apiAuth (Get-BittrexAPIKeys)
            $withdrawalHistoryCollection += $withdrawalHistory
        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
            Write-Output $withdrawalHistoryCollection
        }
    }
}
<#
.Synopsis
Used to execute a withdrawal from one of your account balances.
.DESCRIPTION
/account/withdraw
Used to withdraw funds from your account. note: please account for txfee.
 
Parameters
parameter required description
currency required a string literal for the currency (ie. BTC)
quantity required the quantity of coins to withdraw
address required the address where to send the funds.
paymentid optional used for CryptoNotes/BitShareX/Nxt optional field (memo/paymentid)
 
.EXAMPLE
$withdrawl = Add-Withdrawal -Currency EMC2 -Quantity 10 -Address xxxxxxxxxxxxxxxxxxxxxxxxxxxx
$withdrawl
 
uuid
----
c5045600-7b26-4cd0-965c-1f7d164bfb5e
 
#>

function Add-Withdrawal
{
    [CmdletBinding()]
    Param
    (
        # Quantity To Transfer
        [Parameter(Mandatory=$true,
                   Position=1)]        
        [string]       
        $Quantity
        ,
        # Transfer Address
        [Parameter(Mandatory=$true,
                   Position=2)]        
        [string]       
        $Address
        ,
        # Payment Note/Memo
        [Parameter(Mandatory=$false,
                   Position=3)]        
        [string]       
        $PaymentID = ""
        
    )
    DynamicParam
    {
        $ParameterName = "Currency"
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]

        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        $ParameterPosition = 0

        $AttributeCollection.Add($ParameterAttribute)

        $arrSet = foreach ( $currency in Get-CurrenciesForParameter ) { Write-Output $currency.Currency.ToString() }
        if ( $arrSet.Count -gt 0 )
        {
            $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)

            $AttributeCollection.Add($ValidateSetAttribute)
        }
        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
        return $RuntimeParameterDictionary
    
    }
    Begin
    {
        $continueProcessing = $true
        $Currency = $PSBoundParameters[$ParameterName]        
        $currencyParam = "?currency=$($Currency)"
        $quantityParam = "&quantity=$($Quantity)"
        $addressParam = "&address=$($Address)"
        if ( $PaymentID.Length -gt 0 )
        {
            $paymentidParam = "&paymentID=$($PaymentID)"
        } else {
            $paymentidParam = ""
        }
        $depositAddress = Invoke-BittrexRequest -APIURI "/account/withdraw$($currencyParam)$($quantityParam)$($addressParam)$($paymentidParam)" -apiAuth (Get-BittrexAPIKeys)
        Write-Output $depositAddress
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Get all currencies for which you have balances or deposit addresses defined.
.DESCRIPTION
/account/getbalances
Used to retrieve all balances from your account
 
Parameters
None
 
.EXAMPLE
Get-Balances
 
Currency : BTC
Balance : 0.00000233
Available : 0.00000233
Pending : 0.00000000
CryptoAddress :
 
#>

function Get-Balances
{
    [CmdletBinding()]
    Param
    (
       
    )
    
    Begin
    {
        $continueProcessing = $true
        $currencyBalance = Invoke-BittrexRequest -APIURI "/account/getbalances" -apiAuth (Get-BittrexAPIKeys)
        Write-Output $currencyBalance
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
Used internally to populate the Dynamic Parameter named Market
.DESCRIPTION
.EXAMPLE
#>

function Get-MarketsForParameter
{
    [CmdletBinding()]
    Param
    (
       
    )
    
    Begin
    {
        $continueProcessing = $true
        if ( ( $Global:LastRetrievedCache -eq $null ) -or ((Get-Date) - $Global:LastRetrievedCache).TotalMinutes -gt 10 )
        {
            $markets = Invoke-BittrexRequest -APIURI "/public/getmarkets" -apiAuth (Get-BittrexAPIKeys) -IsPublic | Select-Object -Property MarketName | Sort-Object -Property MarketName
            $lastRetrieved = Get-Date
            Set-Variable -Name MarketCache -Value $markets -Scope Global
            Set-Variable -Name LastRetrievedCache -Value $lastRetrieved -Scope Global
        } else {
            $markets = $Global:MarketCache
        }
        Write-Output $markets
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
<#
.Synopsis
.DESCRIPTION
.EXAMPLE
#>

function Invoke-BittrexRequest
{
    [CmdletBinding()]
    Param
    (
        # URI for the API Call
        [Parameter(Mandatory=$true,
                   Position=0)]
        [string]       
        $APIURI
        ,
        # API Authorization Information Key/Secret
        [Parameter(Mandatory=$true,
                   Position=1)]
        $apiAuth
        ,
        # API Authorization Information Key/Secret
        [Parameter(Mandatory=$false,
                   Position=2)]
        [switch]
        $Test
        ,
        # Skip the PIN Check if it is a public call
        [Parameter(Mandatory=$false,
                   Position=3)]
        [switch]
        $IsPublic
    )

    Begin
    {
        $continueProcessing = $true
        $epoch = Get-Date("1970-01-01")
        [int]$nonce = (( Get-Date ) - $epoch).TotalSeconds

        if ( -Not ($IsPublic) ) 
        {
            $readPinValue = (Get-ItemProperty -Path "HKCU:\Software\BittrexPSModule" -Name "RequirePIN" -ErrorAction SilentlyContinue).RequirePIN
            if ( ( $readPinValue -eq $true ) -and ( $global:KeyPin -eq $null ) )
            {
                Write-Error "You have specified a PIN to protect your API KEYS for the BittrexAPI module functions."
                Write-Warning "Use the 'Set-BittrexKeyPin -PIN nnnn' to set the correct PIN"
                $continueProcessing = $false                
            }
        }
        if ( $continueProcessing -eq $true ) 
        {
            $baseURL = "https://bittrex.com/api/v1.1"
        
            if ( $APIURI.Contains("?") )
            {
                $secureURL = "$($baseURL)$($APIURI)&apikey=$($apiAuth.Key)&nonce=$($nonce)"
            } else {
                $secureURL = "$($baseURL)$($APIURI)?apikey=$($apiAuth.Key)&nonce=$($nonce)"
            }
            $utf = New-Object System.Text.UTF8Encoding
            $byteSecureURL = $utf.GetBytes($secureURL)

            $sha = New-Object System.Security.Cryptography.HMACSHA512
            $sha.Key = [Text.Encoding]::ASCII.GetBytes($apiAuth.Secret)
            $computeSha = $sha.ComputeHash($byteSecureURL)
        
            $signature = [System.BitConverter]::ToString($computeSha) -replace "-"

            $headers = @{"apisign"=$signature}

            Write-Verbose $secureURL
            if ( -not $Test )
            {
                $response = Invoke-WebRequest -Uri $secureURL -Headers $headers
                $returnObject = $response | ConvertFrom-Json
                Write-Verbose "RAW Response: $($response)"
                Write-Verbose "Return Object: $($returnObject)"        
                #if ( -not ( ($returnObject | Get-Member | Where-Object { $_.Name -eq "success" }).Count -eq 0 ) )
                #{
                #
                #}
                if ( -not ( $returnObject.PSObject.Properties['success'] ) )
                {
                    Write-Error "Bittrex API did not return JSON data, as expected."
                    $continueProcessing = $false
                }
                if ( -not ( $returnObject.success -eq $true ) )
                {
                    Write-Error "Bittrex API returned an error: $($response.message)"
                    $continueProcessing = $false
                }
                if ( $continueProcessing -eq $true )
                {
                    if ( ($secureURL.Contains("/market/cancel")) -and ( $returnObject.success -eq $true ) )
                    {
                        Write-Output "Cancellation of $($APIURI) is successful."
                    }
                    Write-Output $returnObject.Result
                } else {
                    Write-Output $null
                }
            } else {
                Write-Output $secureURL
            }
        }
    }
    Process
    {
        if ( $continueProcessing -eq $true )
        {

        } #continue processing
    }
    End
    {
        if ( $continueProcessing -eq $true ) 
        {
        
        }
    }
}
$readPinValue = (Get-ItemProperty -Path "HKCU:\Software\BittrexPSModule" -Name "RequirePIN" -ErrorAction SilentlyContinue).RequirePIN
if ( $readPinValue -eq $true ) 
{
    $PIN = Read-Host -Prompt "PIN Required"
    Set-Variable -Name KeyPin -Value $PIN -Scope Global  
    try 
    {
        $authInfo = Get-BittrexAPIKeys -PIN $PIN
        Write-Verbose "The PIN was accepted" -Verbose
    } catch {
        Write-Error "Please provide the correct PIN before calling other BittrexAPI module functions."
        Write-Warning "Use the 'Set-BittrexKeyPin -PIN nnnn' to set the correct PIN"
    }          
}