def test_round_qty_for_live_mode(): np.testing.assert_equal( jh.round_qty_for_live_mode(np.array([100.3209123456, 100.4299123456]), 2), np.array([100.32, 100.42])) np.testing.assert_equal(jh.round_qty_for_live_mode(np.array([0]), 1), np.array([0.1])) np.testing.assert_equal(jh.round_qty_for_live_mode(np.array([0]), 2), np.array([0.01])) np.testing.assert_equal(jh.round_qty_for_live_mode(np.array([0]), 3), np.array([0.001]))
def test_round_qty_for_live_mode(): np.testing.assert_equal( jh.round_qty_for_live_mode( 0.0003209123456, np.array([100.0003209123456, 100.0004209123456])), np.array([100, 100])) np.testing.assert_equal( jh.round_qty_for_live_mode( 0.003209123456, np.array([100.003209123456, 100.004209123456])), np.array([100, 100])) np.testing.assert_equal( jh.round_qty_for_live_mode( 0.01117123456, np.array([100.01117123456, 100.02117123456])), np.array([100, 100])) np.testing.assert_equal( jh.round_qty_for_live_mode(0.1592123456, np.array([100.1592123456, 100.2592123456])), np.array([100, 100])) np.testing.assert_equal( jh.round_qty_for_live_mode(2.123456, np.array([2.123456, 1.123456])), np.array([2.1, 1.1])) np.testing.assert_equal( jh.round_qty_for_live_mode(137.123456, np.array([137.123456, 837.123456])), np.array([137.123, 837.123])) np.testing.assert_equal( jh.round_qty_for_live_mode(6700.123456, np.array([0.123456, 0.124456])), np.array([0.123, 0.124])) # assert that orders smaller than 0.001 will get rounded to 0.001 because that's the minimum order qty on Binance np.testing.assert_equal( jh.round_qty_for_live_mode(6700.123456, np.array([0.0005, 0.0004])), np.array([0.001, 0.001]))
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' )
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 test_round_qty_for_live_mode(): np.testing.assert_equal( jh.round_qty_for_live_mode( 0.0003209123456, np.array([100.0003209123456, 100.0004209123456])), np.array([100, 100])) np.testing.assert_equal( jh.round_qty_for_live_mode( 0.003209123456, np.array([100.003209123456, 100.004209123456])), np.array([100, 100])) np.testing.assert_equal( jh.round_qty_for_live_mode( 0.01117123456, np.array([100.01117123456, 100.02117123456])), np.array([100, 100])) np.testing.assert_equal( jh.round_qty_for_live_mode(0.1592123456, np.array([100.1592123456, 100.2592123456])), np.array([100, 100])) np.testing.assert_equal( jh.round_qty_for_live_mode(2.123456, np.array([2.123456, 1.123456])), np.array([2.1, 1.1])) np.testing.assert_equal( jh.round_qty_for_live_mode(137.123456, np.array([137.123456, 837.123456])), np.array([137.123, 837.123])) np.testing.assert_equal( jh.round_qty_for_live_mode(6700.123456, np.array([0.123456, 0.124456])), np.array([0.123, 0.124]))