Beispiel #1
0
def size_to_qty(position_size: float,
                entry_price: float,
                precision: int = 8,
                fee_rate: float = 0) -> float:
    """
    converts position-size to quantity
    example: requesting $100 at the entry_price of %50 would return 2

    :param position_size: float
    :param entry_price: float
    :param precision: int
    :param fee_rate:
    :return: float
    """
    if math.isnan(position_size) or math.isnan(entry_price):
        raise TypeError()

    if fee_rate != 0:
        position_size = position_size * (1 - fee_rate * 3)

    return jh.round_decimals_down(position_size / entry_price, precision)
Beispiel #2
0
def test_round_decimals_down():
    assert jh.round_decimals_down(100.329, 2) == 100.32