@@ -18,16 +18,22 @@ def fetch_cmc_data(params, endpoint):
18
18
return response .json (), response .status_code
19
19
20
20
def get_price_by_time (timestamp ):
21
-
21
+ logging . info ( f"Getting price for timestamp { timestamp } " )
22
22
23
23
# Calculate the time 48 hours ago from now
24
24
time_48_hours_ago = datetime .now () - timedelta (hours = 48 )
25
+ logging .info (f"48 hours ago: { time_48_hours_ago } " )
25
26
26
27
# Determine the interval based on the timestamp
27
- if datetime .fromtimestamp (timestamp ) > time_48_hours_ago :
28
+ timestamp_dt = datetime .fromtimestamp (timestamp )
29
+ logging .info (f"Timestamp as datetime: { timestamp_dt } " )
30
+
31
+ if timestamp_dt > time_48_hours_ago :
28
32
interval = '5m'
33
+ logging .info ("Using 5m interval (within last 48 hours)" )
29
34
else :
30
35
interval = '24h'
36
+ logging .info ("Using 24h interval (older than 48 hours)" )
31
37
32
38
parameters = {
33
39
'id' : CMC_TAO_ID ,
@@ -36,22 +42,29 @@ def get_price_by_time(timestamp):
36
42
'time_start' : timestamp ,
37
43
'count' : 1
38
44
}
45
+ logging .info (f"Request parameters: { parameters } " )
39
46
40
47
try :
48
+ logging .info ("Fetching data from CMC API..." )
41
49
data , status_code = fetch_cmc_data (parameters , 'historical' )
50
+ logging .info (f"Got response with status code: { status_code } " )
42
51
except Exception as e :
43
52
logging .error ("Error fetching CMC data: %s" , str (e ))
53
+ logging .error ("Full exception:" , exc_info = True )
44
54
return None
45
55
46
56
if status_code == 200 and 'data' in data and 'quotes' in data ['data' ]:
57
+ logging .info ("Successfully parsed response data" )
47
58
quote = data ['data' ]['quotes' ][0 ]
48
59
usd_quote = quote ['quote' ]['USD' ]
49
60
price = usd_quote ['price' ]
50
61
market_cap = usd_quote ['market_cap' ]
51
62
volume = usd_quote ['volume_24h' ]
63
+ logging .info (f"Returning price={ price } , market_cap={ market_cap } , volume={ volume } " )
52
64
return price , market_cap , volume
53
65
else :
54
66
logging .error ("Failed to fetch TAO price with parameters %s: %s" , parameters , data .get ('status' , {}).get ('error_message' , 'Unknown error' ))
67
+ logging .error (f"Full response data: { data } " )
55
68
return None
56
69
57
70
def get_latest_price ():
0 commit comments