KarlQuant commited on
Commit
cf552b8
Β·
verified Β·
1 Parent(s): fb0e510

Upload Quasar_axrvi_ranker.py

Browse files
Files changed (1) hide show
  1. Quasar_axrvi_ranker.py +13 -4
Quasar_axrvi_ranker.py CHANGED
@@ -2953,11 +2953,14 @@ class PositionManager:
2953
  else:
2954
  ref = trade.entry_tick or trade.entry_price
2955
  mult = ASSET_MULTIPLIER.get(trade.asset, 20)
2956
- stk = trade.quantity * ref # quantity = stake/price β†’ quantity*price = stake
 
 
 
2957
  if ref > 0 and exit_price > 0:
2958
  pct_move = (exit_price - ref) / ref
2959
  sign = 1.0 if trade.direction == TradeDirection.LONG else -1.0
2960
- profit = sign * pct_move * stk * mult - fees
2961
  else:
2962
  profit = -fees # can't compute β€” assume no P&L beyond fees
2963
  return self.close_trade_from_broker(
@@ -3939,7 +3942,10 @@ class QuasarAXRVIBridge:
3939
  # Log live profit for monitoring (this is the REAL P&L)
3940
  if raw_profit is not None:
3941
  logger.debug(f"[{trade.asset}] Live profit: {float(raw_profit):+.4f}")
3942
-
 
 
 
3943
  # ── Terminal state check ──────────────────────────────────────────────
3944
  is_terminal = (
3945
  poc.get("is_expired", False)
@@ -4291,7 +4297,10 @@ class QuasarAXRVIBridge:
4291
  f"Contract may expire naturally on Deriv side."
4292
  )
4293
 
4294
- fees = exit_price * self.trade_config.commission_rate
 
 
 
4295
  trade = self.position_mgr.close_trade(trade_id, exit_price, fees)
4296
  if not trade:
4297
  return
 
2953
  else:
2954
  ref = trade.entry_tick or trade.entry_price
2955
  mult = ASSET_MULTIPLIER.get(trade.asset, 20)
2956
+ # βœ… FIX 3: Use actual stake paid to broker, not quantity*ref.
2957
+ # quantity is near-zero for Kelly-sized trades β†’ quantity*ref β‰ˆ 0,
2958
+ # collapsing the profit term and leaving only fees as the PnL.
2959
+ stake = trade.buy_price if (trade.buy_price and trade.buy_price > 0) else 1.0
2960
  if ref > 0 and exit_price > 0:
2961
  pct_move = (exit_price - ref) / ref
2962
  sign = 1.0 if trade.direction == TradeDirection.LONG else -1.0
2963
+ profit = sign * pct_move * stake * mult - fees
2964
  else:
2965
  profit = -fees # can't compute β€” assume no P&L beyond fees
2966
  return self.close_trade_from_broker(
 
3942
  # Log live profit for monitoring (this is the REAL P&L)
3943
  if raw_profit is not None:
3944
  logger.debug(f"[{trade.asset}] Live profit: {float(raw_profit):+.4f}")
3945
+ # βœ… FIX 1: Cache live broker profit so rotation closes use the real P&L.
3946
+ # trade.profit stays None only if Deriv never sent a profit field at all.
3947
+ trade.profit = float(raw_profit)
3948
+
3949
  # ── Terminal state check ──────────────────────────────────────────────
3950
  is_terminal = (
3951
  poc.get("is_expired", False)
 
4297
  f"Contract may expire naturally on Deriv side."
4298
  )
4299
 
4300
+ # βœ… FIX 2: Fees must be on stake, not spot price.
4301
+ # Was: exit_price * commission_rate β†’ e.g. 316738 * 0.001 = $316.74 (wrong!)
4302
+ # Now: stake * commission_rate β†’ e.g. 1.0 * 0.001 = $0.001 (correct)
4303
+ fees = self.trade_config.amount * self.trade_config.commission_rate
4304
  trade = self.position_mgr.close_trade(trade_id, exit_price, fees)
4305
  if not trade:
4306
  return