def _open(self, qty, price, change_balance=True): if self.is_open: raise OpenPositionError( 'an already open position cannot be opened') if change_balance: size = abs(qty) * price if self.exchange: self.exchange.decrease_balance(self, size) self.entry_price = price self.exit_price = None self.qty = qty self.opened_at = jh.now() info_text = 'OPENED {} position: {}, {}, {}, ${}'.format( self.type, self.exchange_name, self.symbol, self.qty, round(self.entry_price, 2)) if jh.is_debuggable('position_opened'): logger.info(info_text) if jh.is_live( ) and config['env']['notifications']['events']['updated_position']: notifier.notify(info_text)
def _increase(self, qty, price): if not self.is_open: raise OpenPositionError( 'position must be already open in order to incrase its size') qty = abs(qty) size = qty * price if self.exchange: self.exchange.decrease_balance(self, size) self.entry_price = jh.estimate_average_price(qty, price, self.qty, self.entry_price) if self.type == trade_types.LONG: self.qty += qty elif self.type == trade_types.SHORT: self.qty -= qty info_text = 'INCREASED position: {}, {}, {}, {}, ${}'.format( self.exchange_name, self.symbol, self.type, self.qty, round(self.entry_price, 2)) if jh.is_debuggable('position_increased'): logger.info(info_text) if jh.is_live( ) and config['env']['notifications']['events']['updated_position']: notifier.notify(info_text)
def _increase(self, qty: float, price: float) -> None: if not self.is_open: raise OpenPositionError('position must be already open in order to increase its size') qty = abs(qty) # size = qty * price # if self.exchange: # self.exchange.decrease_futures_balance(size) self.entry_price = jh.estimate_average_price(qty, price, self.qty, self.entry_price) if self.type == trade_types.LONG: self.qty = sum_floats(self.qty, qty) elif self.type == trade_types.SHORT: self.qty = subtract_floats(self.qty, qty) info_text = f'INCREASED position: {self.exchange_name}, {self.symbol}, {self.type}, {self.qty}, ${round(self.entry_price, 2)}' if jh.is_debuggable('position_increased'): logger.info(info_text) if jh.is_live() and config['env']['notifications']['events']['updated_position']: notifier.notify(info_text)
def _open(self, qty: float, price: float, change_balance: bool = True) -> None: if self.is_open: raise OpenPositionError('an already open position cannot be opened') self.entry_price = price self.exit_price = None self.qty = qty self.opened_at = jh.now_to_timestamp() info_text = f'OPENED {self.type} position: {self.exchange_name}, {self.symbol}, {self.qty}, ${round(self.entry_price, 2)}' if jh.is_debuggable('position_opened'): logger.info(info_text) if jh.is_live() and config['env']['notifications']['events']['updated_position']: notifier.notify(info_text)