def _convert_to_numpy_array(arr, name): if type(arr) is np.ndarray: return arr try: # create numpy array from list arr = np.array(arr, dtype=float) if jh.is_live(): # in livetrade mode, we'll need them rounded price = arr[0][1] prices = jh.round_price_for_live_mode(price, arr[:, 1]) qtys = jh.round_qty_for_live_mode(price, arr[:, 0]) arr[:, 0] = qtys arr[:, 1] = prices return arr except ValueError: raise exceptions.InvalidShape( 'The format of {} is invalid. \n' 'It must be (qty, price) or [(qty, price), (qty, price)] for multiple points; but {} was given'.format( name, arr ) )
def _convert_to_numpy_array(self, arr, name) -> np.ndarray: if type(arr) is np.ndarray: return arr try: # create numpy array from list arr = np.array(arr, dtype=float) if jh.is_live(): # in livetrade mode, we'll need them rounded current_exchange = selectors.get_exchange(self.exchange) # skip rounding if the exchange doesn't have values for 'precisions' if 'precisions' not in current_exchange.vars: return arr price_precision = current_exchange.vars['precisions'][self.symbol]['price_precision'] qty_precision = current_exchange.vars['precisions'][self.symbol]['qty_precision'] prices = jh.round_price_for_live_mode(arr[:, 1], price_precision) qtys = jh.round_qty_for_live_mode(arr[:, 0], qty_precision) arr[:, 0] = qtys arr[:, 1] = prices return arr except ValueError: raise exceptions.InvalidShape( f'The format of {name} is invalid. \n' f'It must be (qty, price) or [(qty, price), (qty, price)] for multiple points; but {arr} was given' )