예제 #1
0
def test_get_stop_loss_strategy_string(trader: Trader):
    """
    Test trader sell long functionality.
    :param trader: Trader object.
    """
    trader.lossStrategy = STOP
    assert trader.get_stop_loss_strategy_string() == "Stop Loss"

    trader.lossStrategy = TRAILING
    assert trader.get_stop_loss_strategy_string() == "Trailing Loss"

    trader.lossStrategy = None
    assert trader.get_stop_loss_strategy_string() == "None"
예제 #2
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