|
|
@@ -0,0 +1,200 @@
|
|
|
+import APP from '@/services';
|
|
|
+import { useHolderprice, useProfitloss } from '@/services/bus/holdPosition';
|
|
|
+import { QueryTradePositionRsp } from '@/services/go/ermcp/order/interface';
|
|
|
+import { Taaccount } from '@/services/go/TaAccount/interface';
|
|
|
+import { Systemparam } from '@/services/go/useInfo/interface';
|
|
|
+import { Ref } from 'vue';
|
|
|
+
|
|
|
+export const tableColumns = [
|
|
|
+ {
|
|
|
+ key: '0th',
|
|
|
+ dataIndex: 'accountid',
|
|
|
+ title: '资金账号',
|
|
|
+ align: 'center',
|
|
|
+ slots: {
|
|
|
+ customRender: 'accountid',
|
|
|
+ },
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: '1th',
|
|
|
+ dataIndex: 'currentbalance',
|
|
|
+ title: '净值',
|
|
|
+ align: 'center',
|
|
|
+ slots: {
|
|
|
+ customRender: 'currentbalance',
|
|
|
+ },
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: '2th',
|
|
|
+ dataIndex: 'balance',
|
|
|
+ title: '可用资金',
|
|
|
+ align: 'center',
|
|
|
+ slots: {
|
|
|
+ customRender: 'balance',
|
|
|
+ },
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: '3th',
|
|
|
+ dataIndex: 'usedmargin',
|
|
|
+ title: '占用资金',
|
|
|
+ align: 'center',
|
|
|
+ slots: {
|
|
|
+ customRender: 'usedmargin',
|
|
|
+ },
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: '4th',
|
|
|
+ dataIndex: 'freezemargin',
|
|
|
+ title: '冻结资金',
|
|
|
+ align: 'center',
|
|
|
+ slots: {
|
|
|
+ customRender: 'freezemargin',
|
|
|
+ },
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: '5th',
|
|
|
+ dataIndex: 'closepl',
|
|
|
+ title: '浮动盈亏',
|
|
|
+ align: 'center',
|
|
|
+ slots: {
|
|
|
+ customRender: 'closepl',
|
|
|
+ },
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: '51th',
|
|
|
+ dataIndex: 'currentbalance',
|
|
|
+ title: '余额',
|
|
|
+ align: 'center',
|
|
|
+ slots: {
|
|
|
+ customRender: 'currentbalance',
|
|
|
+ },
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: '6th',
|
|
|
+ dataIndex: 'usedmargin',
|
|
|
+ title: '风险率',
|
|
|
+ align: 'center',
|
|
|
+ slots: {
|
|
|
+ customRender: 'accountname',
|
|
|
+ },
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: '7th',
|
|
|
+ dataIndex: 'tradestatus',
|
|
|
+ title: '状态',
|
|
|
+ align: 'center',
|
|
|
+ slots: {
|
|
|
+ customRender: 'tradestatus',
|
|
|
+ },
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+
|
|
|
+export const useHazardRates = (positions: Ref<QueryTradePositionRsp[]>) => {
|
|
|
+ // 获取报价小数位
|
|
|
+ function getDecimalplace() {
|
|
|
+ return positions.value.length > 0 ? positions.value[0].decimalplace : 2
|
|
|
+ }
|
|
|
+ // 获取系统参数
|
|
|
+ const getSystemParam = (paramcode: string, value: string) => APP.getRef('systemParams').value.find((param: Systemparam) => param.paramcode)?.paramvalue === value
|
|
|
+ // 获取当前资金账号对应的头寸
|
|
|
+ function getTaaccountPosition(accountid: number) {
|
|
|
+ return positions.value.filter(e => e.accountid === accountid)
|
|
|
+ }
|
|
|
+ // 汇总资金账号 的 浮动盈亏
|
|
|
+ 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)
|
|
|
+ return acc + temp
|
|
|
+ }, 0)
|
|
|
+ return isDecimalPace ? result.toFixed(decimalplace) : result
|
|
|
+ }
|
|
|
+ // 计算 市值
|
|
|
+ function handleHoldPrice(accountid: number) {
|
|
|
+ return getTaaccountPosition(accountid).reduce((acc: number, current: QueryTradePositionRsp) => {
|
|
|
+ const price = useHolderprice(current)
|
|
|
+ const temp = price === '--' ? 0 : Number(price)
|
|
|
+ return acc + temp
|
|
|
+ }, 0)
|
|
|
+ }
|
|
|
+ // 风险净值
|
|
|
+ function handleRiskValue(taaccount: Taaccount) {
|
|
|
+ const { accountid, currentbalance, otherfreezemargin, outamountfreeze } = taaccount
|
|
|
+ // 浮动盈亏
|
|
|
+ const profitloss = handleProfitloss(taaccount, false) as number
|
|
|
+ // 市值
|
|
|
+ const price = getSystemParam('087', '1') ? handleHoldPrice(accountid) : 0
|
|
|
+
|
|
|
+ // 风险净值 根据系统参数“087 风险净值是否加上市值 - 0:不加 1:加“
|
|
|
+ // 0. 风险净值=期末余额+浮动盈亏(收益权)-其他冻结-出金冻结
|
|
|
+ // 1. 风险净值=期末余额+市值+浮动盈亏(收益权)-其他冻结-出金冻结
|
|
|
+ return currentbalance + price + profitloss - otherfreezemargin - outamountfreeze
|
|
|
+ }
|
|
|
+ // 净值期 末余额+市值+浮动盈亏(收益权
|
|
|
+ function netWorth(taaccount: Taaccount) {
|
|
|
+ const { accountid, currentbalance } = taaccount
|
|
|
+ // 浮动盈亏
|
|
|
+ const profitloss = handleProfitloss(taaccount, false) as number
|
|
|
+ // 市值
|
|
|
+ const price = handleHoldPrice(accountid)
|
|
|
+ const decimalplace = getDecimalplace()
|
|
|
+ return (currentbalance + profitloss + price).toFixed(decimalplace)
|
|
|
+ }
|
|
|
+ // 风险率
|
|
|
+ function hazardRates(taaccount: Taaccount) {
|
|
|
+ const { usedmargin, mortgagecredit } = taaccount
|
|
|
+ // 风险净值
|
|
|
+ const riskValue = handleRiskValue(taaccount)
|
|
|
+ const decimalplace = getDecimalplace()
|
|
|
+ // 风险率 根据系统参数“132 风险率计算公式”:
|
|
|
+ // 1. 风险率=占用/风险净值
|
|
|
+ // 2. 风险率=(占用-授信金额)/(风险净值-授信金额)
|
|
|
+ const credit = getSystemParam('132', '1') ? 0 : mortgagecredit
|
|
|
+ let result = 0
|
|
|
+ if (riskValue && (riskValue - credit)) {
|
|
|
+ result = (usedmargin - credit) / (riskValue - credit)
|
|
|
+ }
|
|
|
+ result = result ? result * 100 : 0
|
|
|
+ return result.toFixed(decimalplace) + '%'
|
|
|
+ }
|
|
|
+
|
|
|
+ function canUseMoney(taaccount: Taaccount) {
|
|
|
+ const { currentbalance, usedmargin, freezemargin, freezecharge, otherfreezemargin, outamountfreeze } = taaccount
|
|
|
+
|
|
|
+ // 浮动盈亏
|
|
|
+ const profitloss = handleProfitloss(taaccount, false) as number
|
|
|
+ // 占用+冻结+其它冻结+手续费冻结+出金冻结
|
|
|
+ const freeze = usedmargin + freezemargin + freezecharge + otherfreezemargin + outamountfreeze
|
|
|
+ let result = 0
|
|
|
+ if (profitloss < 0) {
|
|
|
+ // 账户总浮动盈亏为负:= 期末余额+总浮动盈亏-占用-冻结-其它冻结-手续费冻结-出金冻结
|
|
|
+ result = currentbalance + profitloss - freeze
|
|
|
+ } else {
|
|
|
+ // *系统参数”113“(当日浮动盈利是否可用) 0:不可用 1:可用
|
|
|
+ const isUse = getSystemParam('113', '1')
|
|
|
+ if (isUse) {
|
|
|
+ // 账户总浮动盈亏为正 且 113 = 1 :=期末余额+总浮动盈亏-占用-冻结-其它冻结-手续费冻结-出金冻结
|
|
|
+ result = currentbalance + profitloss - freeze
|
|
|
+ } else {
|
|
|
+ // 账户总浮动盈亏为正 且 113 = 0 :=期末余额-占用-冻结-其它冻结-手续费冻结-出金冻结
|
|
|
+ result = currentbalance - freeze
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const decimalplace = getDecimalplace()
|
|
|
+ return result.toFixed(decimalplace)
|
|
|
+ }
|
|
|
+
|
|
|
+ return { handleProfitloss, hazardRates, netWorth, canUseMoney }
|
|
|
+}
|
|
|
+
|