File size: 2,224 Bytes
1184c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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)