def crypto_js_spot() -> pd.DataFrame: """ 主流加密货币的实时行情数据, 一次请求返回具体某一时刻行情数据 https://datacenter.jin10.com/reportType/dc_bitcoin_current :return: pandas.DataFrame """ bit_payload = bitcoin_payload.copy() bit_payload.update({"_": int(time.time() * 1000)}) bit_payload.update({"_": int(time.time() * 1000)}) r = requests.get(bitcoin_url, params=bit_payload, headers=bitcoin_headers) data_json = r.json() data_df = pd.DataFrame(data_json["data"]) data_df['reported_at'] = pd.to_datetime(data_df['reported_at']) data_df.columns = [ '市场', '交易品种', '最近报价', '涨跌额', '涨跌幅', '24小时最高', '24小时最低', '24小时成交量', '更新时间', ] data_df['最近报价'] = pd.to_numeric(data_df['最近报价']) data_df['涨跌额'] = pd.to_numeric(data_df['涨跌额']) data_df['涨跌幅'] = pd.to_numeric(data_df['涨跌幅']) data_df['24小时最高'] = pd.to_numeric(data_df['24小时最高']) data_df['24小时最低'] = pd.to_numeric(data_df['24小时最低']) data_df['24小时成交量'] = pd.to_numeric(data_df['24小时成交量']) data_df['更新时间'] = data_df['更新时间'].astype(str) return data_df
def get_js_dc_current() -> pd.DataFrame: """ 主流数字货币的实时行情数据, 一次请求返回具体某一时刻行情数据 https://datacenter.jin10.com/reportType/dc_bitcoin_current :return: pandas.DataFrame """ bit_payload = bitcoin_payload.copy() bit_payload.update({"_": int(time.time() * 1000)}) bit_payload.update({"_": int(time.time() * 1000)}) r = requests.get(bitcoin_url, params=bit_payload, headers=bitcoin_headers) data_json = r.json() data_df = pd.DataFrame(data_json["data"]) data_df.set_index("reported_at", drop=True, inplace=True) data_df.index = pd.to_datetime(data_df.index) return data_df
def get_js_dc_current(): """ 主流数字货币的实时行情数据, 一次请求返回具体某一时刻行情数据 :return: pandas.DataFrame """ bit_payload = bitcoin_payload.copy() bit_payload.update({"_": int(time.time() * 1000)}) bit_payload.update({ "jsonpCallback": bitcoin_payload["jsonpCallback"].format(int(time.time() * 1000)) }) res = requests.get(bitcoin_url, params=bit_payload) json_data = json.loads(res.text[res.text.find("{"):res.text.rfind("}") + 1]) data_df = pd.DataFrame(json_data["data"]) data_df.set_index("update", drop=True, inplace=True) data_df.index = pd.to_datetime(data_df.index) return data_df.iloc[:, :-4]