def _setup(self, ltp_quote): self.instrument = ltp_quote['instrument'] ltp = ltp_quote['ltp'] levels = gann(ltp) self.buy = levels[DEFAULTS['buy']] self.target = levels[DEFAULTS['target']] self.stoploss = gann(ltp, 'down')[DEFAULTS['stoploss']] self.prev_ltp = ltp self._print_levels() self.state.append('setup complete')
def process_quote(self, quote): ltp = quote['ltp'] act = None if 'setup complete' not in self.state: self._setup(quote) return act if ltp > self.buy + ltp * 0.01: self.uptrend = False return act if 'order placed' == self.state[-1]: return act elif ltp > self.buy: act = self._create_buy_order() self.state.append('order placed') elif ltp < self.prev_ltp: levels = gann(ltp) self.buy = levels[DEFAULTS['buy']] self.target = levels[DEFAULTS['target']] self.stoploss = gann(ltp, 'down')[DEFAULTS['stoploss']] self.prev_ltp = ltp self._print_levels() return act