Пример #1
0
def macro_cons_gold_change():
    """
    全球最大黄金ETF—SPDR Gold Trust持仓报告, 数据区间从20041118-至今
    :return: pandas.Series
    2004-11-18        0
    2004-11-19    49.76
    2004-11-22    29.24
    2004-11-23     0.00
    2004-11-24     9.33
                  ...
    2019-10-20     0.00
    2019-10-21     0.00
    2019-10-22    -4.98
    2019-10-23    -1.18
    2019-10-24     0.00
    """
    t = time.time()
    res = requests.get(
        JS_CONS_GOLD_ETF_URL.format(str(int(round(t * 1000))),
                                    str(int(round(t * 1000)) + 90)))
    json_data = json.loads(res.text[res.text.find("{"):res.text.rfind("}") +
                                    1])
    date_list = [item["date"] for item in json_data["list"]]
    value_list = [item["datas"]["黄金"] for item in json_data["list"]]
    value_df = pd.DataFrame(value_list)
    value_df.columns = json_data["kinds"]
    value_df.index = pd.to_datetime(date_list)
    temp_df = value_df["增持/减持(吨)"]
    temp_df.name = "gold_change"
    return temp_df
Пример #2
0
def macro_cons_gold_amount():
    """
    全球最大黄金ETF—SPDR Gold Trust持仓报告, 数据区间从20041118-至今
    :return: pandas.Series
    2004-11-18      114920000.00
    2004-11-19      828806907.20
    2004-11-22     1253785205.50
    2004-11-23     1254751438.19
    2004-11-24     1390568824.08
                       ...
    2019-10-20    44286078486.23
    2019-10-21    44333677232.68
    2019-10-22    43907962483.56
    2019-10-23    44120217405.82
    2019-10-24    44120217405.82
    """
    t = time.time()
    res = requests.get(
        JS_CONS_GOLD_ETF_URL.format(str(int(round(t * 1000))),
                                    str(int(round(t * 1000)) + 90)))
    json_data = json.loads(res.text[res.text.find("{"):res.text.rfind("}") +
                                    1])
    date_list = [item["date"] for item in json_data["list"]]
    value_list = [item["datas"]["黄金"] for item in json_data["list"]]
    value_df = pd.DataFrame(value_list)
    value_df.columns = json_data["kinds"]
    value_df.index = pd.to_datetime(date_list)
    temp_df = value_df["总价值(美元)"]
    temp_df.name = "gold_amount"
    return temp_df
Пример #3
0
def macro_cons_gold_volume():
    """
    全球最大黄金ETF—SPDR Gold Trust持仓报告, 数据区间从20041118-至今
    :return: pandas.Series
    2004-11-18      8.09
    2004-11-19     57.85
    2004-11-22     87.09
    2004-11-23     87.09
    2004-11-24     96.42
                   ...
    2019-10-20    924.64
    2019-10-21    924.64
    2019-10-22    919.66
    2019-10-23    918.48
    2019-10-24    918.48
    """
    t = time.time()
    res = requests.get(
        JS_CONS_GOLD_ETF_URL.format(str(int(round(t * 1000))),
                                    str(int(round(t * 1000)) + 90)))
    json_data = json.loads(res.text[res.text.find("{"):res.text.rfind("}") +
                                    1])
    date_list = [item["date"] for item in json_data["list"]]
    value_list = [item["datas"]["黄金"] for item in json_data["list"]]
    value_df = pd.DataFrame(value_list)
    value_df.columns = json_data["kinds"]
    value_df.index = pd.to_datetime(date_list)
    temp_df = value_df["总库存(吨)"]
    temp_df.name = "gold_volume"
    return temp_df
Пример #4
0
def macro_cons_gold_change():
    """
    全球最大黄金ETF—SPDR Gold Trust持仓报告, 数据区间从20041118-至今
    :return: pandas.Series
    """
    t = time.time()
    res = requests.get(
        JS_CONS_GOLD_ETF_URL.format(str(int(round(t * 1000))),
                                    str(int(round(t * 1000)) + 90)))
    json_data = json.loads(res.text[res.text.find("{"):res.text.rfind("}") +
                                    1])
    date_list = [item["date"] for item in json_data["list"]]
    value_list = [item["datas"]["黄金"] for item in json_data["list"]]
    value_df = pd.DataFrame(value_list)
    value_df.columns = json_data["kinds"]
    value_df.index = pd.to_datetime(date_list)
    temp_df = value_df["增持/减持(吨)"]
    url = "https://datacenter-api.jin10.com/reports/list_v2"
    params = {
        "max_date": "",
        "category": "etf",
        "attr_id": "1",
        "_": str(int(round(t * 1000))),
    }
    headers = {
        "accept": "*/*",
        "accept-encoding": "gzip, deflate, br",
        "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
        "cache-control": "no-cache",
        "origin": "https://datacenter.jin10.com",
        "pragma": "no-cache",
        "referer":
        "https://datacenter.jin10.com/reportType/dc_usa_michigan_consumer_sentiment",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-site",
        "user-agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
        "x-app-id": "rU6QIu7JHe2gOUeR",
        "x-csrf-token": "",
        "x-version": "1.0.0",
    }
    r = requests.get(url, params=params, headers=headers)
    temp_se = pd.DataFrame(r.json()["data"]["values"]).iloc[:, [0, 2]]
    temp_se.index = pd.to_datetime(temp_se.iloc[:, 0])
    temp_se = temp_se.iloc[:, 1]
    temp_df = temp_df.append(temp_se)
    temp_df.dropna(inplace=True)
    temp_df.sort_index(inplace=True)
    temp_df = temp_df.reset_index()
    temp_df.drop_duplicates(subset="index", keep="last", inplace=True)
    temp_df.set_index("index", inplace=True)
    temp_df = temp_df.squeeze()
    temp_df.index.name = None
    temp_df.name = "gold_change"
    temp_df = temp_df.astype(float)
    return temp_df