Hi, When I manually create an order on web UI, I want to attach a custom string to the order, so that I can get that custom string in my orderUpdateListener (KiteConnect.setOnOrderUpdateListener()) method.
I mean to say I want to put some tag to the order while creating the order, and I should be able to get that custom tag in my orderUpdateListener (KiteConnect.setOnOrderUpdateListener()) method implementation.
hi @vijayonkite To attach a custom string (tag) to an order in Kite Connect and retrieve it in your orderUpdateListener, you can use the tag parameter available in the Kite Connect API. This parameter allows you to add a custom string to your order, which can then be accessed in the order update callbacks.
Here's how you can do it:
Step-by-Step Guide Add a Tag While Placing an Order: When you place an order using the Kite Connect API, include the tag parameter in your order request. This tag can be any string that you want to associate with the order.
Retrieve the Tag in Order Update Listener: In your orderUpdateListener method, you can access the tag parameter from the order update data.
def on_order_update(order): print("Order Update: ", order) if 'tag' in order: print("Custom Tag: ", order['tag'])
kite.set_on_order_update(on_order_update) Example Code Here is a complete example demonstrating how to place an order with a custom tag and retrieve it in the order update listener:
# Set access token kite.set_access_token("your_access_token")
# Define the order update listener def on_order_update(order): print("Order Update: ", order) if 'tag' in order: print("Custom Tag: ", order['tag'])
# Set the order update listener kite.set_on_order_update(on_order_update)
# Place an order with a custom tag order_id = kite.place_order( variety=kite.VARIETY_REGULAR, exchange="NSE", tradingsymbol="INFY", transaction_type=kite.TRANSACTION_TYPE_BUY, quantity=1, order_type=kite.ORDER_TYPE_MARKET, product=kite.PRODUCT_CNC, tag="my_custom_tag" )
print("Order placed with ID: ", order_id) Notes Ensure that you have the necessary permissions and your API key and access token are correctly set up. The tag parameter is optional and can be used to store any custom string that helps you identify or manage your order
Here's how you can do it:
Step-by-Step Guide
Add a Tag While Placing an Order: When you place an order using the Kite Connect API, include the tag parameter in your order request. This tag can be any string that you want to associate with the order.
order_id = kite.place_order(
variety=kite.VARIETY_REGULAR,
exchange="NSE",
tradingsymbol="INFY",
transaction_type=kite.TRANSACTION_TYPE_BUY,
quantity=1,
order_type=kite.ORDER_TYPE_MARKET,
product=kite.PRODUCT_CNC,
tag="my_custom_tag"
)
Retrieve the Tag in Order Update Listener: In your orderUpdateListener method, you can access the tag parameter from the order update data.
def on_order_update(order):
print("Order Update: ", order)
if 'tag' in order:
print("Custom Tag: ", order['tag'])
kite.set_on_order_update(on_order_update)
Example Code
Here is a complete example demonstrating how to place an order with a custom tag and retrieve it in the order update listener:
from kiteconnect import KiteConnect
# Initialize KiteConnect
kite = KiteConnect(api_key="your_api_key")
# Set access token
kite.set_access_token("your_access_token")
# Define the order update listener
def on_order_update(order):
print("Order Update: ", order)
if 'tag' in order:
print("Custom Tag: ", order['tag'])
# Set the order update listener
kite.set_on_order_update(on_order_update)
# Place an order with a custom tag
order_id = kite.place_order(
variety=kite.VARIETY_REGULAR,
exchange="NSE",
tradingsymbol="INFY",
transaction_type=kite.TRANSACTION_TYPE_BUY,
quantity=1,
order_type=kite.ORDER_TYPE_MARKET,
product=kite.PRODUCT_CNC,
tag="my_custom_tag"
)
print("Order placed with ID: ", order_id)
Notes
Ensure that you have the necessary permissions and your API key and access token are correctly set up.
The tag parameter is optional and can be used to store any custom string that helps you identify or manage your order