feat: paper trading deduct taker fee 0.05% per side (0.1% round trip)
This commit is contained in:
parent
59910fe9cd
commit
47004ece8c
@ -47,6 +47,7 @@ PAPER_TIER_MULTIPLIER = { # 档位仓位倍数
|
|||||||
"standard": 1.0, # 标准: 2%
|
"standard": 1.0, # 标准: 2%
|
||||||
"heavy": 1.5, # 加仓: 3%
|
"heavy": 1.5, # 加仓: 3%
|
||||||
}
|
}
|
||||||
|
PAPER_FEE_RATE = 0.0005 # Taker手续费 0.05%(开仓+平仓各一次)
|
||||||
|
|
||||||
def load_paper_config():
|
def load_paper_config():
|
||||||
"""从配置文件加载模拟盘开关和参数"""
|
"""从配置文件加载模拟盘开关和参数"""
|
||||||
@ -522,14 +523,14 @@ def paper_check_positions(symbol: str, current_price: float, now_ms: int):
|
|||||||
with get_sync_conn() as conn:
|
with get_sync_conn() as conn:
|
||||||
with conn.cursor() as cur:
|
with conn.cursor() as cur:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"SELECT id, direction, entry_price, tp1_price, tp2_price, sl_price, tp1_hit, entry_ts "
|
"SELECT id, direction, entry_price, tp1_price, tp2_price, sl_price, tp1_hit, entry_ts, atr_at_entry "
|
||||||
"FROM paper_trades WHERE symbol=%s AND status IN ('active','tp1_hit') ORDER BY id",
|
"FROM paper_trades WHERE symbol=%s AND status IN ('active','tp1_hit') ORDER BY id",
|
||||||
(symbol,)
|
(symbol,)
|
||||||
)
|
)
|
||||||
positions = cur.fetchall()
|
positions = cur.fetchall()
|
||||||
|
|
||||||
for pos in positions:
|
for pos in positions:
|
||||||
pid, direction, entry_price, tp1, tp2, sl, tp1_hit, entry_ts = pos
|
pid, direction, entry_price, tp1, tp2, sl, tp1_hit, entry_ts, atr_entry = pos
|
||||||
closed = False
|
closed = False
|
||||||
new_status = None
|
new_status = None
|
||||||
pnl_r = 0.0
|
pnl_r = 0.0
|
||||||
@ -584,11 +585,16 @@ def paper_check_positions(symbol: str, current_price: float, now_ms: int):
|
|||||||
pnl_r = max(pnl_r, 0.5 * 1.5)
|
pnl_r = max(pnl_r, 0.5 * 1.5)
|
||||||
|
|
||||||
if closed:
|
if closed:
|
||||||
|
# 扣除手续费(开仓+平仓各Taker 0.05%)
|
||||||
|
risk_distance = 2.0 * 0.7 * atr_entry if atr_entry > 0 else 1
|
||||||
|
fee_r = (2 * PAPER_FEE_RATE * entry_price) / risk_distance if risk_distance > 0 else 0
|
||||||
|
pnl_r -= fee_r
|
||||||
|
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"UPDATE paper_trades SET status=%s, exit_price=%s, exit_ts=%s, pnl_r=%s WHERE id=%s",
|
"UPDATE paper_trades SET status=%s, exit_price=%s, exit_ts=%s, pnl_r=%s WHERE id=%s",
|
||||||
(new_status, current_price, now_ms, round(pnl_r, 4), pid)
|
(new_status, current_price, now_ms, round(pnl_r, 4), pid)
|
||||||
)
|
)
|
||||||
logger.info(f"[{symbol}] 📝 模拟平仓: {direction} @ {current_price:.2f} status={new_status} pnl={pnl_r:+.2f}R")
|
logger.info(f"[{symbol}] 📝 模拟平仓: {direction} @ {current_price:.2f} status={new_status} pnl={pnl_r:+.2f}R (fee={fee_r:.3f}R)")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user