File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -147,3 +147,28 @@ def get_position_pnl(self, symbol: str) -> Decimal:
147147 position_cost = self .positions .get (symbol , Decimal ("0" )) * avg_price
148148 return current_value - position_cost
149149
150+ def get_trading_summary (self ) -> Dict :
151+ """Generate summary of trading activity."""
152+ total_trades = len (self .trades_history )
153+ if total_trades == 0 :
154+ return {
155+ "total_trades" : 0 ,
156+ "profitable_trades" : 0 ,
157+ "total_profit_loss" : Decimal ("0" )
158+ }
159+
160+ profitable_trades = 0
161+ total_pnl = Decimal ("0" )
162+
163+ for trade in self .trades_history :
164+ if trade ["side" ] == "sell" :
165+ profit = trade ["revenue" ] - trade ["price" ] * trade ["volume" ]
166+ if profit > 0 :
167+ profitable_trades += 1
168+ total_pnl += profit
169+
170+ return {
171+ "total_trades" : total_trades ,
172+ "profitable_trades" : profitable_trades ,
173+ "total_profit_loss" : total_pnl
174+ }
You can’t perform that action at this time.
0 commit comments