|
|
@@ -1,6 +1,7 @@
|
|
|
-import { computed } from 'vue';
|
|
|
import { QueryErmcpTradePositionRsp } from '@/services/go/ermcp/futures/interface';
|
|
|
+import { BuyOrSell } from '@/common/constants/enumCommon';
|
|
|
import { getBuyOrSellName } from '@/common/constants/enumsName';
|
|
|
+import { getQuoteDayInfoByCode } from "@/services/bus/goods";
|
|
|
|
|
|
export function getColumns() {
|
|
|
const columns = [
|
|
|
@@ -28,19 +29,35 @@ export function getColumns() {
|
|
|
},
|
|
|
{
|
|
|
title: '开仓均价',
|
|
|
- key: 'openaverageprice'
|
|
|
+ key: 'openaverageprice',
|
|
|
+ customRender: ({ record }: { record: QueryErmcpTradePositionRsp }) => {
|
|
|
+ return calcOpenAveragePrice(record).toFixed(2);
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '持仓均价',
|
|
|
- key: 'positionaverageprice'
|
|
|
+ key: 'positionaverageprice',
|
|
|
+ customRender: ({ record }: { record: QueryErmcpTradePositionRsp }) => {
|
|
|
+ return calcPositionAveragePrice(record).toFixed(2);
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '浮动盈亏',
|
|
|
- key: 'positionpl'
|
|
|
+ key: 'positionpl',
|
|
|
+ customRender: ({ record }: { record: QueryErmcpTradePositionRsp }) => {
|
|
|
+ const result = calcPositionPl(record);
|
|
|
+ if (result === 0) return result;
|
|
|
+ return handlePriceColor(result, result.toFixed(2));
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '盈亏比例',
|
|
|
- key: 'positionplrate'
|
|
|
+ key: 'positionplrate',
|
|
|
+ customRender: ({ record }: { record: QueryErmcpTradePositionRsp }) => {
|
|
|
+ const result = calcPositionPlRate(record);
|
|
|
+ if (result === 0) return result;
|
|
|
+ return handlePriceColor(result, result.toFixed(2) + '%');
|
|
|
+ }
|
|
|
},
|
|
|
];
|
|
|
|
|
|
@@ -53,4 +70,61 @@ export function getColumns() {
|
|
|
...el
|
|
|
}
|
|
|
})
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 计算开仓均价
|
|
|
+ */
|
|
|
+function calcOpenAveragePrice(record: QueryErmcpTradePositionRsp) {
|
|
|
+ const { opencost, curpositionqty, agreeunit } = record
|
|
|
+ // 开仓成本 ÷ 期末头寸 ÷ 合约单位
|
|
|
+ return opencost / curpositionqty / agreeunit;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 计算持仓均价
|
|
|
+ */
|
|
|
+function calcPositionAveragePrice(record: QueryErmcpTradePositionRsp) {
|
|
|
+ const { positioncost, curpositionqty, agreeunit } = record
|
|
|
+ // 持仓成本 ÷ 期末头寸 ÷ 合约单位
|
|
|
+ return positioncost / curpositionqty / agreeunit;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 计算浮动盈亏
|
|
|
+ */
|
|
|
+function calcPositionPl(record: QueryErmcpTradePositionRsp) {
|
|
|
+ const { goodscode, curpositionqty, agreeunit } = record
|
|
|
+ // 获取对应的商品行情
|
|
|
+ const quote = getQuoteDayInfoByCode(goodscode);
|
|
|
+
|
|
|
+ if (quote?.last) {
|
|
|
+ if (record.buyorsell === BuyOrSell.buy) {
|
|
|
+ // 买方向 = (最新价 - 持仓均价) * 买期末头寸 * 合约单位
|
|
|
+ return (quote.last - calcPositionAveragePrice(record)) * curpositionqty * agreeunit
|
|
|
+ } else {
|
|
|
+ // 卖方向 = (持仓均价 - 最新价) * 卖期末头寸 * 合约单位
|
|
|
+ return (calcPositionAveragePrice(record) - quote.last) * curpositionqty * agreeunit
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return record.positionpl
|
|
|
+}
|
|
|
+
|
|
|
+function calcPositionPlRate(record: QueryErmcpTradePositionRsp) {
|
|
|
+ const { opencost } = record
|
|
|
+ // 持仓盈亏 ÷ 开仓成本
|
|
|
+ return calcPositionPl(record) / opencost * 100
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 处理显示颜色
|
|
|
+ */
|
|
|
+function handlePriceColor(value: number, text: string) {
|
|
|
+ let className = ''
|
|
|
+ if (value > 0) {
|
|
|
+ className = 'up-quote-color'
|
|
|
+ } else {
|
|
|
+ className = 'down-quote-color'
|
|
|
+ }
|
|
|
+ return <span class={className}>{text}</span>;
|
|
|
}
|