def test_to_json(self):
     s = TradeStrategy(buy_trigger="hi::>::10.0",
                       sell_trigger="lo::<::11.0",
                       stop_trigger="lo::<::11.0",
                       quantity=10)
     t = Trade(symbol="mock", strategy=s, mock=True)
     self.assertIsNotNone(t.to_json())
     print(t.to_json())
     t.persist("temp")
    def test_persist_and_load_json(self):
        path = "temp/"
        s = TradeStrategy(buy_trigger="hi::>::10.0",
                          sell_trigger="lo::<::11.0",
                          stop_trigger="lo::<::11.0",
                          quantity=10)
        t = Trade(symbol="mock", strategy=s, mock=True)
        t.persist(path=path)

        refreshed = t.refresh()
        self.assertIsNotNone(refreshed)
        self.assertEqual(refreshed.strategy.buy_trigger, s.buy_trigger)
        self.assertEqual(refreshed.strategy.sell_trigger, s.sell_trigger)
        self.assertEqual(refreshed.strategy.stop_trigger, s.stop_trigger)
    def test_persist_and_load_json_different_file(self):
        path = "temp/"
        path_refresh = "resources/sample_trade_2.json"
        s = TradeStrategy(buy_trigger="hi::>::10.0",
                          sell_trigger="lo::<::11.0",
                          stop_trigger="lo::<::11.0",
                          quantity=10)
        t = Trade(symbol="mock", strategy=s, mock=True)
        t.persist(path=path)

        refreshed = t.refresh(path=path_refresh)
        self.assertIsNotNone(refreshed)
        self.assertEqual(refreshed.strategy.buy_trigger, "price::>::99.0")
        self.assertEqual(refreshed.strategy.sell_trigger, "price::<::999.0")
        self.assertEqual(refreshed.strategy.stop_trigger, "price::>::555.0")