@@ -120,15 +120,39 @@ async def __call__(self) -> str:
120120 self .session .commit ()
121121
122122 # Format response with basic statistics only
123- formatted_response = f"""
124- === Pendle Data Statistics ===
125- Latest TVL: { data ["Latest TVL" ]}
126- TVL 24h Change: { data ["TVL 24h Change" ]}
127- Total 7d Volume: { data ["Total 7d Volume" ]}
128- Today's Volume: { data ["Today's Volume" ]}
129- Previous Day's Volume: { data ["Previous Day's Volume" ]}
130- Statistics time: { datetime .now ().strftime ("%Y-%m-%d %H:%M" )}
131- """
123+ formatted_response = "=== Pendle Data Statistics ===\n "
124+
125+ # Helper function to extract numeric value from formatted string
126+ def extract_value (formatted_str , unit ):
127+ try :
128+ if unit in formatted_str :
129+ parts = formatted_str .split ("$" )[1 ].split (unit )[0 ]
130+ return float (parts )
131+ return 0
132+ except (IndexError , ValueError ):
133+ return 0
134+
135+ # Check each metric and only include if non-zero
136+ metrics = {
137+ "Latest TVL" : extract_value (data ["Latest TVL" ], "B" ),
138+ "TVL 24h Change" : extract_value (data ["TVL 24h Change" ], "M" ),
139+ "Total 7d Volume" : extract_value (data ["Total 7d Volume" ], "B" ),
140+ "Today's Volume" : extract_value (data ["Today's Volume" ], "M" ),
141+ "Previous Day's Volume" : extract_value (
142+ data ["Previous Day's Volume" ], "M"
143+ ),
144+ }
145+
146+ # Build response with non-zero values
147+ for key , value in metrics .items ():
148+ if (key == "TVL 24h Change" and value != 0 ) or (
149+ key != "TVL 24h Change" and value > 0
150+ ):
151+ formatted_response += f"{ key } : { data [key ]} \n "
152+
153+ formatted_response += (
154+ f"Statistics time: { datetime .now ().strftime ('%Y-%m-%d %H:%M' )} "
155+ )
132156
133157 logger .info (f"{ self .name } tool response: { formatted_response .strip ()} ." )
134158 return formatted_response .strip ()
@@ -427,3 +451,89 @@ def _parse_volume_data(self, data):
427451 self .results ["Previous Day's Volume" ] = (
428452 f"${ prev_day_volume / 1e6 :.2f} M ({ prev_day_time .strftime ('%Y-%m-%d' )} )"
429453 )
454+
455+
456+ # Add standalone test function
457+ async def test_data_tracker ():
458+ """Test the PendleDataTrackerTool functionality and print detailed metrics"""
459+ try :
460+ print ("Starting PendleDataTrackerTool test..." )
461+
462+ # Create tool instance
463+ tool = PendleDataTrackerTool ()
464+
465+ # Get data
466+ result = await tool ()
467+
468+ # Get raw data and print more detailed information
469+ tracker = PendleTracker ()
470+ data = tracker .get_pendle_data ()
471+
472+ if data :
473+ # Parse raw data
474+ print ("\n === Detailed Metrics ===" )
475+ try :
476+ tvl_value = float (data ["Latest TVL" ].split ("$" )[1 ].split ("B" )[0 ]) * 1e9
477+ tvl_change_parts = data ["TVL 24h Change" ].split ("$" )[1 ].split ("M" )[0 ]
478+ tvl_change_24h = float (tvl_change_parts ) * 1e6
479+ tvl_change_percent = float (
480+ data ["TVL 24h Change" ].split ("(" )[1 ].split ("%" )[0 ]
481+ )
482+ volume_7d = (
483+ float (data ["Total 7d Volume" ].split ("$" )[1 ].split ("B" )[0 ]) * 1e9
484+ )
485+ volume_today = (
486+ float (data ["Today's Volume" ].split ("$" )[1 ].split ("M" )[0 ]) * 1e6
487+ )
488+ volume_prev = (
489+ float (data ["Previous Day's Volume" ].split ("$" )[1 ].split ("M" )[0 ])
490+ * 1e6
491+ )
492+
493+ # Calculate additional metrics
494+ volume_change_percent = (
495+ ((volume_today - volume_prev ) / volume_prev * 100 )
496+ if volume_prev > 0
497+ else 0
498+ )
499+ tvl_direction = (
500+ "up"
501+ if tvl_change_percent > 0
502+ else "down"
503+ if tvl_change_percent < 0
504+ else "flat"
505+ )
506+ volume_direction = (
507+ "up"
508+ if volume_today > volume_prev
509+ else "down"
510+ if volume_today < volume_prev
511+ else "flat"
512+ )
513+
514+ # Print detailed metrics
515+ print (f"TVL Value: ${ tvl_value / 1e9 :.6f} B" )
516+ print (
517+ f"TVL 24h Change: ${ tvl_change_24h / 1e6 :.6f} M ({ tvl_change_percent :.6f} %) - { tvl_direction } "
518+ )
519+ print (f"7-Day Volume: ${ volume_7d / 1e9 :.6f} B" )
520+ print (f"Today's Volume: ${ volume_today / 1e6 :.6f} M" )
521+ print (f"Previous Day's Volume: ${ volume_prev / 1e6 :.6f} M" )
522+ print (
523+ f"Volume Change: { volume_change_percent :.6f} % - { volume_direction } "
524+ )
525+
526+ except Exception as e :
527+ print (f"Error parsing detailed metrics: { e } " )
528+
529+ return result
530+ except Exception as e :
531+ print (f"Error during test: { e } " )
532+ raise
533+
534+
535+ # Add main function
536+ if __name__ == "__main__" :
537+ import asyncio
538+
539+ asyncio .run (test_data_tracker ())
0 commit comments