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]
Exemple #2
0
def scrap_index(indexGroup: IndexGroup, index_storage: IndexStorage):
    date = index_storage.date

    if sameDay(date, datetime.now()):
        date = date - relativedelta(days=1)

    index_price_today = get_latest_price(index_storage, date)

    index_price_6month = get_historical_price(index_storage,
                                              (date - relativedelta(months=6)))

    index_price_1year = get_historical_price(index_storage,
                                             (date - relativedelta(months=12)))

    indexGroup.history = History(index_price_today, index_price_6month,
                                 index_price_1year)

    indexGroup.monthClosings = get_month_closings(index_storage)
Exemple #3
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