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")
def test_refresh_json_string(self): 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) with open(path_refresh, "r") as f: json_body = f.read() refreshed = t.refresh(json_string=json_body) 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")