def _check_limits(self, sell_base, sell_max, quantity, sell_orders_count, symbol_market):
        min_quantity, max_quantity, min_cost, max_cost, min_price, max_price = trading_personal_data.get_min_max_amounts(
            symbol_market)
        orders_count = sell_orders_count

        limit_check = DipAnalyserTradingModeConsumer._ensure_orders_size(
            sell_base, sell_max, quantity, orders_count,
            min_quantity, min_cost, min_price,
            max_quantity, max_cost, max_price)

        while limit_check > 0:
            if limit_check == 1:
                if orders_count > 1:
                    orders_count -= 1
                else:
                    # not enough funds to create orders
                    self.logger.warning(f"Not enough funds to create sell order.")
                    return 0, 0
            elif limit_check == 2:
                if orders_count < 40:
                    orders_count += 1
                else:
                    # too many orders to create, must be a problem
                    self.logger.error("Too many orders to create: error with _generate_sell_orders.")
                    return 0, 0
            limit_check = DipAnalyserTradingModeConsumer._ensure_orders_size(
                sell_base, sell_max, quantity, orders_count,
                min_quantity, min_cost, min_price,
                max_quantity, max_cost, max_price)
        return orders_count, (sell_max - sell_base) / orders_count
Ejemplo n.º 2
0
def test_get_min_max_amounts():
    # normal values
    symbol_market = {
        enums.ExchangeConstantsMarketStatusColumns.LIMITS.value: {
            enums.ExchangeConstantsMarketStatusColumns.LIMITS_AMOUNT.value: {
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_AMOUNT_MIN.value:
                0.5,
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_AMOUNT_MAX.value:
                100,
            },
            enums.ExchangeConstantsMarketStatusColumns.LIMITS_COST.value: {
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_COST_MIN.value:
                None,
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_COST_MAX.value:
                None
            },
            enums.ExchangeConstantsMarketStatusColumns.LIMITS_PRICE.value: {
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_PRICE_MIN.value:
                0.5,
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_PRICE_MAX.value:
                50
            },
        }
    }
    min_quantity, max_quantity, min_cost, max_cost, min_price, max_price = personal_data.get_min_max_amounts(
        symbol_market)
    assert min_quantity == 0.5
    assert max_quantity == 100
    assert min_cost is None
    assert max_cost is None
    assert min_price == 0.5
    assert max_price == 50

    # missing all values
    min_quantity, max_quantity, min_cost, max_cost, min_price, max_price = personal_data.get_min_max_amounts(
        {})
    assert min_quantity is None
    assert max_quantity is None
    assert min_cost is None
    assert max_cost is None
    assert min_price is None
    assert max_price is None

    # missing all values: asign default
    min_quantity, max_quantity, min_cost, max_cost, min_price, max_price = personal_data.get_min_max_amounts(
        {}, "xyz")
    assert min_quantity == "xyz"
    assert max_quantity == "xyz"
    assert min_cost == "xyz"
    assert max_cost == "xyz"
    assert min_price == "xyz"
    assert max_price == "xyz"

    # missing values: assign default

    symbol_market = {
        enums.ExchangeConstantsMarketStatusColumns.LIMITS.value: {
            enums.ExchangeConstantsMarketStatusColumns.LIMITS_AMOUNT.value: {
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_AMOUNT_MIN.value:
                0.5,
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_AMOUNT_MAX.value:
                100,
            },
            enums.ExchangeConstantsMarketStatusColumns.LIMITS_COST.value: {
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_COST_MIN.value:
                None,
                enums.ExchangeConstantsMarketStatusColumns.LIMITS_COST_MAX.value:
                None
            }
        }
    }
    min_quantity, max_quantity, min_cost, max_cost, min_price, max_price = personal_data.get_min_max_amounts(
        symbol_market, "xyz")
    assert min_quantity == 0.5
    assert max_quantity == 100
    assert min_cost == "xyz"  # None is not a valid value => assign default
    assert max_cost == "xyz"  # None is not a valid value => assign default
    assert min_price == "xyz"
    assert max_price == "xyz"