Python build query

share the arguments format to place a limit order in orderRegular method of python build

Hi @Kiran_Thomas,

Assumptions:

  • instrument: instrument object on which you want to place the order
  • action: ‘BUY’ or ‘SELL’
  • quantity: self.number_of_lots * instrument.lot_size
  • price: numerical value
  • trigger_price: numerical value

MARKET order

self.broker.OrderRegular(instrument=instrument, order_transaction_type=action, quantity=quantity)

LIMIT order

self.broker.OrderRegular(instrument=instrument, order_transaction_type=action, quantity=quantity, order_variety=BrokerOrderVarietyConstants.LIMIT, price=price)

STOPLOSS_MARKET order

self.broker.OrderRegular(instrument=instrument, order_transaction_type=action, quantity=quantity, order_variety=BrokerOrderVarietyConstants.STOPLOSS_MARKET, trigger_price=trigger_price)

STOPLOSS_LIMIT order

self.broker.OrderRegular(instrument=instrument, order_transaction_type=action, quantity=quantity, order_variety=BrokerOrderVarietyConstants.STOPLOSS_LIMIT, price=price, trigger_price=trigger_price)

Hope this helps.

Warm Regards,
`Akhil

1 Like

how can i check the current status of the order from the broker and then deciding whether to proceed with the exit command to handle the scenario where an order has already been manually exited or exited by STOPLOSS_MARKET order from the broker but my code still attempts to exit it based on its other conditions.

Hi @Kiran_Thomas,

You can check the order status for your order in the following manner:
order_status = str(_order.get_order_status())

You can then check:
if order_status == 'COMPLETE':
and implement the next steps accordingly.

The expected values for order status are:

PUT_ORDER_REQ_RECEIVED
VALIDATION_PENDING
OPEN_PENDING
TRIGGER_PENDING
CANCEL_PENDING
COMPLETE
CANCELLED
OPEN
REJECTED

Hope this helps.

Warm Regards,
`Akhil

but in this scenario i may need to get status from the broker since i have manually exited the order. if only the position is active then i can implement the next steps.

Hi @Kiran_Thomas,

These status values are internally mapped with the broker statuses for consistency.

Try implementing using these values, you should be able to proceed without any issues.

Hope this helps.

`Akhil

ok ,thanks . will try this …

what will be the expected value from order_status = str(_order.get_order_status()) if the order is not present or its already exited.

Hi @Kiran_Thomas,

Once an order has been processed by the strategy, then the strategy has to manage the order internally for any further steps.

A suggested solution would be:

  • instrument is selected for exit in strategy_select_instruments_for_exit() method

  • Order(s) present for this instrument are processed (exited) in strategy_exit_position() method

  • Order(s) should be set to None in strategy_exit_position() method

  • Before calling _order.get_order_status(), an if condition should be added. Something like if _order is not None:.

In other words, the strategist (strategy coder) and the strategy have the independence to handle orders internally, while calling any of the order object’s methods.

Hope this helps.

`Akhil

1 Like