Ver Fonte

修改浮动盈亏

huangbin há 4 anos atrás
pai
commit
225ce223b5

+ 22 - 2
src/services/bus/market.ts

@@ -3,14 +3,19 @@ import APP from '@/services';
 import { message } from "ant-design-vue";
 import { Marketrun } from "../go/commonMarket/interface";
 import { Market } from "../go/useInfo/interface";
+import { getGoodsList } from "./goods";
+
+export function getAllMarkets(): Market[] {
+    return APP.get('markets')
+}
 
 export function getMarketByTradeMode(trademode: TradeMode): Market | undefined {
-    return APP.get('markets').find((el: Market) => el.trademode === trademode)
+    return getAllMarkets().find((el: Market) => el.trademode === trademode)
 }
 
 // 通过 trademode 获取市场信息列表
 export function getMarketsByTradeMode(trademode: TradeMode): Market[] {
-    return APP.get('markets').filter((el: Market) => el.trademode === trademode)
+    return getAllMarkets().filter((el: Market) => el.trademode === trademode)
 }
 
 
@@ -49,4 +54,19 @@ export function marketIsRun(trademode: TradeMode) {
         console.warn(`没有找到trademode${trademode}对应的市场信息`)
     }
     return result
+}
+
+// 通过 商品id查找 市场id
+export function getMarketByGoodsId(goodsid: number) {
+    return getGoodsList().find(e => e.goodsid === goodsid)?.marketid
+}
+// 通过 商品id查找 市场交易属性
+export function getMarketTradePropertyByGoodsId(goodsid: number) {
+    let result = null
+    const marketid = getMarketByGoodsId(goodsid)
+    if (marketid) {
+        const temp = getAllMarkets().find(el => el.marketid === marketid)?.tradeproperty
+        result = temp ? temp : null
+    }
+    return result
 }

+ 5 - 1
src/views/order/commodity_contract/components/commodity_contract_summary/index.vue

@@ -27,13 +27,17 @@
       <template #lastprice="{ record }">
         <a>{{ getLastprice(record) }}</a>
       </template>
+      <!-- 均价 -->
+      <template #averageprice="{ text }">
+        <a>{{ text ? text : 0 }}</a>
+      </template>
       <!-- 持仓金额  -->
       <template #holderprice="{ record }">
         <a>{{ useHolderprice(record) }}</a>
       </template>
       <!-- 持仓盈亏 -->
       <template #profitloss="{ record }">
-        <a>{{ useProfitloss(record) }}</a>
+        <span>{{ record.averageprice ? useProfitloss(record) : '--' }}</span>
       </template>
     </a-table>
     <component :is="componentId"

+ 16 - 5
src/views/order/funding_information/components/funding_information_funding_summary/setup.ts

@@ -1,5 +1,6 @@
 import APP from '@/services';
 import { useHolderprice, useProfitloss } from '@/services/bus/holdPosition';
+import { getMarketTradePropertyByGoodsId } from '@/services/bus/market';
 import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
 import { Taaccount } from '@/services/go/TaAccount/interface';
 import { Systemparam } from '@/services/go/useInfo/interface';
@@ -114,8 +115,13 @@ export const useHazardRates = (positions: Ref<QueryTradePositionRsp[]>) => {
     function handleProfitloss({ accountid }: Taaccount, isDecimalPace = true) {
         const decimalplace = getDecimalplace()
         const result = getTaaccountPosition(accountid).reduce((acc: number, current: QueryTradePositionRsp) => {
-            const profitloos = useProfitloss(current)
-            const temp = profitloos === '--' ? 0 : Number(profitloos)
+            const tradeproperty = getMarketTradePropertyByGoodsId(current.goodsid)
+            let temp = 0
+            if (tradeproperty === 1) {
+                // 资金 只算 收益权
+                const profitloos = useProfitloss(current)
+                temp = profitloos === '--' ? 0 : Number(profitloos)
+            }
             return acc + temp
         }, 0)
         return isDecimalPace ? result.toFixed(decimalplace) : result
@@ -141,15 +147,20 @@ export const useHazardRates = (positions: Ref<QueryTradePositionRsp[]>) => {
         // 1. 风险净值=期末余额+市值+浮动盈亏(收益权)-其他冻结-出金冻结
         return currentbalance + price + profitloss - otherfreezemargin - outamountfreeze
     }
-    // 净值期 末余额+市值+浮动盈亏(收益权
+    // 净值
+    // 根据系统参数“307 账户净值是否减冻结资金 - 0:不减 1:减“
+    //0.净值=期末余额+市值+浮动盈亏(收益权)
+    //1.净值=期末余额+市值+浮动盈亏(收益权)-其他冻结-出金冻结
     function netWorth(taaccount: Taaccount) {
-        const { accountid, currentbalance } = taaccount
+        const { accountid, currentbalance, otherfreezemargin, outamountfreeze } = taaccount
         // 浮动盈亏
+        const free = getSystemParam('037', '1') ? (otherfreezemargin + outamountfreeze) : 0
+
         const profitloss = handleProfitloss(taaccount, false) as number
         // 市值
         const price = handleHoldPrice(accountid)
         const decimalplace = getDecimalplace()
-        return (currentbalance + profitloss + price).toFixed(decimalplace)
+        return (currentbalance + profitloss + price - free).toFixed(decimalplace)
     }
     // 风险率
     function hazardRates(taaccount: Taaccount) {