@@ -235,18 +235,22 @@ def serialize_local(
235235 ownership_percentage = ratios ["ownership_percent" ]
236236
237237 share_change = changes ["shares" ]
238- share_action = share_change ["action" ]
239- share_amount = share_change ["amount" ]
240- share_bought = abs (share_amount ) if share_action == "buy" else "N/A"
241- share_sold = abs (share_amount ) if share_action == "sell" else "N/A"
238+ share_action = share_change .get ("action" , "N/A" )
239+ share_amount = share_change .get ("amount" , None )
240+ share_bought = (
241+ abs (share_amount ) if share_action == "buy" and share_amount else "N/A"
242+ )
243+ share_sold = abs (share_amount ) if share_action == "sell" and share_amount else "N/A"
242244 share_bought_str = f"{ int (share_bought ):,} " if share_bought != "N/A" else "N/A"
243245 share_sold_str = f"{ int (share_sold ):,} " if share_sold != "N/A" else "N/A"
244246
245247 value_change = changes ["value" ]
246- value_action = value_change ["action" ]
247- value_amount = value_change ["amount" ]
248- value_bought = abs (value_amount ) if value_action == "buy" else "N/A"
249- value_sold = abs (value_amount ) if value_action == "sell" else "N/A"
248+ value_action = value_change .get ("action" , "N/A" )
249+ value_amount = value_change .get ("amount" , None )
250+ value_bought = (
251+ abs (value_amount ) if value_action == "buy" and value_amount else "N/A"
252+ )
253+ value_sold = abs (value_amount ) if value_action == "sell" and value_amount else "N/A"
250254 value_bought_str = f"${ int (value_bought ):,} " if value_bought != "N/A" else "N/A"
251255 value_sold_str = f"${ int (value_sold ):,} " if value_sold != "N/A" else "N/A"
252256
0 commit comments