Переглянути джерело

修改 商品掉期 挂牌求购 最大数量和保证金

huangbin 4 роки тому
батько
коміт
b4820cd972

+ 15 - 1
src/hooks/margin.ts

@@ -30,5 +30,19 @@ export const useTodayMargin = () => {
         }
         return result
     }
-    return { findTodayMarginByMarketId, getReckonMarginValueByTradeMode }
+    // 获取 保证金值 方式
+    function getReckonMarginTypeAndValueByTradeMode(trademode: TradeMode) {
+        const result = [0, 0]
+        const marketInfo = getMarketByTradeMode(trademode)
+        if (marketInfo) {
+            const temp = findTodayMarginByMarketId(marketInfo.marketid)?.infoc
+            if (temp) {
+                result[0] = temp.MarginAlgorithm
+                result[1] = temp.ReckonMarginValue
+            }
+        }
+        return result
+    }
+
+    return { findTodayMarginByMarketId, getReckonMarginValueByTradeMode, getReckonMarginTypeAndValueByTradeMode }
 }

+ 1 - 1
src/services/go/Tjmd/interface.ts

@@ -29,7 +29,7 @@ export interface GoodsMarginCfgStruct {
     GoodsID: number;//商品ID
     IsDefault: number;//是否默认标志位
     LockMarginValue: number;//锁仓保证金
-    MarginAlgorithm: number;//保证金计算方式
+    MarginAlgorithm: number;//保证金计算方式 指定保证金方式 1:比率 2:固定
     MarketMarginValue: number;//即市保证金值
     RealMarginAlgorithm: number;//实付保证金计算方式
     RealMarginValue: number;//实付比例

+ 33 - 15
src/views/market/spot_trade/spot_trade_order_transaction/spot_trade_order_transaction_swap/components/post_buying/index.vue

@@ -187,7 +187,7 @@ export default defineComponent({
         queryTable(queryTradePosition);
 
         // 获取保证金比例
-        const { getReckonMarginValueByTradeMode } = useTodayMargin();
+        const { getReckonMarginValueByTradeMode, getReckonMarginTypeAndValueByTradeMode } = useTodayMargin();
         // 控制弹窗
         const { visible, cancel } = _closeModal(context);
         // 表单
@@ -207,26 +207,44 @@ export default defineComponent({
         const { getFloatPrice, getMoney } = useListingTradeNumAndPrice<FormParam>(param);
         // 保证金
         const getMargin = () => {
-            const marginvalue = getReckonMarginValueByTradeMode(TradeMode.DiaoQi);
-            return marginvalue ? marginvalue : '--';
+            let result = '--';
+            const [marginType, marginValue] = getReckonMarginTypeAndValueByTradeMode(TradeMode.DiaoQi);
+            if (marginType) {
+                // 保证金方式 1:比率 2:固定
+                if (marginType === 1) {
+                    if (getMoney()) {
+                        // 履约保证金=挂牌金额*保证金比例
+                        result = ((getMoney() * marginValue) / 100).toFixed(2);
+                    }
+                } else {
+                    if (formState.OrderQty) {
+                        // 履约保证金=挂牌数量*保证金固定值
+                        result = (formState.OrderQty * marginValue).toFixed(2);
+                    }
+                }
+            }
+            return result;
         };
         // 最大数量
         const getMaxNum = () => {
             let result = 0;
-            if (isBuy()) {
-                // 可用资金
-                const temp = +canUseMoney();
-
-                const money = temp > 0 ? temp : 0;
-                const agreeunit = getGoodsAgreeunitByGoodsCode(props.selectedRow.goodscode);
-                if (money && formState.FixedPrice) {
-                    result = +(money / (formState.FixedPrice * agreeunit)).toFixed(0);
+            const [marginType, marginValue] = getReckonMarginTypeAndValueByTradeMode(TradeMode.DiaoQi);
+            // 可用资金
+            const temp = +canUseMoney();
+            const money = temp > 0 ? temp : 0;
+            if (marginType && money && formState.FixedPrice) {
+                // 保证金方式 1:比率 2:固定
+                if (marginType === 1) {
+                    // 合约单位
+                    const agreeunit = getGoodsAgreeunitByGoodsCode(props.selectedRow.goodscode);
+                    // 最大可挂牌数量=可用/(价格*合约单位*保证金比例
+                    result = money / (((formState.FixedPrice * marginValue) / 100) * agreeunit);
+                } else {
+                    // 最大可挂牌数量=可用/保证金固定值
+                    result = money / marginValue;
                 }
-            } else {
-                const temp = tableList.value.find((el) => el.goodscode === props.selectedRow.goodscode)?.enableqty;
-                result = temp ? temp : 0;
             }
-            return result;
+            return +result.toFixed(0);
         };
         // 估算价
         function getPrice() {