holdPosition.ts 1.2 KB

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