Exemplo n.º 1
0
    def test_index_group_to_json(self):

        # given:
        index_group = IndexGroup("isin", "index_name", "source_id", "source")
        index_group.stocks = [Stock("stock_id", "stock_name", index_group)]
        index_group.history = History(1, 2, 3)
        index_group.monthClosings = MonthClosings()
        index_group.monthClosings.closings = [0, 0, 0, 0]
Exemplo n.º 2
0
    def fromJson(self, json_str: str) -> IndexGroup:

        index_json = json.loads(json_str)

        # backward compatibilities
        isin = index_json["isin"] if "isin" in index_json else index_json["index"]
        name = index_json["name"]
        sourceID = index_json["sourceId"] if "sourceId" in index_json else name
        source = index_json["source"] if "source" in index_json else "onvista"

        indexGroup = IndexGroup(isin, name, sourceID, source)

        history = index_json["history"]
        indexGroup.history = History(history["today"], history["half_a_year"], history["one_year"])

        indexGroup.monthClosings = MonthClosings()
        indexGroup.monthClosings.closings = index_json["monthClosings"].get("closings")

        indexGroup.stocks = list(map(lambda s: Stock(s.id, s.name, indexGroup)), index_json["stocks"])

        return indexGroup