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
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()
def test_get_position(trader: Trader, current_position): """ Test trader get position functionality. """ trader.currentPosition = current_position assert trader.get_position() == current_position
def test_get_position_string(trader: Trader, current_position, expected): """ Test trader get position string functionality. """ trader.currentPosition = current_position assert trader.get_position_string() == expected