Skip to content

Commit 48b195a

Browse files
committed
fix tao price shovel
1 parent 3ea6331 commit 48b195a

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

scraper_service/shovel_tao_price/cmc_client.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import requests
22
import logging
33
import os
4-
from datetime import datetime
4+
from datetime import datetime, timedelta
55

66
CMC_TAO_ID = 22974
77
CMC_TOKEN = os.getenv("CMC_TOKEN")
@@ -18,15 +18,30 @@ def fetch_cmc_data(params, endpoint):
1818
return response.json(), response.status_code
1919

2020
def get_price_by_time(timestamp):
21+
22+
23+
# Calculate the time 48 hours ago from now
24+
time_48_hours_ago = datetime.now() - timedelta(hours=48)
25+
26+
# Determine the interval based on the timestamp
27+
if datetime.fromtimestamp(timestamp) > time_48_hours_ago:
28+
interval = '5m'
29+
else:
30+
interval = '24h'
31+
2132
parameters = {
2233
'id': CMC_TAO_ID,
2334
'convert': 'USD',
24-
'interval': '24h',
35+
'interval': interval,
2536
'time_start': timestamp,
2637
'count': 1
2738
}
2839

29-
data, status_code = fetch_cmc_data(parameters, 'historical')
40+
try:
41+
data, status_code = fetch_cmc_data(parameters, 'historical')
42+
except Exception as e:
43+
logging.error("Error fetching CMC data: %s", str(e))
44+
return None
3045

3146
if status_code == 200 and 'data' in data and 'quotes' in data['data']:
3247
quote = data['data']['quotes'][0]

0 commit comments

Comments
 (0)