@@ -646,6 +646,8 @@ def stabilize_decision_with_structure(
646646 _first_list_value (trend_dict .get ("resistance_levels" )),
647647 )
648648 flow_bias = _capital_flow_bias (fundamental_context )
649+ if flow_bias == "unavailable" :
650+ return
649651 decision_type = infer_decision_type_from_advice (
650652 getattr (result , "decision_type" , "" ),
651653 default = getattr (result , "decision_type" , "hold" ) or "hold" ,
@@ -808,24 +810,32 @@ def _first_numeric_value(*values: Any) -> Optional[float]:
808810
809811def _capital_flow_bias (fundamental_context : Optional [Dict [str , Any ]]) -> str :
810812 if not isinstance (fundamental_context , dict ):
811- return "neutral "
813+ return "unavailable "
812814 block = fundamental_context .get ("capital_flow" )
813815 if not isinstance (block , dict ):
814- return "neutral"
816+ return "unavailable"
817+ if block .get ("status" ) == "not_supported" :
818+ return "unavailable"
815819 data = block .get ("data" ) if isinstance (block .get ("data" ), dict ) else block
816820 stock_flow = data .get ("stock_flow" ) if isinstance (data , dict ) else None
817- if not isinstance (stock_flow , dict ):
818- return "neutral "
821+ if not isinstance (stock_flow , dict ) or not stock_flow :
822+ return "unavailable "
819823
820824 def _flow_direction (value : Optional [float ]) -> Optional [str ]:
821825 if value is None or value == 0 :
822826 return None
823827 return "inflow" if value > 0 else "outflow"
824828
829+ numeric_values = [
830+ _coerce_numeric_value (stock_flow .get ("main_net_inflow" )),
831+ _coerce_numeric_value (stock_flow .get ("inflow_5d" )),
832+ _coerce_numeric_value (stock_flow .get ("inflow_10d" )),
833+ ]
834+ if all (value is None for value in numeric_values ):
835+ return "unavailable"
836+
825837 ordered_signals = [
826- _flow_direction (_coerce_numeric_value (stock_flow .get ("main_net_inflow" ))),
827- _flow_direction (_coerce_numeric_value (stock_flow .get ("inflow_5d" ))),
828- _flow_direction (_coerce_numeric_value (stock_flow .get ("inflow_10d" ))),
838+ _flow_direction (value ) for value in numeric_values
829839 ]
830840 directions = {signal for signal in ordered_signals if signal is not None }
831841 if not directions or len (directions ) > 1 :
0 commit comments