holdPosition.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { BuyOrSell } from "@/common/constants/enumCommon";
  2. import { QueryTradePositionRsp } from "../go/ermcp/order/interface";
  3. import { getQuoteDayInfoByCodeFindPrice } from "./goods";
  4. // 持仓盈亏
  5. // 浮动盈亏 持仓单:
  6. // 收益权=(最新价-持仓价)*持仓数量*合约单位*方向(买[1]:卖[-1])(*汇率)
  7. // 所有权=(最新价*持仓数量*合约单位(*汇率) - 持仓金额)
  8. export const useProfitloss = (record: QueryTradePositionRsp, goodscode?: string) => {
  9. // 最新价
  10. if (!goodscode) {
  11. goodscode = record.goodscode
  12. }
  13. const lastPrice = getQuoteDayInfoByCodeFindPrice(goodscode);
  14. if (lastPrice !== '--') {
  15. const { averageprice, decimalplace, agreeunit, curpositionqty, buyorsell } = record;
  16. const temp = buyorsell === BuyOrSell.buy ? 1 : -1
  17. const result = ((+lastPrice - averageprice) * curpositionqty * agreeunit * temp).toFixed(2);
  18. return result === '-0' ? '0' : result
  19. } else {
  20. return lastPrice;
  21. }
  22. }
  23. // 市值(所有权) = 数量 * 现价 * 合约单位
  24. export const useHolderprice = (record: QueryTradePositionRsp) => {
  25. // 最新价
  26. const lastPrice = getQuoteDayInfoByCodeFindPrice(record.goodscode);
  27. if (lastPrice !== '--') {
  28. const { decimalplace, agreeunit, curpositionqty } = record;
  29. return (+lastPrice * curpositionqty * agreeunit).toFixed(decimalplace);
  30. } else {
  31. return lastPrice
  32. }
  33. }