KarlQuant commited on
Commit
fb0e510
·
verified ·
1 Parent(s): 44a372a

Upload Quasar_axrvi_ranker.py

Browse files
Files changed (1) hide show
  1. Quasar_axrvi_ranker.py +20 -23
Quasar_axrvi_ranker.py CHANGED
@@ -2864,8 +2864,7 @@ class PositionManager:
2864
  ) -> Optional[Trade]:
2865
  """
2866
  Called from _on_deriv_message when proposal_open_contract reports
2867
- a terminal state (is_expired, is_sold, status in won/lost/sold/expired).
2868
- Authoritative close — profit comes directly from broker.
2869
  """
2870
  with self._lock:
2871
  if trade_id not in self._open_trades:
@@ -2873,38 +2872,36 @@ class PositionManager:
2873
  trade = self._open_trades.pop(trade_id)
2874
 
2875
  exit_price = sell_price or exit_tick or (trade.current_spot or 0.0)
2876
- trade.profit = profit
2877
- trade.realized_pnl = profit # authoritative broker P&L
2878
- trade.sell_price = sell_price
2879
- trade.exit_price = exit_price
2880
- trade.exit_time = time.time()
2881
- trade.status = status
2882
- trade.state = PositionState.CLOSED
2883
- trade.fees = 0.0 # fees already reflected in broker profit
 
 
2884
 
2885
  with self._lock:
2886
  self._closed_trades.append(trade)
2887
- self.trades_closed += 1
2888
  self.total_realized_pnl += trade.realized_pnl
2889
 
2890
  if self.ranker_logger:
2891
- return_pct = (
2892
- (exit_price - trade.entry_price) / trade.entry_price
2893
- if trade.direction == TradeDirection.LONG and trade.entry_price > 0
2894
- else (trade.entry_price - exit_price) / trade.entry_price
2895
- if trade.entry_price > 0
2896
- else 0.0
2897
- )
2898
  self.ranker_logger.trade_close(
2899
- trade_id = trade_id,
2900
- asset = trade.asset,
2901
- pnl = trade.realized_pnl,
2902
- return_pct = return_pct,
2903
  )
2904
 
 
2905
  logger.info(
2906
  f"🔴 [{trade.asset}] TRADE CLOSED | trade_id={trade_id} | "
2907
- f"status={status} | profit={profit:+.4f} | "
2908
  f"contract_id={trade.contract_id}"
2909
  )
2910
  return trade
 
2864
  ) -> Optional[Trade]:
2865
  """
2866
  Called from _on_deriv_message when proposal_open_contract reports
2867
+ a terminal state. Authoritative close - profit comes directly from broker.
 
2868
  """
2869
  with self._lock:
2870
  if trade_id not in self._open_trades:
 
2872
  trade = self._open_trades.pop(trade_id)
2873
 
2874
  exit_price = sell_price or exit_tick or (trade.current_spot or 0.0)
2875
+
2876
+ # Store the REAL profit from broker
2877
+ trade.profit = profit
2878
+ trade.realized_pnl = profit # authoritative broker P&L
2879
+ trade.sell_price = sell_price
2880
+ trade.exit_price = exit_price
2881
+ trade.exit_time = time.time()
2882
+ trade.status = status
2883
+ trade.state = PositionState.CLOSED
2884
+ trade.fees = 0.0
2885
 
2886
  with self._lock:
2887
  self._closed_trades.append(trade)
2888
+ self.trades_closed += 1
2889
  self.total_realized_pnl += trade.realized_pnl
2890
 
2891
  if self.ranker_logger:
2892
+ # Use REAL profit for return calculation, not price difference
2893
+ return_pct = (profit / trade.quantity) / trade.entry_price if trade.entry_price > 0 else 0.0
 
 
 
 
 
2894
  self.ranker_logger.trade_close(
2895
+ trade_id=trade_id,
2896
+ asset=trade.asset,
2897
+ pnl=profit, # ← REAL profit!
2898
+ return_pct=return_pct,
2899
  )
2900
 
2901
+ # ✅ Log the REAL profit, not the contract value
2902
  logger.info(
2903
  f"🔴 [{trade.asset}] TRADE CLOSED | trade_id={trade_id} | "
2904
+ f"status={status} | profit={profit:+.4f} | " # ← This is the REAL P&L now
2905
  f"contract_id={trade.contract_id}"
2906
  )
2907
  return trade