@@ -1656,6 +1656,12 @@ def _analyze_opportunities_crypto(opportunities: list):
16561656 crypto_data = _fetch_crypto_prices ()
16571657 if crypto_data :
16581658 _set_cached ("crypto_prices" , crypto_data )
1659+
1660+ if not crypto_data :
1661+ logger .warning ("_analyze_opportunities_crypto: No crypto data available" )
1662+ return
1663+
1664+ logger .debug (f"_analyze_opportunities_crypto: Analyzing { len (crypto_data )} crypto coins" )
16591665
16601666 for coin in (crypto_data or [])[:20 ]:
16611667 change = _safe_float (coin .get ("change_24h" , 0 ))
@@ -1669,12 +1675,13 @@ def _analyze_opportunities_crypto(opportunities: list):
16691675 reason = ""
16701676 impact = "neutral"
16711677
1678+ # Lower thresholds to show more opportunities
16721679 if change > 15 :
16731680 signal = "overbought"
16741681 strength = "strong"
16751682 reason = f"24h涨幅{ change :.1f} %,7日涨幅{ change_7d :.1f} %,短期超买风险"
16761683 impact = "bearish"
1677- elif change > 8 :
1684+ elif change > 5 : # Lowered from 8 to 5
16781685 signal = "bullish_momentum"
16791686 strength = "medium"
16801687 reason = f"24h涨幅{ change :.1f} %,上涨动能强劲"
@@ -1684,7 +1691,7 @@ def _analyze_opportunities_crypto(opportunities: list):
16841691 strength = "strong"
16851692 reason = f"24h跌幅{ abs (change ):.1f} %,可能超卖反弹"
16861693 impact = "bullish"
1687- elif change < - 8 :
1694+ elif change < - 5 : # Lowered from -8 to -5
16881695 signal = "bearish_momentum"
16891696 strength = "medium"
16901697 reason = f"24h跌幅{ abs (change ):.1f} %,下跌趋势明显"
@@ -1713,6 +1720,12 @@ def _analyze_opportunities_stocks(opportunities: list):
17131720 stock_data = _fetch_stock_opportunity_prices ()
17141721 if stock_data :
17151722 _set_cached ("stock_opportunity_prices" , stock_data , 3600 )
1723+
1724+ if not stock_data :
1725+ logger .warning ("_analyze_opportunities_stocks: No stock data available" )
1726+ return
1727+
1728+ logger .debug (f"_analyze_opportunities_stocks: Analyzing { len (stock_data )} stocks" )
17161729
17171730 for stock in (stock_data or []):
17181731 change = _safe_float (stock .get ("change" , 0 ))
@@ -1731,7 +1744,7 @@ def _analyze_opportunities_stocks(opportunities: list):
17311744 strength = "strong"
17321745 reason = f"日涨幅{ change :.1f} %,短期涨幅较大,注意回调风险"
17331746 impact = "bearish"
1734- elif change > 3 :
1747+ elif change > 2 : # Lowered from 3 to 2
17351748 signal = "bullish_momentum"
17361749 strength = "medium"
17371750 reason = f"日涨幅{ change :.1f} %,上涨动能强劲"
@@ -1741,7 +1754,7 @@ def _analyze_opportunities_stocks(opportunities: list):
17411754 strength = "strong"
17421755 reason = f"日跌幅{ abs (change ):.1f} %,可能超卖反弹"
17431756 impact = "bullish"
1744- elif change < - 3 :
1757+ elif change < - 2 : # Lowered from -3 to -2
17451758 signal = "bearish_momentum"
17461759 strength = "medium"
17471760 reason = f"日跌幅{ abs (change ):.1f} %,下跌趋势明显"
@@ -1769,6 +1782,12 @@ def _analyze_opportunities_forex(opportunities: list):
17691782 forex_data = _fetch_forex_pairs ()
17701783 if forex_data :
17711784 _set_cached ("forex_pairs" , forex_data , 3600 )
1785+
1786+ if not forex_data :
1787+ logger .warning ("_analyze_opportunities_forex: No forex data available" )
1788+ return
1789+
1790+ logger .debug (f"_analyze_opportunities_forex: Analyzing { len (forex_data )} forex pairs" )
17721791
17731792 for pair in (forex_data or []):
17741793 change = _safe_float (pair .get ("change" , 0 ))
@@ -1787,7 +1806,7 @@ def _analyze_opportunities_forex(opportunities: list):
17871806 strength = "strong"
17881807 reason = f"日涨幅{ change :.2f} %,汇率波动剧烈,注意回调"
17891808 impact = "bearish"
1790- elif change > 0.8 :
1809+ elif change > 0.5 : # Lowered from 0.8 to 0.5
17911810 signal = "bullish_momentum"
17921811 strength = "medium"
17931812 reason = f"日涨幅{ change :.2f} %,上涨动能较强"
@@ -1797,7 +1816,7 @@ def _analyze_opportunities_forex(opportunities: list):
17971816 strength = "strong"
17981817 reason = f"日跌幅{ abs (change ):.2f} %,汇率波动剧烈,可能反弹"
17991818 impact = "bullish"
1800- elif change < - 0.8 :
1819+ elif change < - 0.5 : # Lowered from -0.8 to -0.5
18011820 signal = "bearish_momentum"
18021821 strength = "medium"
18031822 reason = f"日跌幅{ abs (change ):.2f} %,下跌趋势明显"
@@ -1836,17 +1855,34 @@ def trading_opportunities():
18361855 opportunities = []
18371856
18381857 # 1) Crypto
1839- _analyze_opportunities_crypto (opportunities )
1858+ try :
1859+ _analyze_opportunities_crypto (opportunities )
1860+ crypto_count = len ([o for o in opportunities if o .get ("market" ) == "Crypto" ])
1861+ logger .info (f"Trading opportunities: found { crypto_count } crypto opportunities" )
1862+ except Exception as e :
1863+ logger .error (f"Failed to analyze crypto opportunities: { e } " , exc_info = True )
18401864
18411865 # 2) US Stocks
1842- _analyze_opportunities_stocks (opportunities )
1866+ try :
1867+ _analyze_opportunities_stocks (opportunities )
1868+ stock_count = len ([o for o in opportunities if o .get ("market" ) == "USStock" ])
1869+ logger .info (f"Trading opportunities: found { stock_count } US stock opportunities" )
1870+ except Exception as e :
1871+ logger .error (f"Failed to analyze stock opportunities: { e } " , exc_info = True )
18431872
18441873 # 3) Forex
1845- _analyze_opportunities_forex (opportunities )
1874+ try :
1875+ _analyze_opportunities_forex (opportunities )
1876+ forex_count = len ([o for o in opportunities if o .get ("market" ) == "Forex" ])
1877+ logger .info (f"Trading opportunities: found { forex_count } forex opportunities" )
1878+ except Exception as e :
1879+ logger .error (f"Failed to analyze forex opportunities: { e } " , exc_info = True )
18461880
18471881 # Sort by absolute change descending
18481882 opportunities .sort (key = lambda x : abs (x .get ("change_24h" , 0 )), reverse = True )
18491883
1884+ logger .info (f"Trading opportunities: total { len (opportunities )} opportunities found (Crypto: { len ([o for o in opportunities if o .get ('market' ) == 'Crypto' ])} , USStock: { len ([o for o in opportunities if o .get ('market' ) == 'USStock' ])} , Forex: { len ([o for o in opportunities if o .get ('market' ) == 'Forex' ])} )" )
1885+
18501886 _set_cached ("trading_opportunities" , opportunities , 3600 )
18511887
18521888 return jsonify ({"code" : 1 , "msg" : "success" , "data" : opportunities })
0 commit comments