Take profit example using python please

could some one give me a simple example of placing an order with take profit only using python please.
Thanks
Sai

Hello @saisaigraph

You can take a look at Quickstart, which we have added on DhanHQ Python Library : DhanHQ-py Hands on.

Here’s an example to place order:

# Place an order for Equity Cash
dhan.place_order(security_id='1333',   #hdfcbank
    exchange_segment=dhan.NSE,
    transaction_type=dhan.BUY,
    quantity=10,
    order_type=dhan.MARKET,
    product_type=dhan.INTRA,
    price=0)

Let me know if this helps you to get started. You can also refer to a video series that we created recently around using our Python Library: DhanHQ API Trading For Beginners - YouTube

Hardik
I am looking for Take profit with limit order as simple as that.
The above arguments do not have the take profit.
Please advise.
Thanks
Sai

In this video the guy does not explain any arguments/parameters
after quantity, “even more surprising he says that other arguments can be just kept like that” and skips… very disappointed by this guys videos please come up with new videos with detailed explainations if possible. Sorry about the -ve comments but its important useful and helpful for serious people.
Thanks.

Hardik
even though there is the arg: bo_profit_value
not sure if it is take_profit.
Please confirm.
I would like to place a limit order with specific take_profit and no stop_loss.
Thanks

Hello @saisaigraph

If ‘take_profit’ means target price to exit in profit, then yes, bo_profit_value is the parameter you are looking for. On the video series, we will try to create a beginner’s guide as well, with focusing on single API calls soon.

If you just want target price and not stop loss, then I suggest you not using BO order, rather creating two separate orders - one for entering position and other limit order for target. This is because a BO (Bracket Order) requires three legs which includes stop loss too.

Could you please code example of this please.
Thanks

i am stuck so desperately waiting for this. Sorry about the pressure.
Thanks

Hello @saisaigraph

Sure. You can use one for entering position:

dhan.place_order(security_id='1333',   #hdfcbank
    exchange_segment=dhan.NSE,
    transaction_type=dhan.BUY,
    quantity=10,
    order_type=dhan.MARKET,
    product_type=dhan.INTRA,
    price=0)

And then the other one for Target as:

dhan.place_order(security_id='1333',   #hdfcbank
    exchange_segment=dhan.NSE,
    transaction_type=dhan.SELL,
    quantity=10,
    order_type=dhan.LIMIT,
    product_type=dhan.INTRA,
    price=1700)

Let me know if this helps.

1 Like

Thanks Hardik. Let me try and get back.
Thanks
Sai

A quick question Hardik, if i want to enter at prev day close at 1500 and exit at 1700 then i am hoping the only change is price = 1500 like this:

dhan.place_order(security_id='1333',   #hdfcbank
    exchange_segment=dhan.NSE,
    transaction_type=dhan.BUY,
    quantity=10,
    order_type=dhan.MARKET,
    product_type=dhan.INTRA,
    price=1500)

And then the other one for Target as:

dhan.place_order(security_id='1333',   #hdfcbank
    exchange_segment=dhan.NSE,
    transaction_type=dhan.SELL,
    quantity=10,
    order_type=dhan.LIMIT,
    product_type=dhan.INTRA,
    price=1700)

Could you please let me know.
Thanks
Sai

I am getting ready to place a few 100 orders at a time so i would like to be sure. Please help.
Thanks

Hello @saisaigraph

In case you are looking to trade for Intraday, then this code can be used as it is. Otherwise, you will need to modify Order Type here. I suggest you go through documentation as we have detailed it out there.

HI Hardik
all the target orders are failing. the buy orders are good. please advice about the target orders here is the code:

  try:
          # for entering
          response1 = dhan.place_order(
                      transaction_type=dhan.BUY, 
                      exchange_segment=dhan.NSE,
                      product_type=dhan.INTRA, 
                      order_type=dhan.LIMIT,
                      security_id=f'{security_id}',
                      quantity=1,
                      price=price                    
                      )

        if response1['status'] == 'success':
            # for exit
            response2 = dhan.place_order(
                        transaction_type=dhan.SELL, 
                        exchange_segment=dhan.NSE,
                        product_type=dhan.INTRA, 
                        order_type=dhan.LIMIT,
                        security_id=f'{security_id}',
                        quantity=1,
                        price= take_price, 
                        )

Hello @saisaigraph

Can you help me with the error code that you are getting in response to the failing orders?

Response for Rejection
EXCH:16283:The order price is not multiple of the tick size.

Hello @saisaigraph

As I can see in the screenshot shared, the price that you have entered for selling this is 1024.68, which is not in the multiple of 0.05. As you may know, all equity instruments in NSE are traded at tick size of 0.05.

Here, you can either keep it 1024.65 or 1024.70 and then try again.

1 Like

Thanks Hardik helpful

Hi Hardik
It looks like the sell orders are getting placed before the buy order for some of the symbols . Attached is the screenshot and here is the code i am using that you have shared earlier. Please let me know if you have any suggestions.

        # for entering
        response1 = dhan.place_order(
                    transaction_type=dhan.BUY, #ttype_buy_sell,
                    exchange_segment=dhan.NSE,
                    product_type=dhan.INTRA, #, #.INTRA,
                    order_type=dhan.LIMIT,
                    security_id=f'{security_id}',
                    quantity=1,
                    price=price_nse                    
                    )
        if response1['status'] == 'success':
            # for exit
            time.sleep(1)
            response2 = dhan.place_order(
                        transaction_type=dhan.SELL, #ttype_buy_sell,
                        exchange_segment=dhan.NSE,
                        product_type=dhan.INTRA, #.INTRA,
                        order_type=dhan.LIMIT,
                        security_id=f'{security_id}',
                        quantity=1,
                        price= take_price, #price*bo_profit_val_calc                    
                        )

I have also added time.sleep(1) to ensure buy happens but the same issue.
Please suggest.

No response guys…waiting since a day… not professional… sorry… very disappointing…