fix: 佣金按委托级合并计费(分笔成交只收一次佣金)
- calcOrderFees 委托层合并计费:同一委托分笔成交按总金额算一次佣金(最低5元一次) - mapTrade 保留原始成交字段,不再逐笔算费 - 前端聚合调用 calcOrderFees,展开明细只展示成交本身 - 验证:200股拆两笔佣金5元(非10元);两笔独立委托各5元
This commit is contained in:
@@ -48,6 +48,23 @@ function directionText(direction) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
/** 费用计算:按整笔委托合并(同一委托分笔成交只收一次佣金,最低5元;2026-09-01 老师修正) */
|
||||
function calcOrderFeesLocal(trades, commissionRateWan) {
|
||||
const list = Array.isArray(trades) ? trades : [];
|
||||
const totalAmount = list.reduce((s, t) => s + Math.max(0, +(t.amount ?? 0)), 0);
|
||||
const direction = list[0]?.direction ?? '';
|
||||
let commission = totalAmount * (commissionRateWan / 10000);
|
||||
if (commission < 5 && commission > 0) commission = 5;
|
||||
const stampTax = direction === 'sell' ? totalAmount * 0.0005 : 0;
|
||||
const transferFee = totalAmount * 0.00001;
|
||||
return {
|
||||
commission: +commission.toFixed(4),
|
||||
stampTax: +stampTax.toFixed(4),
|
||||
transferFee: +transferFee.toFixed(4),
|
||||
total: +(commission + stampTax + transferFee).toFixed(4),
|
||||
};
|
||||
}
|
||||
|
||||
/** 合并逻辑:按 m_strOrderSysID 把成交聚合进委托 */
|
||||
function mergeOrdersAndTrades(orders, trades) {
|
||||
const tradeByOrder = new Map();
|
||||
@@ -59,24 +76,22 @@ function mergeOrdersAndTrades(orders, trades) {
|
||||
const ts = tradeByOrder.get(o.orderId) ?? [];
|
||||
const totalVol = ts.reduce((s, t) => s + t.volume, 0);
|
||||
const totalAmount = ts.reduce((s, t) => s + t.amount, 0);
|
||||
// 费用逐笔计算后聚合(每笔 commission/stampTax/transferFee 已是金额)
|
||||
const aggCommission = ts.reduce((s, t) => s + t.commission, 0);
|
||||
const aggStampTax = ts.reduce((s, t) => s + t.stampTax, 0);
|
||||
const aggTransferFee = ts.reduce((s, t) => s + t.transferFee, 0);
|
||||
const aggFeeTotal = ts.reduce((s, t) => s + t.feeTotal, 0);
|
||||
const weightedPrice = totalVol > 0
|
||||
? ts.reduce((s, t) => s + t.price * t.volume, 0) / totalVol
|
||||
: 0;
|
||||
// 费用:按整笔委托合并计算(同一委托分笔成交只收一次佣金,calcOrderFees)
|
||||
const rateWan = ts[0]?.commissionRateWan ?? 0; // 佣金费率(万分之,来自成交,账号级一致)
|
||||
const fees = calcOrderFeesLocal(ts, rateWan);
|
||||
return {
|
||||
...o,
|
||||
trades: ts,
|
||||
aggVolume: totalVol,
|
||||
aggPrice: weightedPrice,
|
||||
aggAmount: totalAmount,
|
||||
aggCommission,
|
||||
aggStampTax,
|
||||
aggTransferFee,
|
||||
aggFeeTotal,
|
||||
aggCommission: fees.commission,
|
||||
aggStampTax: fees.stampTax,
|
||||
aggTransferFee: fees.transferFee,
|
||||
aggFeeTotal: fees.total,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -288,10 +303,6 @@ function OrderRows({ order, expanded, onToggle }) {
|
||||
<th style={{ ...tdStyle, textAlign: 'right' }}>成交价</th>
|
||||
<th style={{ ...tdStyle, textAlign: 'right' }}>成交量</th>
|
||||
<th style={{ ...tdStyle, textAlign: 'right' }}>成交额</th>
|
||||
<th style={{ ...tdStyle, textAlign: 'right' }}>总费用</th>
|
||||
<th style={{ ...tdStyle, textAlign: 'right' }}>佣金</th>
|
||||
<th style={{ ...tdStyle, textAlign: 'right' }}>印花税</th>
|
||||
<th style={{ ...tdStyle, textAlign: 'right' }}>过户费</th>
|
||||
<th style={{ ...tdStyle, textAlign: 'right' }}>成交号</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -302,10 +313,6 @@ function OrderRows({ order, expanded, onToggle }) {
|
||||
<td style={{ ...tdStyle, textAlign: 'right' }}>{fmtNum(t.price)}</td>
|
||||
<td style={{ ...tdStyle, textAlign: 'right' }}>{fmtNum(t.volume, 0)}</td>
|
||||
<td style={{ ...tdStyle, textAlign: 'right' }}>{fmtNum(t.amount)}</td>
|
||||
<td style={{ ...tdStyle, textAlign: 'right' }}>{fmtNum(t.feeTotal, 2)}</td>
|
||||
<td style={{ ...tdStyle, textAlign: 'right' }}>{fmtNum(t.commission, 2)}</td>
|
||||
<td style={{ ...tdStyle, textAlign: 'right' }}>{fmtNum(t.stampTax, 2)}</td>
|
||||
<td style={{ ...tdStyle, textAlign: 'right' }}>{fmtNum(t.transferFee, 2)}</td>
|
||||
<td style={{ ...tdStyle, textAlign: 'right', color: '#999' }}>{t.tradeId}</td>
|
||||
</tr>
|
||||
))}
|
||||
|
||||
@@ -189,25 +189,30 @@ export class QmtBridgeRestDataSource {
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算单笔成交的费用(2026-09-01 老师定规则)
|
||||
* - 佣金:成交额 × (佣金费率万分之m_dCommission),不足 5 元按 5 元(账号没免五)
|
||||
* - 印花税:卖出单边,成交额 × 万分之5(2023-08-28 起标准)
|
||||
* - 过户费:双向,成交额 × 万分之0.1(2022-04-29 起标准,无最低限额)
|
||||
* @param {number} amount 成交额
|
||||
* 计算一笔委托的总费用(2026-09-01 老师定规则 + 修正)
|
||||
* 核心规则:同一笔委托分多笔成交,按总成交金额合并算一次佣金(不逐笔重复收费);
|
||||
* 多笔独立委托(分开下单)才各自算佣金、各自触发 5 元最低。
|
||||
* - 佣金:Σ成交额 × (佣金费率万分之m_dCommission),不足 5 元按 5 元(账号没免五,一次)
|
||||
* - 印花税:卖出单边,Σ成交额 × 万分之5(2023-08-28 起标准)
|
||||
* - 过户费:双向,Σ成交额 × 万分之0.1(2022-04-29 起标准,无最低限额)
|
||||
* @param {Array} trades 该委托的成交列表(每笔含 amount/direction)
|
||||
* @param {number} commissionRateWan 佣金费率(万分之,来自 m_dCommission)
|
||||
* @param {'buy'|'sell'|''} direction 方向
|
||||
* @returns {{ commission: number, stampTax: number, transferFee: number, total: number }}
|
||||
* @returns {{ totalAmount: number, commission: number, stampTax: number, transferFee: number, total: number }}
|
||||
*/
|
||||
calcTradeFees(amount, commissionRateWan, direction) {
|
||||
const a = Math.max(0, +(amount ?? 0));
|
||||
// 佣金:万分之X,最低 5 元(没免五)
|
||||
let commission = a * (commissionRateWan / 10000);
|
||||
calcOrderFees(trades, commissionRateWan) {
|
||||
const list = Array.isArray(trades) ? trades : [];
|
||||
// 合并总成交额(同一委托分笔成交合并计费)
|
||||
const totalAmount = list.reduce((s, t) => s + Math.max(0, +(t.amount ?? 0)), 0);
|
||||
const direction = list[0]?.direction ?? '';
|
||||
// 佣金:合并总额 × 费率,不足 5 元按 5 元(一次)
|
||||
let commission = totalAmount * (commissionRateWan / 10000);
|
||||
if (commission < 5 && commission > 0) commission = 5;
|
||||
// 印花税:卖出单边,万分之5
|
||||
const stampTax = direction === 'sell' ? a * 0.0005 : 0;
|
||||
const stampTax = direction === 'sell' ? totalAmount * 0.0005 : 0;
|
||||
// 过户费:双向,万分之0.1
|
||||
const transferFee = a * 0.00001;
|
||||
const transferFee = totalAmount * 0.00001;
|
||||
return {
|
||||
totalAmount: +totalAmount.toFixed(2),
|
||||
commission: +commission.toFixed(4),
|
||||
stampTax: +stampTax.toFixed(4),
|
||||
transferFee: +transferFee.toFixed(4),
|
||||
@@ -219,9 +224,6 @@ export class QmtBridgeRestDataSource {
|
||||
* m_dCommission 语义(2026-09-01 老师定):佣金费率(万分之),如 0.852 = 万分之0.852 */
|
||||
mapTrade(t) {
|
||||
const direction = t.m_nOffsetFlag === 48 ? 'buy' : t.m_nOffsetFlag === 49 ? 'sell' : '';
|
||||
const commissionRateWan = +(t.m_dCommission ?? t.m_dComssion ?? 0); // 拼写变体兜底
|
||||
const amount = +(t.m_dTradeAmount ?? 0);
|
||||
const fees = this.calcTradeFees(amount, commissionRateWan, direction);
|
||||
return {
|
||||
tradeId: t.m_strTradeID ?? '',
|
||||
orderId: t.m_strOrderSysID ?? '', // 关联委托
|
||||
@@ -233,12 +235,8 @@ export class QmtBridgeRestDataSource {
|
||||
optName: t.m_strOptName ?? '',
|
||||
price: +(t.m_dPrice ?? 0),
|
||||
volume: t.m_nVolume ?? 0,
|
||||
amount,
|
||||
commissionRateWan, // 佣金费率(万分之)
|
||||
commission: fees.commission, // 佣金金额(最低5元)
|
||||
stampTax: fees.stampTax, // 印花税(卖出)
|
||||
transferFee: fees.transferFee, // 过户费
|
||||
feeTotal: fees.total, // 总费用
|
||||
amount: +(t.m_dTradeAmount ?? 0),
|
||||
commissionRateWan: +(t.m_dCommission ?? t.m_dComssion ?? 0), // 佣金费率(万分之)
|
||||
tradeDate: t.m_strTradeDate ?? '',
|
||||
tradeTime: t.m_strTradeTime ?? '',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user