|
|
@@ -3,18 +3,19 @@ import { TradeMode } from '@/common/constants/enumCommon';
|
|
|
import { queryResultLoadingAndInfo } from '@/common/methods/request/resultInfo';
|
|
|
import { queryTableList } from '@/common/setup/table';
|
|
|
import { hasSystemParam } from '@/hooks/system';
|
|
|
-import { useHolderprice, useProfitloss } from '@/services/bus/holdPosition';
|
|
|
+import { useHolderprice } from '@/services/bus/holdPosition';
|
|
|
import { getMarketIdsByTradeMode, getMarketTradePropertyByGoodsId } from '@/services/bus/market';
|
|
|
import { getUserAccountType, getUsrId } from '@/services/bus/user';
|
|
|
import { AccountListItem } from '@/services/dataCenter/interafce/account';
|
|
|
import { queryTradePosition } from '@/services/go/ermcp/order';
|
|
|
import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
|
|
|
import { queryTradeHolderDetail } from "@/services/go/order";
|
|
|
-import { QueryTradeHolderDetailReq } from "@/services/go/order/interface";
|
|
|
+import { QueryTradeHolderDetailRsp } from "@/services/go/order/interface";
|
|
|
import { Taaccount } from '@/services/go/TaAccount/interface';
|
|
|
import { queryQuoteGoodsList } from '@/services/go/Tjmd';
|
|
|
import { QueryQuoteGoodsListReq, QueryQuoteGoodsListRsp } from '@/services/go/Tjmd/interface';
|
|
|
-import { findGoodsCode } from '@/views/order/swap_the_order/components/swap_commodity_contract_summary/setup';
|
|
|
+import { findGoodsCode, useDetail } from '@/views/order/swap_the_order/components/swap_commodity_contract_summary/setup';
|
|
|
+import { handleSubcriteQuote } from '@/common/setup/table/tableQuote';
|
|
|
import { ref, Ref } from 'vue';
|
|
|
|
|
|
export const tableColumns = () => {
|
|
|
@@ -140,40 +141,38 @@ export const tableColumns = () => {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
-// export function useTradePosition() {
|
|
|
-// const positionList = ref<QueryTradePositionRsp[]>([]); // 持仓汇总
|
|
|
-// const positionDetailList = ref<QueryTradeHolderDetailReq[]>([]); // 持仓明细
|
|
|
+/**
|
|
|
+ * 资金账户数据计算------------------------待优化
|
|
|
+ */
|
|
|
+export function useHazardRates() {
|
|
|
+ const { getDetailProfitloss } = useDetail();
|
|
|
+ const positionList = ref<QueryTradePositionRsp[]>([]); // 所有持仓汇总
|
|
|
+ const positionDetailList = ref<QueryTradeHolderDetailRsp[]>([]); // 所有持仓明细
|
|
|
+ const swapList = ref<QueryQuoteGoodsListRsp[]>([]); // 交割商品
|
|
|
|
|
|
-// const getPositionList = (loading: Ref<boolean>) => {
|
|
|
-// // 获取头寸
|
|
|
-// queryResultLoadingAndInfo(queryTradePosition, loading).then((res) => {
|
|
|
-// positionList.value = res;
|
|
|
-// })
|
|
|
-
|
|
|
-// const param: QueryTradeHolderDetailReq = {
|
|
|
-// userid: getUsrId(),
|
|
|
-// accids: accountid.toString(),
|
|
|
-// trademodes: trademode.toString(),
|
|
|
-// marketids: marketid.toString(),
|
|
|
-// }
|
|
|
-// queryResultLoadingAndInfo(queryTradeHolderDetail, loading, param).then(res => {
|
|
|
-// positionDetailList.value = res
|
|
|
-// })
|
|
|
-// }
|
|
|
-// }
|
|
|
+ const getHoldsList = async (loading: Ref<boolean>, tradeMode?: string) => {
|
|
|
+ // 获取头寸
|
|
|
+ await queryResultLoadingAndInfo(queryTradePosition, loading, tradeMode).then((res) => {
|
|
|
+ const goodsSet = new Set<string>();
|
|
|
+ positionList.value = res;
|
|
|
|
|
|
+ res.forEach((el) => {
|
|
|
+ // 商品掉期取参考行情最新价,挂牌点选取自己行情的最新价
|
|
|
+ const goodscode = findGoodsCode(el.goodsid, el.goodscode, swapList.value);
|
|
|
+ if (goodscode) {
|
|
|
+ goodsSet.add(goodscode);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
-export const useHazardRates = () => {
|
|
|
- // 持仓汇总
|
|
|
- const holdsList = ref<QueryTradePositionRsp[]>([]);
|
|
|
- function getHoldsList(loading: Ref<boolean>) {
|
|
|
- // 获取头寸
|
|
|
- queryResultLoadingAndInfo(queryTradePosition, loading).then(res => {
|
|
|
- holdsList.value = res;
|
|
|
+ // 行情订阅
|
|
|
+ const { subscribeAction } = handleSubcriteQuote();
|
|
|
+ subscribeAction([...goodsSet]);
|
|
|
+ })
|
|
|
+ await queryResultLoadingAndInfo(queryTradeHolderDetail, loading, { userid: getUsrId() }).then(res => {
|
|
|
+ positionDetailList.value = res
|
|
|
})
|
|
|
}
|
|
|
- // 交割商品
|
|
|
- const swapList = ref<QueryQuoteGoodsListRsp[]>([]);
|
|
|
+
|
|
|
function getSwapList() {
|
|
|
const { queryTable } = queryTableList<QueryQuoteGoodsListRsp>();
|
|
|
// 组装 参数
|
|
|
@@ -186,31 +185,50 @@ export const useHazardRates = () => {
|
|
|
}
|
|
|
queryTable(queryQuoteGoodsList, param).then(res => swapList.value = res)
|
|
|
}
|
|
|
+
|
|
|
// 获取报价小数位
|
|
|
function getDecimalplace() {
|
|
|
- return holdsList.value.length > 0 ? holdsList.value[0].decimalplace : 2
|
|
|
+ return positionList.value.length > 0 ? positionList.value[0].decimalplace : 2
|
|
|
}
|
|
|
|
|
|
// 获取当前资金账号对应的头寸
|
|
|
function getTaaccountPosition(accountid: number) {
|
|
|
- return holdsList.value.filter(e => e.accountid === accountid)
|
|
|
+ return positionList.value.filter(e => e.accountid === accountid)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取持仓明细
|
|
|
+ function getTradeHolderDetail(record: QueryTradePositionRsp) {
|
|
|
+ const { accountid, trademode, marketid, goodsid, buyorsell } = record;
|
|
|
+ return positionDetailList.value.filter((e) => e.accountid === accountid && e.trademode === trademode && e.marketid === marketid && e.goodsid === goodsid && e.buyorsell === buyorsell);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 持仓盈亏
|
|
|
+ // 浮动盈亏 持仓单:
|
|
|
+ // 收益权=(最新价-持仓价)*持仓数量*合约单位*方向(买[1]:卖[-1])(*汇率)
|
|
|
+ // 所有权=(最新价*持仓数量*合约单位(*汇率) - 持仓金额)
|
|
|
+ function useProfitloss(record: QueryTradePositionRsp) {
|
|
|
+ const detailList = getTradeHolderDetail(record);
|
|
|
+ return detailList.reduce((res, item) => {
|
|
|
+ const goodscode = findGoodsCode(item.goodsid, item.goodscode, swapList.value);
|
|
|
+ res += Number(getDetailProfitloss(item, goodscode));
|
|
|
+ return res;
|
|
|
+ }, 0)
|
|
|
}
|
|
|
+
|
|
|
// 汇总资金账号 的 浮动盈亏
|
|
|
function handleProfitloss({ accountid }: Taaccount, isDecimalPace = true) {
|
|
|
const decimalplace = getDecimalplace()
|
|
|
const result = getTaaccountPosition(accountid).reduce((acc: number, current: QueryTradePositionRsp) => {
|
|
|
- const tradeproperty = getMarketTradePropertyByGoodsId(current.goodsid)
|
|
|
- let temp = 0
|
|
|
+ const tradeproperty = getMarketTradePropertyByGoodsId(current.goodsid);
|
|
|
+ // 资金 只算 收益权
|
|
|
if (tradeproperty === 1) {
|
|
|
- // 资金 只算 收益权
|
|
|
- const goodscode = findGoodsCode(current.goodsid, current.goodscode, swapList.value)
|
|
|
- const profitloos = useProfitloss(current, goodscode)
|
|
|
- temp = profitloos === '--' ? 0 : Number(profitloos)
|
|
|
+ acc += useProfitloss(current);
|
|
|
}
|
|
|
- return acc + temp
|
|
|
+ return acc
|
|
|
}, 0)
|
|
|
return isDecimalPace ? result.toFixed(decimalplace) : result
|
|
|
}
|
|
|
+
|
|
|
// 计算 市值
|
|
|
function handleHoldPrice(accountid: number) {
|
|
|
return getTaaccountPosition(accountid).reduce((acc: number, current: QueryTradePositionRsp) => {
|
|
|
@@ -219,6 +237,7 @@ export const useHazardRates = () => {
|
|
|
return acc + temp
|
|
|
}, 0)
|
|
|
}
|
|
|
+
|
|
|
// 风险净值
|
|
|
function handleRiskValue(taaccount: Taaccount) {
|
|
|
const { accountid, currentbalance, otherfreezemargin, outamountfreeze } = taaccount
|
|
|
@@ -232,6 +251,7 @@ export const useHazardRates = () => {
|
|
|
// 1. 风险净值=期末余额+市值+浮动盈亏(收益权)-其他冻结-出金冻结
|
|
|
return currentbalance + price + profitloss - otherfreezemargin - outamountfreeze
|
|
|
}
|
|
|
+
|
|
|
// 净值
|
|
|
// 根据系统参数“307 账户净值是否减冻结资金 - 0:不减 1:减“
|
|
|
//0.净值=期末余额+市值+浮动盈亏(收益权)
|
|
|
@@ -247,6 +267,7 @@ export const useHazardRates = () => {
|
|
|
const decimalplace = getDecimalplace()
|
|
|
return (currentbalance + profitloss + price - free).toFixed(decimalplace)
|
|
|
}
|
|
|
+
|
|
|
// 风险率
|
|
|
function hazardRates(taaccount: Taaccount) {
|
|
|
const { usedmargin, mortgagecredit } = taaccount
|
|
|
@@ -264,6 +285,7 @@ export const useHazardRates = () => {
|
|
|
result = result ? result * 100 : 0
|
|
|
return result.toFixed(decimalplace) + '%'
|
|
|
}
|
|
|
+
|
|
|
// 可用资金
|
|
|
function canUseMoney(taaccount: Taaccount | AccountListItem) {
|
|
|
const { currentbalance, usedmargin, freezemargin, freezecharge, otherfreezemargin, outamountfreeze } = taaccount
|
|
|
@@ -291,6 +313,17 @@ export const useHazardRates = () => {
|
|
|
return result.toFixed(decimalplace)
|
|
|
}
|
|
|
|
|
|
- return { handleProfitloss, getSwapList, hazardRates, netWorth, canUseMoney, getHoldsList, handleHoldPrice }
|
|
|
+ return {
|
|
|
+ positionList,
|
|
|
+ swapList,
|
|
|
+ useProfitloss,
|
|
|
+ handleProfitloss,
|
|
|
+ getTradeHolderDetail,
|
|
|
+ getSwapList,
|
|
|
+ hazardRates,
|
|
|
+ netWorth,
|
|
|
+ canUseMoney,
|
|
|
+ getHoldsList,
|
|
|
+ handleHoldPrice
|
|
|
+ }
|
|
|
}
|
|
|
-
|