-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallMarketPages.py
More file actions
45 lines (31 loc) · 1.02 KB
/
allMarketPages.py
File metadata and controls
45 lines (31 loc) · 1.02 KB
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
'''
from pycoingecko import CoinGeckoAPI
import time
cg = CoinGeckoAPI()
def get_all_pages(per_page=250, vs_currency='usd'):
page_num = 1
all_data = []
while True:
data = cg.get_coins_markets(vs_currency=vs_currency, per_page=per_page, page=page_num)
if not data:
break
all_data.extend(data)
page_num += 1
time.sleep(1) # Respect rate limits (e.g., 10-30 calls per minute)
return all_data
all_coins_data = get_all_pages()
print(f"Total coins fetched: {len(all_coins_data)}")
'''
import pandas as pd
import requests
import requests_cache
import json
url = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250&price_change_percentage=1h%2C24h%2C1y&precision=full"
headers = {
"accept": "application/json",
"x-cg-demo-api-key": "CG-ULEXj9kgbnAK2kGvieVgsDBL"
}
requests_cache.install_cache('demo_cache')
response = requests.get(url, headers=headers)
save_json("markets.json", response.json())
print(response.text)