def update_transaction_info(self, item): # First time work if not self.start_price: self.start_time_text = datetime.now().strftime('%H:%M') self.start_time = self.to_min_count(self.start_time_text) self.start_price = item.current_price reference_price = wmath.get_bottom(item.current_price, self.interval) self.set_reference(reference_price) self.leverage.buy(self.buy_limit, self.capital // item.current_price, 'MARKET') return # Trade if self.sell_off_ordered: msg = ('sale.ordered:' + str(self.leverage.episode_sale.ordered), 'open_amount:' + str(self.leverage.episode_sale.open_amount)) self.post('(SELL_OFF)', *msg) if self.leverage.episode_sale.ordered or self.leverage.episode_sale.open_amount: return self.sell_off_ordered = False if item.current_price >= self.reference_price + self.interval: self.post('Situation 1') self.shift_reference_up() if self.leverage.holding_amount: self.leverage.correct_purchase(self.buy_limit) elif item.current_price >= self.buy_limit + self.loss_cut: self.post('Situation 2') self.leverage.sell_out(self.reference_price) elif item.current_price <= self.loss_limit: self.post('Situation 4') self.sell_off_ordered = True self.leverage.sell_off_deprecated() self.shift_reference_down() elif item.current_price <= self.reference_price - self.loss_cut: self.post('Situation 3') self.leverage.buy_up()
def set_reference(self, current_price): if self.trade_position == LONG_POSITION: self.reference_price = wmath.get_top(current_price, self.interval) self.trade_limit = self.reference_price - self.interval self.loss_limit = self.trade_limit - self.loss_cut self.episode_amount = int(self.capital // (self.trade_limit * MULTIPLIER)) elif self.trade_position == SHORT_POSITION: self.reference_price = wmath.get_bottom(current_price, self.interval) self.trade_limit = self.reference_price + self.interval self.loss_limit = self.trade_limit + self.loss_cut self.episode_amount = int(self.capital // (self.trade_limit * MULTIPLIER))