Reusable code for placing orders

ganeshv02
ganeshv02 edited July 2020 in Python client
@sujith @rakeshr -

I want to write a python function to place orders so I can set the default values like variety, exchange etc. When I want to place an order I just pass the ones that will change like trading symbol, price, quantity. I am not able to achieve that using the function mentioned below as the defaults are mentioned as string in the function definition and kite.place_order throws an error. How can I solve this problem? Is there a way to achieve this so I can reduce some code in my program.
def place_order(kite, variety='kite.VARIETY_AMO', exchange='kite.EXCHANGE_NFO', tradingsymbol=None, transaction_type='kite.TRANSACTION_TYPE_BUY', quantity=None, price=None, product='kite.PRODUCT_NRML', order_type='kite.ORDER_TYPE_LIMIT', tag='algo_trader'):
try:
order_id = kite.place_order(
variety=variety,
exchange=exchange,
tradingsymbol=tradingsymbol,
transaction_type=transaction_type,
quantity=quantity,
price=price,
product=product,
order_type=order_type,
tag=tag)
except Exception as e:
logging.error("Unable to place order: %s", e)
logging.info("Retrying....")
  • ganeshv02
    ganeshv02 edited July 2020
    I just found that we can use this short form and don't necessarily need to use the class variables. We can close this thread. Thanks.

    def place_order(kite, variety='amo', exchange='NFO', transaction_type='BUY', product='NRML', order_type='LIMIT', tradingsymbol=None, price=None, quantity=None, tag="algo_trade"):
This discussion has been closed.