It looks like you're new here. If you want to get involved, click one of these buttons!
#User Details
$api_key ='enter your api key'
$access_token = 'enter your access token'
$credPair = "$($api_key):$($access_token)"
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
#common header for retrieving data
$common_header = @{
'X-Kite-Version' = '3'
'Authorization' = "Basic $encodedCredentials"}
# Body/order parameters to place the order
$Body = @{
'tradingsymbol'='ACC'
'exchange'='NSE'
'transaction_type'='BUY'
'order_type'='MARKET'
'quantity'='1'
'product'='MIS'
'validity'='DAY'
}
#placing order
Invoke-RestMethod -Uri "https://api.kite.trade/orders/regular" -Method Post -Headers $common_header -Body $body
#get order details
(Invoke-RestMethod -Uri "https://api.kite.trade/orders" -Headers $common_header).data | Format-Table -AutoSize
# get net position
(Invoke-RestMethod -Uri "https://api.kite.trade/portfolio/positions" -Headers $common_header).data.net | ft -auto
# generate access token using PowerShell
#---------------------------------------------------------------------------------------------------
$api_key = 'your api key'
$api_secret = 'your api secret'
Write-Host " Please navigate to following URL and copy request token:
https://kite.trade/connect/login?api_key=$api_key&v=3
"
$ready = Read-Host -Prompt 'Enter any key to continue'
$request_token = Read-Host -Prompt 'Please enter your request token'
Function Get-StringHash([String] $String,$HashName = "MD5")
{ $StringBuilder = New-Object System.Text.StringBuilder
[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{
[Void]$StringBuilder.Append($_.ToString("x2")) }
$StringBuilder.ToString() }
$sha256string = Get-StringHash "$api_key$request_token$apr_secret" "SHA256"
$basic_header = @{ 'X-Kite-Version' = '3'}
$auth = @{ 'api_key'=$api_key ; 'request_token'=$request_token ; 'checksum'=$sha256string}
try { $token = (Invoke-RestMethod "https://api.kite.trade/session/token" -Method Post -Headers $basic_header -Body $auth).data
$access_token = $token.access_token
Write-Host "Successfully logged in to Zerodha account." -ForegroundColor Green }
catch {Write-Host "Could not login to Zerodha account please re-run the script." -BackgroundColor Yellow -ForegroundColor Red}
#---------------------------------------------------------------------------------------------------