Пример #1
0
    def get_trade_fee(
            self,
            symbol,
            order_type,
            quantity,
            price,
            taker_or_maker=ExchangeConstantsMarketPropertyColumns.TAKER.value):
        symbol_fees = self.get_fees(symbol)
        rate = symbol_fees[
            taker_or_maker] / 100  # /100 because rate in used in %
        currency, market = split_symbol(symbol)
        fee_currency = currency

        precision = self.get_market_status(symbol)[ExchangeConstantsMarketStatusColumns.PRECISION.value] \
            [ExchangeConstantsMarketStatusColumns.PRECISION_PRICE.value]
        cost = float(round_into_str_with_max_digits(quantity * rate,
                                                    precision))

        if order_type == TraderOrderType.SELL_MARKET or order_type == TraderOrderType.SELL_LIMIT:
            cost = float(
                round_into_str_with_max_digits(cost * price, precision))
            fee_currency = market

        return {
            FeePropertyColumns.TYPE.value: taker_or_maker,
            FeePropertyColumns.CURRENCY.value: fee_currency,
            FeePropertyColumns.RATE.value: rate,
            FeePropertyColumns.COST.value: cost
        }
Пример #2
0
 def get_min_string_from_number(number, max_digits=8):
     if number is None or round(number, max_digits) == 0.0:
         return "0"
     else:
         if number % 1 != 0:
             number_str = round_into_str_with_max_digits(number, max_digits)
             if "." in number_str:
                 number_str = number_str.rstrip("0.")
             return number_str
         return "{:f}".format(number).split(".")[0]
Пример #3
0
    def get_trade_fee(self, symbol, order_type, quantity, price, taker_or_maker):
        if not taker_or_maker:
            taker_or_maker = enums.ExchangeConstantsMarketPropertyColumns.TAKER.value
        symbol_fees = self.get_fees(symbol)
        rate = symbol_fees[taker_or_maker] / 100  # /100 because rate in used in %
        currency, market = symbol_util.split_symbol(symbol)
        fee_currency = currency

        precision = self.get_market_status(symbol)[enums.ExchangeConstantsMarketStatusColumns.PRECISION.value] \
            [enums.ExchangeConstantsMarketStatusColumns.PRECISION_PRICE.value]
        cost = float(number_util.round_into_str_with_max_digits(float(quantity) * rate, precision))

        if order_type == enums.TraderOrderType.SELL_MARKET or order_type == enums.TraderOrderType.SELL_LIMIT:
            cost = float(number_util.round_into_str_with_max_digits(cost * float(price), precision))
            fee_currency = market

        return {
            enums.FeePropertyColumns.TYPE.value: taker_or_maker,
            enums.FeePropertyColumns.CURRENCY.value: fee_currency,
            enums.FeePropertyColumns.RATE.value: rate,
            enums.FeePropertyColumns.COST.value: decimal.Decimal(str(cost)),
        }
def get_min_string_from_number(number, max_digits=8) -> str:
    """
    Get a min string from number
    :param number: the number
    :param max_digits: the mex digits
    :return: the string from number
    """
    if number is None or round(number, max_digits) == 0.0:
        return "0"
    if number % 1 != 0:
        number_str = number_util.round_into_str_with_max_digits(number, max_digits)
        # remove post comma trailing 0
        if "." in number_str:
            # remove "0" first and only the "." to avoid removing 2x"0" in 10.0 and returning 1 for example.
            number_str = number_str.rstrip("0").rstrip(".")
        return number_str
    return "{:f}".format(number).split(".")[0]
Пример #5
0
def test_round_into_max_digits():
    assert round_into_str_with_max_digits(125.0256, 2) == '125.03'
    assert round_into_float_with_max_digits(125.0210, 2) == 125.02
    assert round_into_float_with_max_digits(1301, 5) == 1301.00000
    assert round_into_float_with_max_digits(59866, 0) == 59866
    assert round_into_float_with_max_digits(1.567824117582484154178,
                                            15) == 1.567824117582484
    assert round_into_float_with_max_digits(0.000000059, 8) == 0.00000006
    assert not round_into_float_with_max_digits(8712661000.1273185137283,
                                                10) == 8712661000.127318
    assert round_into_float_with_max_digits(8712661000.1273185137283,
                                            10) == 8712661000.1273185
    assert round_into_float_with_max_digits(8712661000.1273185137283,
                                            10) == 8712661000.12731851
    assert round_into_float_with_max_digits(8712661000.1273185137283,
                                            10) == 8712661000.127318513
    assert round_into_float_with_max_digits(8712661000.1273185137283,
                                            10) == 8712661000.1273185137
    assert round_into_float_with_max_digits(0.0000000000001, 5) == 0
    assert not round_into_float_with_max_digits(0.0000000000001, 13) == 0