Powershell method to use KiteConnect

rupaliubhe
rupaliubhe edited November 2019 in General
# Sample Powershell code for PS developers
#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
Sign In or Register to comment.