GTT Order Placing Error - Please Help

Ashish_Mittal
Ashish_Mittal edited January 2 in Python client
import requests
from kiteconnect import KiteConnect
from decimal import Decimal
import logging
import time
import csv
import requests

api_key = 'c92a0d13vybrhf3'
access_token = 'w2dUzsMRtsdCg2F9Rv28AYNNGguw5eYZV'

symbol = 'RELIANCE'
trigger_price = 2581.7
quantity = 1
order_type = 'LIMIT'
transaction_type = 'BUY'
product = 'CNC'
last_price = 2590.25

gtt_order_params = {
'type': 'SINGLE',
'condition': {
'exchange': 'NSE',
'tradingsymbol': symbol,
'trigger_values': [trigger_price],
'last_price': last_price,
},
'orders': [
{
'exchange': 'NSE',
'tradingsymbol': symbol,
'transaction_type': transaction_type,
'quantity': quantity,
'order_type': order_type,
'product': product,
'price': trigger_price
}
]
}

try:
response = requests.post(
'https://api.kite.trade/gtt/triggers',
headers={
'X-Kite-Version': '3',
'Authorization': f'token {api_key}:{access_token}'
},
json=gtt_order_params
)

print(f"Request to API: {gtt_order_params}")
print(f"Response from API: {response.json()}")

data = response.json()
if data['status'] == 'success':
trigger_id = data['data']['trigger_id']
print(f"GTT order placed successfully for {symbol}. Trigger ID: {trigger_id}")
else:
print(f"Error placing GTT order for {symbol}: {data}")
except Exception as e:
print(f"Error placing GTT order for {symbol}: {e}")

========== RESTART: ==========

Request to API: {'type': 'SINGLE', 'condition': {'exchange': 'NSE', 'tradingsymbol': 'RELIANCE', 'trigger_values': [2581.7], 'last_price': 2590.25}, 'orders': [{'exchange': 'NSE', 'tradingsymbol': 'RELIANCE', 'transaction_type': 'BUY', 'quantity': 1, 'order_type': 'LIMIT', 'product': 'CNC', 'price': 2581.7}]}
Response from API: {'status': 'error', 'message': 'Invalid order params.', 'data': None, 'error_type': 'InputException'}
Error placing GTT order for RELIANCE: {'status': 'error', 'message': 'Invalid order params.', 'data': None, 'error_type': 'InputException'}
  • sujith
    You can refer to the example here.

    PS: Please don't post app or client specific tokens on public threads. You may private message, if you have to share any of the tokens.
Sign In or Register to comment.