Esempio n. 1
0
    def test_get_trend(self):
        self.assertEqual(self.trader.get_trend(), None)

        bullish_strategy1 = Strategy(name='b1', parent=None)
        bullish_strategy1.trend = BULLISH

        self.trader.strategies['b1'] = bullish_strategy1
        self.assertEqual(self.trader.get_trend(), BULLISH)

        bullish_strategy2 = Strategy(name='b2', parent=None)
        bullish_strategy2.trend = BULLISH

        self.trader.strategies['b2'] = bullish_strategy2
        self.assertEqual(self.trader.get_trend(), BULLISH)

        bearish_strategy = Strategy(name='b3', parent=None)
        bearish_strategy.trend = BEARISH

        self.trader.strategies['b3'] = bearish_strategy
        self.assertEqual(self.trader.get_trend(), None)

        for strategy in self.trader.strategies:
            self.trader.strategies[strategy].trend = BEARISH

        self.assertEqual(self.trader.get_trend(), BEARISH)
Esempio n. 2
0
def test_get_trend(trader: Trader):
    """
    Test trader get trend functionality.
    :param trader: Trader object.
    """
    assert trader.get_trend() is None

    bullish_strategy1 = Strategy(name='b1', parent=None)
    bullish_strategy1.trend = BULLISH

    trader.strategies['b1'] = bullish_strategy1
    assert trader.get_trend() == BULLISH

    bullish_strategy2 = Strategy(name='b2', parent=None)
    bullish_strategy2.trend = BULLISH

    trader.strategies['b2'] = bullish_strategy2
    assert trader.get_trend() == BULLISH

    bearish_strategy = Strategy(name='b3', parent=None)
    bearish_strategy.trend = BEARISH

    trader.strategies['b3'] = bearish_strategy
    assert trader.get_trend() is None

    for strategy in trader.strategies.values():
        strategy.trend = BEARISH

    assert trader.get_trend() == BEARISH