Advertisement
Double_X

基本貨幣數量

Jan 15th, 2024
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.81 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8">
  5.         <title>基本貨幣數量</title>
  6.         <script>
  7.             window.onload = () => {
  8.                 const INPUT_IDS = [
  9.                     "maxLossPercent",
  10.                     "minOdds",
  11.                     "maxAmount",
  12.                     "lossCap",
  13.                     "openPrice"
  14.                 ], INPUTS = INPUT_IDS.reduce((inputs, id) => {
  15.                     inputs[id] = document.getElementById(id);
  16.                     inputs[id].onchange = () => onUpdateAdvisedAmount();
  17.                     return inputs;
  18.                 }, {}), { advisedAmount, advisedGainCap } = [
  19.                     "advisedAmount",
  20.                     "advisedGainCap"
  21.                 ].reduce((outputs, id) => {
  22.                     outputs[id] = document.getElementById(id);
  23.                     return outputs;
  24.                 }, {});
  25.                 const inputValue = id => INPUTS[id].value;
  26.                 const areValidInputs = () => INPUT_IDS.every(inputValue);
  27.                 const onUpdateAdvisedAmount = () => {
  28.                     if (areValidInputs()) updateAdvisedAmount();
  29.                 }, updateAdvisedAmount = () => {
  30.                     const {
  31.                         maxLossPercent,
  32.                         minOdds,
  33.                         maxAmount,
  34.                         lossCap,
  35.                         openPrice
  36.                     } = INPUT_IDS.reduce((values, id) => {
  37.                         values[id] = +inputValue(id);
  38.                         return values;
  39.                     }, {}), loss = lossCap - openPrice;
  40.                     const lossPercent = Math.abs(loss / openPrice * 100.0);
  41.                     const amountRatio = maxLossPercent / lossPercent;
  42.                     const rawAdvisedAmount = amountRatio * maxAmount;
  43.                     advisedAmount.value = Math.min(rawAdvisedAmount, maxAmount);
  44.                     advisedGainCap.value = openPrice - loss * minOdds;
  45.                 };
  46.                 INPUTS.maxLossPercent.value = "0.04";
  47.                 INPUTS.minOdds.value = "2";
  48.             };
  49.         </script>
  50.     </head>
  51.     <body>
  52.         <text>最大止損%</text>
  53.         <input id="maxLossPercent" type="text" />
  54.         <text>最小盈虧比</text>
  55.         <input id="minOdds" type="text" />
  56.         <text>最大購買力</text>
  57.         <input id="maxAmount" type="text" />
  58.         <text>止損價</text>
  59.         <input id="lossCap" type="text" />
  60.         <text>開倉價</text>
  61.         <input id="openPrice" type="text" />
  62.         <br>
  63.         <text><b><u>建議購買力</u></b></text>
  64.         <input id="advisedAmount" readOnly=true type="text" />
  65.         <text><b><u>建議止盈價</u></b></text>
  66.         <input id="advisedGainCap" readOnly=true type="text" />
  67.     </body>
  68. </html>
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement