Beispiel #1
0
    def generateTrade(self, tradingSymbol, direction, high, low):
        trade = Trade(tradingSymbol)
        trade.strategy = self.getName()
        trade.isFutures = True
        trade.direction = direction
        trade.productType = self.productType
        trade.placeMarketOrder = True
        trade.requestedEntry = high if direction == Direction.LONG else low
        trade.timestamp = Utils.getEpoch(
            self.startTimestamp)  # setting this to strategy timestamp
        # Calculate lots
        numLots = self.calculateLotsPerTrade()
        isd = Instruments.getInstrumentDataBySymbol(
            tradingSymbol)  # Get instrument data to know qty per lot
        trade.qty = isd['lot_size']

        trade.stopLoss = low if direction == Direction.LONG else high
        slDiff = high - low
        # target is 1.5 times of SL
        if direction == 'LONG':
            trade.target = Utils.roundToNSEPrice(trade.requestedEntry +
                                                 1.5 * slDiff)
        else:
            trade.target = Utils.roundToNSEPrice(trade.requestedEntry -
                                                 1.5 * slDiff)

        trade.intradaySquareOffTimestamp = Utils.getEpoch(
            self.squareOffTimestamp)
        # Hand over the trade to TradeManager
        TradeManager.addNewTrade(trade)
Beispiel #2
0
    def generateTrade(self, optionSymbol, numLots, lastTradedPrice,
                      counterPosition):
        trade = Trade(optionSymbol)
        trade.strategy = self.getName()
        trade.isOptions = True
        trade.direction = Direction.SHORT  # Always short here as option selling only
        trade.productType = self.productType
        trade.placeMarketOrder = True
        trade.requestedEntry = lastTradedPrice
        trade.timestamp = Utils.getEpoch(
            self.startTimestamp)  # setting this to strategy timestamp
        trade.slPercentage = 25
        trade.moveToCost = True
        trade.counterPosition = counterPosition

        isd = Instruments.getInstrumentDataBySymbol(
            optionSymbol)  # Get instrument data to know qty per lot
        trade.qty = isd['lot_size'] * numLots

        trade.stopLoss = Utils.roundToNSEPrice(trade.requestedEntry +
                                               trade.requestedEntry *
                                               self.slPercentage / 100)
        trade.target = 0  # setting to 0 as no target is applicable for this trade

        trade.intradaySquareOffTimestamp = Utils.getEpoch(
            self.squareOffTimestamp)
        # Hand over the trade to TradeManager
        TradeManager.addNewTrade(trade)
  def unregisterSymbols(self, symbols):
    tokens = []
    for symbol in symbols:
      isd = Instruments.getInstrumentDataBySymbol(symbol)
      token = isd['instrument_token']
      logging.info('ZerodhaTicker unregisterSymbols: %s token = %s', symbol, token)
      tokens.append(token)

    logging.info('ZerodhaTicker Unsubscribing tokens %s', tokens)
    self.ticker.unsubscribe(tokens)