Skip to content

Commit 3e24d07

Browse files
committed
add moar logs
1 parent 976917c commit 3e24d07

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

scraper_service/shovel_tao_price/cmc_client.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@ def fetch_cmc_data(params, endpoint):
1818
return response.json(), response.status_code
1919

2020
def get_price_by_time(timestamp):
21-
21+
logging.info(f"Getting price for timestamp {timestamp}")
2222

2323
# Calculate the time 48 hours ago from now
2424
time_48_hours_ago = datetime.now() - timedelta(hours=48)
25+
logging.info(f"48 hours ago: {time_48_hours_ago}")
2526

2627
# 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:
2832
interval = '5m'
33+
logging.info("Using 5m interval (within last 48 hours)")
2934
else:
3035
interval = '24h'
36+
logging.info("Using 24h interval (older than 48 hours)")
3137

3238
parameters = {
3339
'id': CMC_TAO_ID,
@@ -36,22 +42,29 @@ def get_price_by_time(timestamp):
3642
'time_start': timestamp,
3743
'count': 1
3844
}
45+
logging.info(f"Request parameters: {parameters}")
3946

4047
try:
48+
logging.info("Fetching data from CMC API...")
4149
data, status_code = fetch_cmc_data(parameters, 'historical')
50+
logging.info(f"Got response with status code: {status_code}")
4251
except Exception as e:
4352
logging.error("Error fetching CMC data: %s", str(e))
53+
logging.error("Full exception:", exc_info=True)
4454
return None
4555

4656
if status_code == 200 and 'data' in data and 'quotes' in data['data']:
57+
logging.info("Successfully parsed response data")
4758
quote = data['data']['quotes'][0]
4859
usd_quote = quote['quote']['USD']
4960
price = usd_quote['price']
5061
market_cap = usd_quote['market_cap']
5162
volume = usd_quote['volume_24h']
63+
logging.info(f"Returning price={price}, market_cap={market_cap}, volume={volume}")
5264
return price, market_cap, volume
5365
else:
5466
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}")
5568
return None
5669

5770
def get_latest_price():

scraper_service/shovel_tao_price/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from tenacity import retry, wait_fixed
1212

1313
BLOCKS_A_DAY = (24 * 60 * 60) / 12
14-
BLOCKS_IN_36_S = 36/12
14+
FETCH_EVERY_N_BLOCKS = (60 * 5) / 12;
1515

16-
# After this block change the interval from daily to every 36s
16+
# After this block change the interval from daily to every 5 mins
1717
THRESHOLD_BLOCK = 4249779
1818

1919
logging.basicConfig(level=logging.INFO,
@@ -31,7 +31,7 @@ def process_block(self, n):
3131
# enough to handle conditions
3232
if n > THRESHOLD_BLOCK:
3333
logging.info("1")
34-
if n % BLOCKS_IN_36_S != 0:
34+
if n % FETCH_EVERY_N_BLOCKS != 0:
3535
logging.info("2")
3636
return
3737
else:

0 commit comments

Comments
 (0)