Unable To Place Sell Order In Paper Trading

I am trying paper trading. It is throwing the below error which is working fine in backtesting but working fine in paper trading.

Code:

def strategy_enter_position(self, candle, instrument, sideband_info):
    self.logger.info('Entering Position')
    child = sideband_info['child']
    self.main_order_map[instrument] = self.broker.OrderRegular(instrument, sideband_info['action'], quantity=self.number_of_lots * instrument.lot_size, position=BrokerExistingOrderPositionConstants.ENTER)
    
    buy_order_status = str(self.main_order_map[instrument].get_order_status())
    self.logger.info(buy_order_status)
    self.logger.info(self.instrument.lot_size)
    
            
    if buy_order_status == 'COMPLETE':
        self.order_details['FirstSellOrder']=self.broker.OrderRegular(instrument=instrument, order_transaction_type='SELL', quantity=2*self.instrument.lot_size, position=BrokerExistingOrderPositionConstants.EXIT, order_variety=BrokerOrderVarietyConstants.LIMIT, price = self.Action[child]['Target1'])
        self.logger.info(self.order_details['FirstSellOrder'])
        self.logger.info('FirstSellOrder')
        self.logger.info(self.order_details['FirstSellOrder'].get_order_status())
        
        self.order_details['SecondSellOrder']=self.broker.OrderRegular(instrument=instrument, order_transaction_type='SELL', quantity=2*self.instrument.lot_size, position=BrokerExistingOrderPositionConstants.EXIT, order_variety=BrokerOrderVarietyConstants.LIMIT, price=self.Action[child]['Target2'])
        #self.logger.info(str(self.main_order_map[instrument].get_order_status()))
        #self.order_details['SecondSellOrder'] = self.main_order_map[instrument]
        self.logger.info('SecondSellOrder')
        self.logger.info(self.order_details['SecondSellOrder'].get_order_status())

    
    return self.main_order_map[instrument]

Backtesting Results - Working fine

