leap / dataset.py
0zAND1z's picture
Initial commit
1184c84
raw
history blame
2.22 kB
import json
import requests
model_dictionary = {
"price_details": [
{
"chain": "solana",
"prices": [
{
"timestamp": 1586491596,
"price": 0.7437452104269077
},
{
"timestamp": 1618027596,
"price": 27.58404304009728
},
{
"timestamp": 1649563596,
"price": 113.54993240569314
},
{
"timestamp": 1681099596,
"price": 20.28
}
]
}
]
}
dictionary = {}
price_details = []
URL_TGE_TIMESTAMP = 'https://coins.llama.fi/prices/first/'
URL_PRICE = 'https://coins.llama.fi/prices/historical/'
COINS = ['coingecko:ethereum', 'coingecko:cosmos', 'coingecko:solana', 'coingecko:polkadot', 'coingecko:avalanche-2']
UNIX_SECONDS_52W = 31449600
YEARS = [1, 2, 3]
for COIN in COINS:
chain_details = {}
prices = []
ogpricetuple = {}
print("=====")
print(COIN)
chain_details['chain'] = COIN
tge_timestamp_res = requests.get(URL_TGE_TIMESTAMP + COIN)
tge_timestamp = json.loads(tge_timestamp_res.text)['coins'][COIN]['timestamp']
ogpricetuple['timestamp'] = tge_timestamp
tge_price_res = requests.get(URL_PRICE + str(tge_timestamp) + '/' + COIN + '?searchWidth=1h')
tge_price = json.loads(tge_price_res.text)['coins'][COIN]['price']
ogpricetuple['price'] = tge_price
prices.append(ogpricetuple)
for YEAR in YEARS:
pricetuple = {}
timestamp = tge_timestamp + YEAR * UNIX_SECONDS_52W
timestamp_price_res = requests.get(URL_PRICE + str(timestamp) + '/' + COIN + '?searchWidth=1h')
timestamp_price = json.loads(timestamp_price_res.text)['coins'][COIN]['price']
pricetuple['timestamp'] = timestamp
pricetuple['price'] = timestamp_price
prices.append(pricetuple)
chain_details['prices'] = prices
price_details.append(chain_details)
dictionary['price_details'] = price_details
print(dictionary)
with open("data.json", "w") as outfile:
json.dump(dictionary, outfile)