Пример #1
0
def test_get_stop_loss(trader: Trader):
    """
    Test trader get stop loss functionality.
    :param trader: Trader object.
    """
    trader.lossStrategy = STOP
    trader.lossPercentageDecimal = 0.1
    trader.currentPrice = 5

    trader.currentPosition = LONG
    trader.buyLongPrice = 10
    assert trader.get_stop_loss() == 10 * (1 - trader.lossPercentageDecimal)

    trader.currentPosition = SHORT
    trader.sellShortPrice = 10
    assert trader.get_stop_loss() == 10 * (1 + trader.lossPercentageDecimal)

    trader.currentPosition = None
    assert trader.get_stop_loss() is None
Пример #2
0
def test_get_take_profit(trader: Trader):
    """
    Test trader get take profit functionality.
    """
    trader.takeProfitType = STOP
    trader.takeProfitPercentageDecimal = 0.05

    trader.currentPosition = LONG
    trader.buyLongPrice = 10
    assert trader.get_take_profit() == 10 * (1 + 0.05)

    trader.currentPosition = SHORT
    trader.sellShortPrice = 10
    assert trader.get_take_profit() == 10 * (1 - 0.05)

    trader.takeProfitType = None
    assert trader.get_take_profit() is None

    trader.takeProfitType = 5
    with pytest.raises(ValueError, match="Invalid type of take profit type provided."):
        trader.get_take_profit()