[BT] [2023-12-22 09:42:00,000] [INFO] [tls] Entering position for instrument: NSE_FO:NIFTY28DEC2321250CE [LOCAL]…
[BT] [2023-12-22 09:42:00,000] [INFO] [strategy] Entering Position
[BT] [2023-12-22 09:42:00,000] [INFO] [order] [PLACING NEW ORDER] [2023-12-22 09:42:00+05:30] [21ba839961b245d38c82e8691032ca51] [BUY] [NSE_FO:NIFTY28DEC2321250CE] [QTY:200] [QTY PENDING: 200] [ENTRY PRICE: 185.75] [PRICE:None] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_MARKET] [ORDER_POSITION_ENTER]
[BT] [2023-12-22 09:42:00,000] [INFO] [order] [ORDER ID RECEIVED] [ABVIRTUALBROKER] [ID:21ba839961b245d38c82e8691032ca51] [BUY] [NSE_FO:NIFTY28DEC2321250CE [LOCAL]] [Order ID: (Order: [2023-12-22 09:42:00+05:30] [21ba839961b245d38c82e8691032ca51] [BUY] [NSE_FO:NIFTY28DEC2321250CE] [QTY:200] [QTY PENDING: 200] [ENTRY PRICE: 185.75] [PRICE:None] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_MARKET] [ORDER_POSITION_ENTER])
Status History: PUT ORDER REQ RECEIVED → VALIDATION PENDING → OPEN PENDING → OPEN → COMPLETE)]
[BT] [2023-12-22 09:42:00,000] [INFO] [order] [NEW ORDER SUCCESS] [2023-12-22 09:42:00+05:30] [21ba839961b245d38c82e8691032ca51] [BUY] [NSE_FO:NIFTY28DEC2321250CE] [QTY:200] [QTY PENDING: 200] [ENTRY PRICE: 185.75] [PRICE:None] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_MARKET] [ORDER_POSITION_ENTER] [STATUS:COMPLETE]
[BT] [2023-12-22 09:42:00,000] [INFO] [strategy] COMPLETE
[BT] [2023-12-22 09:42:00,000] [INFO] [strategy] 50
[BT] [2023-12-22 09:42:00,000] [INFO] [order] [PLACING NEW ORDER] [2023-12-22 09:42:00+05:30] [befae6952e9240319498b85f66db349b] [SELL] [NSE_FO:NIFTY28DEC2321250CE] [QTY:100] [QTY PENDING: 100] [ENTRY PRICE: 203.15] [PRICE:203.15] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_LIMIT] [ORDER_POSITION_EXIT]
[BT] [2023-12-22 09:42:00,000] [INFO] [order] [ORDER ID RECEIVED] [ABVIRTUALBROKER] [ID:befae6952e9240319498b85f66db349b] [SELL] [NSE_FO:NIFTY28DEC2321250CE [LOCAL]] [Order ID: (Order: [2023-12-22 09:42:00+05:30] [befae6952e9240319498b85f66db349b] [SELL] [NSE_FO:NIFTY28DEC2321250CE] [QTY:100] [QTY PENDING: 100] [ENTRY PRICE: 203.15] [PRICE:203.15] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_LIMIT] [ORDER_POSITION_EXIT])
Status History: PUT ORDER REQ RECEIVED → VALIDATION PENDING → OPEN PENDING → OPEN)]
[BT] [2023-12-22 09:42:00,000] [INFO] [order] [NEW ORDER SUCCESS] [2023-12-22 09:42:00+05:30] [befae6952e9240319498b85f66db349b] [SELL] [NSE_FO:NIFTY28DEC2321250CE] [QTY:100] [QTY PENDING: 100] [ENTRY PRICE: 203.15] [PRICE:203.15] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_LIMIT] [ORDER_POSITION_EXIT] [STATUS:OPEN]
[BT] [2023-12-22 09:42:00,000] [INFO] [strategy] [2023-12-22 09:42:00+05:30] [befae6952e9240319498b85f66db349b] [SELL] [NSE_FO:NIFTY28DEC2321250CE] [QTY:100] [QTY PENDING: 100] [ENTRY PRICE: 203.15] [PRICE:203.15] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_LIMIT] [ORDER_POSITION_EXIT]
[BT] [2023-12-22 09:42:00,000] [INFO] [strategy] FirstSellOrder
[BT] [2023-12-22 09:42:00,000] [INFO] [strategy] OPEN
[BT] [2023-12-22 09:42:00,000] [INFO] [order] [PLACING NEW ORDER] [2023-12-22 09:42:00+05:30] [1e2d53ab452a4b54bf96bf30c95d2615] [SELL] [NSE_FO:NIFTY28DEC2321250CE] [QTY:100] [QTY PENDING: 100] [ENTRY PRICE: 221.3] [PRICE:221.3] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_LIMIT] [ORDER_POSITION_EXIT]
[BT] [2023-12-22 09:42:00,000] [INFO] [order] [ORDER ID RECEIVED] [ABVIRTUALBROKER] [ID:1e2d53ab452a4b54bf96bf30c95d2615] [SELL] [NSE_FO:NIFTY28DEC2321250CE [LOCAL]] [Order ID: (Order: [2023-12-22 09:42:00+05:30] [1e2d53ab452a4b54bf96bf30c95d2615] [SELL] [NSE_FO:NIFTY28DEC2321250CE] [QTY:100] [QTY PENDING: 100] [ENTRY PRICE: 221.3] [PRICE:221.3] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_LIMIT] [ORDER_POSITION_EXIT])
Status History: PUT ORDER REQ RECEIVED → VALIDATION PENDING → OPEN PENDING → OPEN)]
[BT] [2023-12-22 09:42:00,000] [INFO] [order] [NEW ORDER SUCCESS] [2023-12-22 09:42:00+05:30] [1e2d53ab452a4b54bf96bf30c95d2615] [SELL] [NSE_FO:NIFTY28DEC2321250CE] [QTY:100] [QTY PENDING: 100] [ENTRY PRICE: 221.3] [PRICE:221.3] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_LIMIT] [ORDER_POSITION_EXIT] [STATUS:OPEN]
[BT] [2023-12-22 09:42:00,000] [INFO] [strategy] SecondSellOrder
[BT] [2023-12-22 09:42:00,000] [INFO] [strategy] OPEN

Paper Trading

