Order_placement_with_api_strategy

Zen8_ith
Hi, I am running my algorithm with api . It was a limit order. Same limit order I placed with kite plateform manually. It got placed with kite platform but not with kite api . It was irfc, placed buy order at 77.05 Price went to to 77.25 but it did not placed same same order placed with at 76.90. Same with Tatasteel I placed buy order at 125.78 but now price is 126.1 still not placed. How do i fix it please guide me.
  • sujith
    Can you share the error json and http status code or, it would be better if you can share the entire debug logs. It will make it easier to see all request params and response json. You can enable debug logs while initializing Kite Connect client library.

    PS: Make sure to remove client and app specific tokens.
  • Zen8_ith
    Okay, I did not get any error message it just passed the signal. Like it did not throw any error but it just pass the signal. I can share my code with you.
  • Zen8_ith
    Zen8_ith edited October 2023
    kite = kiteconnect.KiteConnect(api_key=api_key)
    kite.set_access_token(access_token)

    def placeOrders(trans_type, symbol, price):
    try:
    order_id = kite.place_order(tradingsymbol=symbol,
    exchange=kite.EXCHANGE_NSE,
    transaction_type=trans_type,
    quantity=1,
    variety=kite.VARIETY_REGULAR,
    price=price,
    order_type=kite.ORDER_TYPE_LIMIT,
    product=kite.PRODUCT_MIS

    )

    logging.info("Order placed. ID is: {}".format(order_id))
    except Exception as e:
    logging.info("Order placement failed: {}".format(e.message))

    def strategy:
    try:
    price = kite.ltp(['NSE:' + S1])['NSE:' + S1]['last_price']
    {Here is my strategy}
    except (requests.exceptions.RequestException, ValueError) as e:
    print(f"Error: {e}")
    pass

    except DataException as e:
    print(f"Error fetching data for symbol {symbol}: {e}")
    pass

    except ReadTimeout:
    pass
    except exceptions.NetworkException:
    pass

    def run_strategy(symbol):
    strategy(symbol)


    if __name__ == "__main__":
    num_processes = multiprocessing.cpu_count() # Number of CPU cores
    pool = multiprocessing.Pool(processes=num_processes)

    # Use the pool to execute the strategy for each stock symbol
    pool.map(run_strategy, stock_symbols)

    # Close the pool and wait for all processes to finish
    pool.close()
    pool.join()
    I am using multiprocessing for it.
  • Zen8_ith
    I have enabled the debug mode.
  • sujith
    I don't think issue is with code. For semantic errors, it is better if we have request and response logs.
    Can you enable debug logs while initializing Kite Connect?
  • Zen8_ith
    Yes, I have enabled debug logs.
  • sujith
    Can you try placing the order with same params and share complete stack trace?
  • Zen8_ith
    My algo is running for irfc, tatasteel, iex, and ongc . As the conditions meet I will connect to you. In between should i also placed order with kite platform?
  • Zen8_ith
    currentprice,sell_price,buy_price
    76.55 76.02 76.78
    135.15 134.32 135.68
    187.55 186.61 188.49
    126.4 125.52 126.78
    76.55 76.02 76.78
  • sujith
    We just need complete info to reproduce issue at our end.
  • Zen8_ith
    I have enabled debug mode kite = kiteconnect.KiteConnect(api_key=api_key,debug = True)
    Now My Limit order was set at 126.78 and executed at 126.80 but sometimes it neither execute nor show any thing on debug lof just pass the signal.
  • rakeshr
    sometimes it neither execute nor show any thing on debug lof just pass the signal.
    You can manually add the debug logs at your end as well. Go through the python help article.
  • Zen8_ith
    Thanks you so much for your assistance.
This discussion has been closed.