数字货币算力和价格数据研究
由think创建,最终由think 被浏览 84 用户
Overview
- 研究数字货币价格走势
- 算力变化对数字货币价格的影响
获取数字货币代码列表
- 使用 f2pool 的数据
def bigquant_run(input_1, input_2, input_3):
import requests
response = requests.post(
"https://www.f2pool.com/coins",
data={"sort_by": "output24h", "sort_type": "desc"}
)
data = response.json()
ds = DataSource.write_pickle(data)
return Outputs(data_1=ds)
获取数字货币算力和价格数据
- 这里获取过去30天的小时数据
def bigquant_run(input_1, input_2, input_3):
# date 没有实际使用,更新这个值缓存可以更新
def fetch_coin_data(currency_code, date=None):
import requests
response = requests.post(
"https://www.f2pool.com/coins-chart",
data={"currency_code": currency_code, "history_days": "30d", "interval": "60m"}
)
try:
data = response.json()
df = pd.DataFrame(data["data"]["chart_data"])
df["timestamp"] = pd.to_datetime(df['timestamp'], unit="ms")
ds = DataSource.write_df(df)
except Exception as e:
T.log.exception(e)
ds = None
return Outputs(data=ds)
coins = input_1.read()
i = 0
for coin in coins["data"]["top100"]:
i += 1
T.log.info(f'fetch {i}/{len(coins["data"]["top100"])} {coin["code"]} ..')
coin["data_ds"] = M.cached.v3(
run=fetch_coin_data,
params={"currency_code": coin["code"], "date": "2021-08-17"}
).data
data = DataSource.write_pickle(coins)
return Outputs(data_1=data)
完整代码
https://bigquant.com/experimentshare/e7911af273f144d693e5290d0accbded
\