[PT] [2024-03-22 10:00:05,338] [INFO] [strategy] Entering Position
[PT] [2024-03-22 10:00:05,366] [INFO] [order] [PLACING NEW ORDER] [2024-03-22 10:00:05+05:30] [4ca634a318fc400e991a5b51550ba5d3] [BUY] [NSE_FO:NIFTY28MAR2421900CE] [QTY:200] [QTY PENDING: 200] [ENTRY PRICE: 223.7] [PRICE:None] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_MARKET] [ORDER_POSITION_ENTER]
[PT] [2024-03-22 10:00:05,367] [INFO] [order] [ORDER ID RECEIVED] [ABVIRTUALBROKER] [ID:4ca634a318fc400e991a5b51550ba5d3] [BUY] [NSE_FO:NIFTY28MAR2421900CE] [Order ID: (Order: [2024-03-22 10:00:05+05:30] [4ca634a318fc400e991a5b51550ba5d3] [BUY] [NSE_FO:NIFTY28MAR2421900CE] [QTY:200] [QTY PENDING: 200] [ENTRY PRICE: 223.7] [PRICE:None] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_MARKET] [ORDER_POSITION_ENTER])
Status History: PUT ORDER REQ RECEIVED → VALIDATION PENDING → OPEN PENDING → OPEN → COMPLETE)]
[PT] [2024-03-22 10:00:05,367] [INFO] [order] [NEW ORDER SUCCESS] [2024-03-22 10:00:05+05:30] [4ca634a318fc400e991a5b51550ba5d3] [BUY] [NSE_FO:NIFTY28MAR2421900CE] [QTY:200] [QTY PENDING: 200] [ENTRY PRICE: 223.7] [PRICE:None] [TRIGGER PRICE:None] [ORDER_TYPE_REGULAR] [ORDER_CODE_INTRADAY] [ORDER_VARIETY_MARKET] [ORDER_POSITION_ENTER] [STATUS:COMPLETE]
[PT] [2024-03-22 10:00:05,367] [INFO] [strategy] COMPLETE
[PT] [2024-03-22 10:00:05,367] [CRITICAL] [tls] Strategy encountered unknown error. Exiting…
[PT] [2024-03-22 10:00:05,370] [INFO] [tls] Received event EXCEPTION. Stopping AlgoBulls Trading Core Engine…
[PT] [2024-03-22 10:00:05,370] [INFO] [tls] Cancelling all open orders (if any)…
[PT] [2024-03-22 10:00:05,370] [INFO] [tls] Exiting all open positions…
[PT] [2024-03-22 10:00:05,370] [INFO] [tls] Exiting all open positions with order code: ORDER_CODE_INTRADAY (if any)…
[PT] [2024-03-22 10:00:05,371] [INFO] [tls] Exiting all open positions with order code: ORDER_CODE_DELIVERY_T0 (if any)…
[PT] [2024-03-22 10:00:05,371] [INFO] [tls] Exiting all open positions with order code: ORDER_CODE_DELIVERY_T1 (if any)…
[PT] [2024-03-22 10:00:05,371] [INFO] [tls] Exiting all open positions with order code: ORDER_CODE_DELIVERY_T2 (if any)…
[PT] [2024-03-22 10:00:05,699] [INFO] [tls] [User: ALGOBULLS VIRTUAL USER] Trading session completed
[PT] [2024-03-22 10:00:05,700] [CRITICAL] [tls] Dumping Debug Stack to Python friendly Traceback Format for Python Build Customers: Uncaught exception | Exception Class: <class ‘AssertionError’> | Exception Details: Argument “0” did not qualify the extern_function “<function is_positive_int at 0x7fcbd6601ab0>”. (Message: quantity should be positive int or float) | Traceback Below:
File “/tmp/tmp5isu3jja/strategy_dir_1711078969400009/strategy.py”, line 273, in strategy_enter_position
self.order_details[‘FirstSellOrder’]=self.broker.OrderRegular(instrument=instrument, order_transaction_type=‘SELL’, quantity=2*self.instrument.lot_size, position=BrokerExistingOrderPositionConstants.EXIT, order_variety=BrokerOrderVarietyConstants.LIMIT, price = self.Action[child][‘Target1’])

[PT] [2024-03-22 10:00:05,700] [CRITICAL] [tls] An error has occurred due to which the strategy execution cannot proceed anymore. Reason: Argument “0” did not qualify the extern_function “<function is_positive_int at 0x7fcbd6601ab0>”. (Message: quantity should be positive int or float).
If the reason doesn’t help, please double check the config parameters you have provided. If everything seems fine, reach us on our Slack Community (Slack) for support.

Hi @Rutul_Patel ,

Kindly print your quantity parameter to check its value first.

self.logger.info(f'Quantity: {2*self.instrument.lot_size}')

If the above message reveals your quantity to be zero (0), then you may fix your logic accordingly.

Also, kindly add the related_order parameter as an additional step towards solving this issue.

As per your code snippet, the parameter and its value will be:

related_order=self.main_order_map[instrument]

The complete line(s) should be:

self.order_details['FirstSellOrder']=self.broker.OrderRegular(instrument=instrument, order_transaction_type='SELL', quantity=2*self.instrument.lot_size, position=BrokerExistingOrderPositionConstants.EXIT, related_order=self.main_order_map[instrument], order_variety=BrokerOrderVarietyConstants.LIMIT, price = self.Action[child]['Target1'])

and

self.order_details['SecondSellOrder']=self.broker.OrderRegular(instrument=instrument, order_transaction_type='SELL', quantity=2*self.instrument.lot_size, position=BrokerExistingOrderPositionConstants.EXIT, related_order=self.main_order_map[instrument], order_variety=BrokerOrderVarietyConstants.LIMIT, price=self.Action[child]['Target2'])

Kindly let us know if this resolves your issue.

Also, the logs mention the following line at the end:

If the reason doesn’t help, please double check the config parameters you have provided. If everything seems fine, reach us on our Slack Community (Slack) for support.

This line mentions the Slack community link, where you can get enhanced support.

We urge you to kindly join the community to get any further issues addressed and resolved.

Warm Regards,
`Akhil