Private/New-ClobOrder.ps1
|
function New-ClobOrder { [CmdletBinding(SupportsShouldProcess)] param ( [Parameter(Mandatory = $true)] [string]$Token, [Parameter(Mandatory = $true)] [string]$Price, [Parameter(Mandatory = $true)] [string]$Size, [Parameter()] [ValidateSet('buy', 'sell')] [string]$Side = 'buy', [Parameter()] [ValidateSet('GTC', 'FOK', 'GTD', 'FAK')] [string]$OrderType = 'GTC', [Parameter()] [switch]$PostOnly, [Parameter()] [ValidateSet('table', 'json')] [string]$Output = 'table' ) process { if ($PSCmdlet.ShouldProcess("Order on $Token", "Create $Side order for $Size @ $Price")) { $client = [ClobClient]::new() $config = [PolymarketConfig]::Load() if (!$config.ContainsKey('api_key')) { throw "API credentials not found." } $client.SetCredentials($config['api_key'], $config['api_secret'], $config['api_passphrase']) $order = @{ token_id = $Token price = $Price size = $Size side = $Side order_type = $OrderType post_only = $PostOnly.IsPresent } $result = $client.PostOrder($order) [PolymarketOutput]::Format($result, $Output) } } } |