import { BuyOrSell } from "@/common/constants/enumCommon"; import { QueryTradePositionRsp } from "../go/ermcp/order/interface"; import { getQuoteDayInfoByCodeFindPrice } from "./goods"; // 持仓盈亏 // 浮动盈亏 持仓单: // 收益权=(最新价-持仓价)*持仓数量*合约单位*方向(买[1]:卖[-1])(*汇率) // 所有权=(最新价*持仓数量*合约单位(*汇率) - 持仓金额) export const useProfitloss = (record: QueryTradePositionRsp, goodscode?: string) => { // 最新价 if (!goodscode) { goodscode = record.goodscode } const lastPrice = getQuoteDayInfoByCodeFindPrice(goodscode); if (lastPrice !== '--') { const { averageprice, decimalplace, agreeunit, curpositionqty, buyorsell } = record; const temp = buyorsell === BuyOrSell.buy ? 1 : -1 const result = ((+lastPrice - averageprice) * curpositionqty * agreeunit * temp).toFixed(2); return result === '-0' ? '0' : result } else { return lastPrice; } } // 市值(所有权) = 数量 * 现价 * 合约单位 export const useHolderprice = (record: QueryTradePositionRsp) => { // 最新价 const lastPrice = getQuoteDayInfoByCodeFindPrice(record.goodscode); if (lastPrice !== '--') { const { decimalplace, agreeunit, curpositionqty } = record; return (+lastPrice * curpositionqty * agreeunit).toFixed(decimalplace); } else { return lastPrice } }