def placeTargetOrder(trade, isMarketOrder = False):
   oip = OrderInputParams(trade.tradingSymbol)
   oip.direction = Direction.SHORT if trade.direction == Direction.LONG else Direction.LONG
   oip.productType = trade.productType
   oip.orderType = OrderType.MARKET if isMarketOrder == True else OrderType.LIMIT
   oip.price = 0 if isMarketOrder == True else trade.target
   oip.qty = trade.qty
   try:
     trade.targetOrder = TradeManager.getOrderManager().placeOrder(oip)
   except Exception as e:
     logging.exrror('TradeManager: Failed to place Target order for tradeID %s: Error => %s', trade.tradeID, str(e))
     return False
   logging.info('TradeManager: Successfully placed Target order %s for tradeID %s', trade.targetOrder.orderId, trade.tradeID)
   return True
 def placeSLOrder(trade):
   oip = OrderInputParams(trade.tradingSymbol)
   oip.direction = Direction.SHORT if trade.direction == Direction.LONG else Direction.LONG 
   oip.productType = trade.productType
   oip.orderType = OrderType.SL_MARKET
   oip.triggerPrice = trade.stopLoss
   oip.qty = trade.qty
   try:
     trade.slOrder = TradeManager.getOrderManager().placeOrder(oip)
   except Exception as e:
     logging.error('TradeManager: Failed to place SL order for tradeID %s: Error => %s', trade.tradeID, str(e))
     return False
   logging.info('TradeManager: Successfully placed SL order %s for tradeID %s', trade.slOrder.orderId, trade.tradeID)
   return True
  def executeTrade(trade):
    logging.info('TradeManager: Execute trade called for %s', trade)
    trade.initialStopLoss = trade.stopLoss
    # Create order input params object and place order
    oip = OrderInputParams(trade.tradingSymbol)
    oip.direction = trade.direction
    oip.productType = trade.productType
    oip.orderType = OrderType.MARKET if trade.placeMarketOrder == True else OrderType.LIMIT
    oip.price = trade.requestedEntry
    oip.qty = trade.qty
    try:
      trade.entryOrder = TradeManager.getOrderManager().placeOrder(oip)
    except Exception as e:
      logging.exrror('TradeManager: Execute trade failed for tradeID %s: Error => %s', trade.tradeID, str(e))
      return False

    logging.info('TradeManager: Execute trade successful for %s and entryOrder %s', trade, trade.entryOrder)
    return True
Exemple #4
0
 def placeEmergencyExitOrder(trade):
     logging.info(
         "TradeManager: Placing emergency exit order as SL order was cancelled by exchange"
     )
     oip = OrderInputParams(trade.tradingSymbol)
     oip.direction = Direction.SHORT if trade.direction == Direction.LONG else Direction.LONG
     oip.productType = trade.productType
     oip.orderType = OrderType.MARKET
     oip.qty = trade.qty
     if trade.isFutures == True or trade.isOptions == True:
         oip.isFnO = True
     try:
         trade.emergencyExitOrder = TradeManager.getOrderManager(
         ).placeOrder(oip)
     except Exception as e:
         logging.error(
             'TradeManager: Failed to place emergency exit order for tradeID %s: Error => %s',
             trade.tradeID, str(e))
Exemple #5
0
    def placeSLOrder(trade):
        oip = OrderInputParams(trade.tradingSymbol)
        oip.direction = Direction.SHORT if trade.direction == Direction.LONG else Direction.LONG
        oip.productType = trade.productType
        oip.orderType = OrderType.SL_MARKET
        oip.triggerPrice = Utils.roundToNSEPrice(trade.entry + trade.entry *
                                                 trade.slPercentage / 100)
        oip.qty = trade.qty
        if trade.isFutures == True or trade.isOptions == True:
            oip.isFnO = True
        try:
            trade.slOrder = TradeManager.getOrderManager().placeOrder(oip)
        except Exception as e:
            logging.error(
                'TradeManager: Failed to place SL order for tradeID %s: Error => %s',
                trade.tradeID, str(e))
            return False

        message = "TradeManager: Successfully placed SL order {0} for tradeID {1}".format(
            trade.slOrder.orderId, trade.tradeID)
        Utils.sendMessageTelegramBot(message)
        logging.info(message)
        return True