Beispiel #1
0
    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
                )
            )
Beispiel #2
0
    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'
            )
Beispiel #3
0
def test_round_price_for_live_mode():
    np.testing.assert_equal(
        jh.round_price_for_live_mode(
            0.0003209123456, np.array([0.0003209123456, 0.0004209123456])),
        np.array([0.0003209, 0.0004209]))
    np.testing.assert_equal(
        jh.round_price_for_live_mode(
            0.003209123456, np.array([0.003209123456, 0.004209123456])),
        np.array([0.003209, 0.004209]))
    np.testing.assert_equal(
        jh.round_price_for_live_mode(0.01117123456,
                                     np.array([0.01117123456, 0.02117123456])),
        np.array([0.01117, 0.02117]))
    np.testing.assert_equal(
        jh.round_price_for_live_mode(0.1592123456,
                                     np.array([0.1592123456, 0.2592123456])),
        np.array([0.1592, 0.2592]))
    np.testing.assert_equal(
        jh.round_price_for_live_mode(2.123456, np.array([2.123456, 1.123456])),
        np.array([2.123, 1.123]))
    np.testing.assert_equal(
        jh.round_price_for_live_mode(137.123456,
                                     np.array([137.123456, 837.123456])),
        np.array([137.1, 837.1]))
    np.testing.assert_equal(
        jh.round_price_for_live_mode(6700.123456,
                                     np.array([6700.123456, 1000.123456])),
        np.array([6700, 1000]))
Beispiel #4
0
    def update_position(exchange: str, symbol: str, candle: np.ndarray):
        # get position object
        p = selectors.get_position(exchange, symbol)

        # for extra_route candles, p == None, hence no further action is required
        if p is None:
            return

        # update position.current_price
        p.current_price = jh.round_price_for_live_mode(candle[2], candle[2])
Beispiel #5
0
    def update_position(exchange: str, symbol: str, candle: np.ndarray) -> None:
        # get position object
        p = selectors.get_position(exchange, symbol)

        # for extra_route candles, p == None, hence no further action is required
        if p is None:
            return

        price_precision = 0
        if jh.is_live():
          price_precision = selectors.get_exchange(exchange).vars['precisions'][symbol]['price_precision']

        # update position.current_price
        p.current_price = jh.round_price_for_live_mode(candle[2], candle[2], price_precision)
Beispiel #6
0
def test_round_price_for_live_mode():
    np.testing.assert_equal(
        jh.round_price_for_live_mode(
            np.array([0.0003209123456, 0.0004209123456]), 7),
        np.array([0.0003209, 0.0004209]))