def test_estimate_average_price(): assert jh.estimate_average_price(100, 7200, 0, 0) == 7200 with pytest.raises(TypeError): jh.estimate_average_price(100, 7200, 0, None) jh.estimate_average_price(100, 7200, None, 0) jh.estimate_average_price(100, None, 0, 0) jh.estimate_average_price(None, 7200, 0, 0)
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)