w-trade-backtest 1.0.8 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/w-trade-backtest.umd.js +2 -2
- package/dist/w-trade-backtest.umd.js.map +1 -1
- package/docs/buildKLinesTpSl.mjs.html +2 -2
- package/docs/buildStrategyFastSession.mjs.html +365 -0
- package/docs/calcOrders.mjs.html +2 -2
- package/docs/calcOrdersRatio.mjs.html +2 -2
- package/docs/calcOrdersSummary.mjs.html +2 -2
- package/docs/calcOrdersSummarySimple.mjs.html +7 -4
- package/docs/calcSummary.mjs.html +2 -2
- package/docs/closeAndSummaryOrders.mjs.html +2 -2
- package/docs/genKLinesTpSl.mjs.html +2 -2
- package/docs/genReport.mjs.html +2 -2
- package/docs/genReportCore.mjs.html +2 -2
- package/docs/global.html +667 -3
- package/docs/index.html +2 -2
- package/docs/loadKLinesTpSl.mjs.html +4 -5
- package/docs/runStrategies.mjs.html +2 -2
- package/docs/runStrategiesAndBacktest.mjs.html +2 -2
- package/docs/runStrategy.mjs.html +2 -2
- package/docs/settleOrderPnl.mjs.html +100 -0
- package/package.json +3 -3
- package/src/WTradeBacktest.mjs +2 -0
- package/src/buildStrategyFastSession.mjs +293 -0
- package/src/calcOrdersSummarySimple.mjs +5 -2
- package/src/loadKLinesTpSl.mjs +2 -3
- package/src/settleOrderPnl.mjs +28 -0
- package/test/unit-WTradeBacktest.test.mjs +1 -0
- package/test/unit-buildStrategyFastSession.test.mjs +298 -0
package/docs/global.html
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<nav >
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#buildKLinesTpSl">buildKLinesTpSl</a></li><li><a href="global.html#calcOrders">calcOrders</a></li><li><a href="global.html#calcOrdersRatio">calcOrdersRatio</a></li><li><a href="global.html#calcOrdersSummary">calcOrdersSummary</a></li><li><a href="global.html#calcOrdersSummarySimple">calcOrdersSummarySimple</a></li><li><a href="global.html#calcSummary">calcSummary</a></li><li><a href="global.html#closeAndSummaryOrders">closeAndSummaryOrders</a></li><li><a href="global.html#genKLinesTpSl">genKLinesTpSl</a></li><li><a href="global.html#genReport">genReport</a></li><li><a href="global.html#genReportCore">genReportCore</a></li><li><a href="global.html#loadKLinesTpSl">loadKLinesTpSl</a></li><li><a href="global.html#runStrategies">runStrategies</a></li><li><a href="global.html#runStrategiesAndBacktest">runStrategiesAndBacktest</a></li><li><a href="global.html#runStrategy">runStrategy</a></li></ul>
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#buildKLinesTpSl">buildKLinesTpSl</a></li><li><a href="global.html#buildStrategyFastSession">buildStrategyFastSession</a></li><li><a href="global.html#calcOrders">calcOrders</a></li><li><a href="global.html#calcOrdersRatio">calcOrdersRatio</a></li><li><a href="global.html#calcOrdersSummary">calcOrdersSummary</a></li><li><a href="global.html#calcOrdersSummarySimple">calcOrdersSummarySimple</a></li><li><a href="global.html#calcSummary">calcSummary</a></li><li><a href="global.html#closeAndSummaryOrders">closeAndSummaryOrders</a></li><li><a href="global.html#genKLinesTpSl">genKLinesTpSl</a></li><li><a href="global.html#genReport">genReport</a></li><li><a href="global.html#genReportCore">genReportCore</a></li><li><a href="global.html#loadKLinesTpSl">loadKLinesTpSl</a></li><li><a href="global.html#runStrategies">runStrategies</a></li><li><a href="global.html#runStrategiesAndBacktest">runStrategiesAndBacktest</a></li><li><a href="global.html#runStrategy">runStrategy</a></li><li><a href="global.html#settleOrderPnl">settleOrderPnl</a></li></ul>
|
|
33
33
|
|
|
34
34
|
</nav>
|
|
35
35
|
|
|
@@ -680,6 +680,407 @@ console.log(r.bars['2020-01-01T12:00:00'])
|
|
|
680
680
|
|
|
681
681
|
|
|
682
682
|
|
|
683
|
+
<h4 class="name" id="buildStrategyFastSession"><span class="type-signature"></span>buildStrategyFastSession<span class="signature">(ott, opt)</span><span class="type-signature"> → {Object}</span></h4>
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
<dl class="details">
|
|
691
|
+
|
|
692
|
+
<dt class="tag-description">Description:</dt>
|
|
693
|
+
<dd class="tag-description"><ul class="dummy"><li><p>建立策略快速評估session,供求解熱路徑(如RGA/PSO目標函數)重複評估同一K線窗之不同條件組合</p>
|
|
694
|
+
<p>建置期一次攤提runStrategy每次呼叫都要重建的不變量: 各因子{time,param}序列轉為K棒對位Float64Array(缺值填NaN)、各(tp,sl)組合之first-touch預算表(genKLinesTpSl,惰性建置+Map快取)
|
|
695
|
+
評估期單迴圈逐棒判斷conds觸發並沿calcOrders同式結算(settleOrderPnl),摘要直接以calcOrdersSummarySimple計算,與官方全鏈(runStrategy→calcOrders→calcOrdersSummary)對應欄位嚴格相等
|
|
696
|
+
觸發語義與runStrategy等價: 任一cond序列於該棒缺值(NaN)即整棒跳過(等同僅於全部cond序列皆有值之共同時間點判斷)、'and'組須全真且'or'組至少一真、sym為'>'比大於否則比小於
|
|
697
|
+
序列param須為有限數值,缺值以該時間點不存在表示; opt.mode非'long'或'short'、arrOhlc或serieses無效時throw; evaluate之conds非有效陣列(含空陣列, 同runStrategy)或cond.key不在serieses時throw</p>
|
|
698
|
+
<p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-backtest/blob/master/test/unit-WTradeBacktest.test.mjs">Github</a></p></li></ul></dd>
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
<dt class="tag-source">Source:</dt>
|
|
703
|
+
<dd class="tag-source"><ul class="dummy"><li>
|
|
704
|
+
<a href="buildStrategyFastSession.mjs.html">buildStrategyFastSession.mjs</a>, <a href="buildStrategyFastSession.mjs.html#line63">line 63</a>
|
|
705
|
+
</li></ul></dd>
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
</dl>
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
<h5 class="h5-examples">Example</h5>
|
|
750
|
+
|
|
751
|
+
<pre class="prettyprint"><code>let arrOhlc = [
|
|
752
|
+
{ time: '2020-01-01T00:00:00', Open: 100, High: 101, Low: 99, Close: 100 },
|
|
753
|
+
{ time: '2020-01-01T04:00:00', Open: 100, High: 106, Low: 100, Close: 105 },
|
|
754
|
+
{ time: '2020-01-01T08:00:00', Open: 105, High: 107, Low: 102, Close: 103 },
|
|
755
|
+
{ time: '2020-01-01T12:00:00', Open: 103, High: 104, Low: 94, Close: 95 },
|
|
756
|
+
{ time: '2020-01-01T16:00:00', Open: 95, High: 98, Low: 92, Close: 93 },
|
|
757
|
+
{ time: '2020-01-01T20:00:00', Open: 93, High: 99, Low: 95, Close: 97 },
|
|
758
|
+
]
|
|
759
|
+
|
|
760
|
+
let arrSig = [
|
|
761
|
+
{ time: '2020-01-01T00:00:00', param: 1 },
|
|
762
|
+
{ time: '2020-01-01T04:00:00', param: 0 },
|
|
763
|
+
{ time: '2020-01-01T08:00:00', param: 1 },
|
|
764
|
+
{ time: '2020-01-01T12:00:00', param: 0 },
|
|
765
|
+
{ time: '2020-01-01T16:00:00', param: 0 },
|
|
766
|
+
{ time: '2020-01-01T20:00:00', param: 0 },
|
|
767
|
+
]
|
|
768
|
+
|
|
769
|
+
let session = buildStrategyFastSession(ott, {
|
|
770
|
+
arrOhlc,
|
|
771
|
+
mode: 'long',
|
|
772
|
+
serieses: { sig: arrSig },
|
|
773
|
+
})
|
|
774
|
+
|
|
775
|
+
let sm = session.evaluate({
|
|
776
|
+
conds: [{ key: 'sig', sym: '>', th: 0.5, opr: 'and' }],
|
|
777
|
+
tp: 0.05,
|
|
778
|
+
sl: 0.03,
|
|
779
|
+
settings: { uIni: 1000, uTrade: 100, rFee: 0.0005 },
|
|
780
|
+
})
|
|
781
|
+
console.log(sm.numTrade, sm.rWin, sm.uEquityFinal)
|
|
782
|
+
// => 2 50.00% 1001.8</code></pre>
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
<h5 class="h5-parameters">Parameters:</h5>
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
<table class="params">
|
|
791
|
+
<thead>
|
|
792
|
+
<tr>
|
|
793
|
+
|
|
794
|
+
<th>Name</th>
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
<th>Type</th>
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
<th class="last">Description</th>
|
|
804
|
+
</tr>
|
|
805
|
+
</thead>
|
|
806
|
+
|
|
807
|
+
<tbody>
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
<tr>
|
|
811
|
+
|
|
812
|
+
<td class="name"><code>ott</code></td>
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
<td class="type">
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
<span class="param-type">function</span>
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
</td>
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
<td class="description last"><p>輸入時區時間函數,傳入時間字串回傳dayjs時間物件(可用src/ott.mjs或自行以dayjs包裝)</p></td>
|
|
830
|
+
</tr>
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
<tr>
|
|
835
|
+
|
|
836
|
+
<td class="name"><code>opt</code></td>
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
<td class="type">
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
<span class="param-type">Object</span>
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
</td>
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
<td class="description last"><p>輸入設定物件</p>
|
|
854
|
+
<h6>Properties</h6>
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
<table class="params">
|
|
858
|
+
<thead>
|
|
859
|
+
<tr>
|
|
860
|
+
|
|
861
|
+
<th>Name</th>
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
<th>Type</th>
|
|
865
|
+
|
|
866
|
+
|
|
867
|
+
<th>Attributes</th>
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
<th>Default</th>
|
|
872
|
+
|
|
873
|
+
|
|
874
|
+
<th class="last">Description</th>
|
|
875
|
+
</tr>
|
|
876
|
+
</thead>
|
|
877
|
+
|
|
878
|
+
<tbody>
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
<tr>
|
|
882
|
+
|
|
883
|
+
<td class="name"><code>arrOhlc</code></td>
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
<td class="type">
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
<span class="param-type">Array</span>
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
</td>
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
<td class="attributes">
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
</td>
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
<td class="default">
|
|
908
|
+
|
|
909
|
+
</td>
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
<td class="description last"><p>輸入K線陣列,各元素需含time(秒時間字串)、Close、High、Low欄位,且依時間由小至大排序,與runStrategy之funGetSeries(keyOhlc)同一份</p></td>
|
|
913
|
+
</tr>
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
<tr>
|
|
918
|
+
|
|
919
|
+
<td class="name"><code>mode</code></td>
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
<td class="type">
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
<span class="param-type">String</span>
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
</td>
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
<td class="attributes">
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
</td>
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
<td class="default">
|
|
944
|
+
|
|
945
|
+
</td>
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
<td class="description last"><p>輸入交易方向字串,'long'或'short'</p></td>
|
|
949
|
+
</tr>
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
953
|
+
<tr>
|
|
954
|
+
|
|
955
|
+
<td class="name"><code>serieses</code></td>
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
<td class="type">
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
<span class="param-type">Object</span>
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
</td>
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
<td class="attributes">
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
</td>
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
<td class="default">
|
|
980
|
+
|
|
981
|
+
</td>
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
<td class="description last"><p>輸入因子序列物件,key為因子名稱,value為{time,param}陣列,param須為有限數值</p></td>
|
|
985
|
+
</tr>
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
<tr>
|
|
990
|
+
|
|
991
|
+
<td class="name"><code>tpsls</code></td>
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
<td class="type">
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
<span class="param-type">Array</span>
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
</td>
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
<td class="attributes">
|
|
1006
|
+
|
|
1007
|
+
<optional><br>
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
</td>
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
<td class="default">
|
|
1018
|
+
|
|
1019
|
+
<code>[]</code>
|
|
1020
|
+
|
|
1021
|
+
</td>
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
<td class="description last"><p>輸入預建first-touch表之{tp,sl}陣列,未列組合於evaluate時惰性建置,預設[]</p></td>
|
|
1025
|
+
</tr>
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
</tbody>
|
|
1029
|
+
</table>
|
|
1030
|
+
|
|
1031
|
+
</td>
|
|
1032
|
+
</tr>
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
</tbody>
|
|
1036
|
+
</table>
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
<h5 class="h5-returns">Returns:</h5>
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
<div class="param-desc">
|
|
1057
|
+
<p>回傳session物件,內含evaluate({conds,tp,sl,settings},opt)評估函數,conds各元素為{key,sym,th,opr}(與runStrategy同構),settings可給uIni(預設1000)、uTrade(預設1)、rFee(預設0.0005),evaluate預設回傳calcOrdersSummarySimple同構摘要物件,evaluate之opt.withOrders為true時回傳{orders,summary}(orders與loadKLinesTpSl之ordersFromBars同構,供除錯對照之慢速路徑)</p>
|
|
1058
|
+
</div>
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
<dl class="param-type">
|
|
1063
|
+
<dt>
|
|
1064
|
+
Type
|
|
1065
|
+
</dt>
|
|
1066
|
+
<dd>
|
|
1067
|
+
|
|
1068
|
+
<span class="param-type">Object</span>
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
|
|
1072
|
+
</dd>
|
|
1073
|
+
</dl>
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
|
|
683
1084
|
<h4 class="name" id="calcOrders"><span class="type-signature type-signature-async">(async) </span>calcOrders<span class="signature">(arrOhlc, orders, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise}</span></h4>
|
|
684
1085
|
|
|
685
1086
|
|
|
@@ -4255,7 +4656,7 @@ fpJson非有效字串或非檔案時throw</p>
|
|
|
4255
4656
|
|
|
4256
4657
|
<dt class="tag-source">Source:</dt>
|
|
4257
4658
|
<dd class="tag-source"><ul class="dummy"><li>
|
|
4258
|
-
<a href="loadKLinesTpSl.mjs.html">loadKLinesTpSl.mjs</a>, <a href="loadKLinesTpSl.mjs.html#
|
|
4659
|
+
<a href="loadKLinesTpSl.mjs.html">loadKLinesTpSl.mjs</a>, <a href="loadKLinesTpSl.mjs.html#line37">line 37</a>
|
|
4259
4660
|
</li></ul></dd>
|
|
4260
4661
|
|
|
4261
4662
|
|
|
@@ -5897,6 +6298,269 @@ console.log(r.summary.numTrade, r.summary.rWin, r.summary.uEquityFinal)
|
|
|
5897
6298
|
|
|
5898
6299
|
|
|
5899
6300
|
|
|
6301
|
+
|
|
6302
|
+
|
|
6303
|
+
|
|
6304
|
+
|
|
6305
|
+
<h4 class="name" id="settleOrderPnl"><span class="type-signature"></span>settleOrderPnl<span class="signature">(mode, uTrade, priceStart, priceEnd, uFee)</span><span class="type-signature"> → {Number}</span></h4>
|
|
6306
|
+
|
|
6307
|
+
|
|
6308
|
+
|
|
6309
|
+
|
|
6310
|
+
|
|
6311
|
+
|
|
6312
|
+
<dl class="details">
|
|
6313
|
+
|
|
6314
|
+
<dt class="tag-description">Description:</dt>
|
|
6315
|
+
<dd class="tag-description"><ul class="dummy"><li><p>計算單筆訂單之淨盈虧金額(USDT)</p>
|
|
6316
|
+
<p>結算公式與calcOrders逐字對齊(bit-exact): long為uTrade*(priceEnd/priceStart)-uTrade-2<em>uFee,short為(priceStart-priceEnd)</em>(uTrade/priceStart)-2*uFee
|
|
6317
|
+
供loadKLinesTpSl之ordersFromBars與buildStrategyFastSession共用,避免套件內出現第三份手抄公式</p>
|
|
6318
|
+
<p>Unit Test: <a href="https://github.com/yuda-lyu/w-trade-backtest/blob/master/test/unit-WTradeBacktest.test.mjs">Github</a></p></li></ul></dd>
|
|
6319
|
+
|
|
6320
|
+
|
|
6321
|
+
|
|
6322
|
+
<dt class="tag-source">Source:</dt>
|
|
6323
|
+
<dd class="tag-source"><ul class="dummy"><li>
|
|
6324
|
+
<a href="settleOrderPnl.mjs.html">settleOrderPnl.mjs</a>, <a href="settleOrderPnl.mjs.html#line21">line 21</a>
|
|
6325
|
+
</li></ul></dd>
|
|
6326
|
+
|
|
6327
|
+
|
|
6328
|
+
|
|
6329
|
+
|
|
6330
|
+
|
|
6331
|
+
|
|
6332
|
+
|
|
6333
|
+
|
|
6334
|
+
|
|
6335
|
+
|
|
6336
|
+
|
|
6337
|
+
|
|
6338
|
+
|
|
6339
|
+
|
|
6340
|
+
|
|
6341
|
+
|
|
6342
|
+
|
|
6343
|
+
|
|
6344
|
+
|
|
6345
|
+
|
|
6346
|
+
|
|
6347
|
+
|
|
6348
|
+
|
|
6349
|
+
|
|
6350
|
+
|
|
6351
|
+
|
|
6352
|
+
|
|
6353
|
+
|
|
6354
|
+
|
|
6355
|
+
|
|
6356
|
+
|
|
6357
|
+
</dl>
|
|
6358
|
+
|
|
6359
|
+
|
|
6360
|
+
|
|
6361
|
+
|
|
6362
|
+
|
|
6363
|
+
|
|
6364
|
+
|
|
6365
|
+
|
|
6366
|
+
|
|
6367
|
+
|
|
6368
|
+
|
|
6369
|
+
<h5 class="h5-examples">Example</h5>
|
|
6370
|
+
|
|
6371
|
+
<pre class="prettyprint"><code>console.log(settleOrderPnl('long', 100, 100, 105, 0.05))
|
|
6372
|
+
// => 4.9</code></pre>
|
|
6373
|
+
|
|
6374
|
+
|
|
6375
|
+
|
|
6376
|
+
|
|
6377
|
+
<h5 class="h5-parameters">Parameters:</h5>
|
|
6378
|
+
|
|
6379
|
+
|
|
6380
|
+
<table class="params">
|
|
6381
|
+
<thead>
|
|
6382
|
+
<tr>
|
|
6383
|
+
|
|
6384
|
+
<th>Name</th>
|
|
6385
|
+
|
|
6386
|
+
|
|
6387
|
+
<th>Type</th>
|
|
6388
|
+
|
|
6389
|
+
|
|
6390
|
+
|
|
6391
|
+
|
|
6392
|
+
|
|
6393
|
+
<th class="last">Description</th>
|
|
6394
|
+
</tr>
|
|
6395
|
+
</thead>
|
|
6396
|
+
|
|
6397
|
+
<tbody>
|
|
6398
|
+
|
|
6399
|
+
|
|
6400
|
+
<tr>
|
|
6401
|
+
|
|
6402
|
+
<td class="name"><code>mode</code></td>
|
|
6403
|
+
|
|
6404
|
+
|
|
6405
|
+
<td class="type">
|
|
6406
|
+
|
|
6407
|
+
|
|
6408
|
+
<span class="param-type">String</span>
|
|
6409
|
+
|
|
6410
|
+
|
|
6411
|
+
|
|
6412
|
+
|
|
6413
|
+
</td>
|
|
6414
|
+
|
|
6415
|
+
|
|
6416
|
+
|
|
6417
|
+
|
|
6418
|
+
|
|
6419
|
+
<td class="description last"><p>輸入交易方向字串,'long'或'short'</p></td>
|
|
6420
|
+
</tr>
|
|
6421
|
+
|
|
6422
|
+
|
|
6423
|
+
|
|
6424
|
+
<tr>
|
|
6425
|
+
|
|
6426
|
+
<td class="name"><code>uTrade</code></td>
|
|
6427
|
+
|
|
6428
|
+
|
|
6429
|
+
<td class="type">
|
|
6430
|
+
|
|
6431
|
+
|
|
6432
|
+
<span class="param-type">Number</span>
|
|
6433
|
+
|
|
6434
|
+
|
|
6435
|
+
|
|
6436
|
+
|
|
6437
|
+
</td>
|
|
6438
|
+
|
|
6439
|
+
|
|
6440
|
+
|
|
6441
|
+
|
|
6442
|
+
|
|
6443
|
+
<td class="description last"><p>輸入下單金額(USDT)</p></td>
|
|
6444
|
+
</tr>
|
|
6445
|
+
|
|
6446
|
+
|
|
6447
|
+
|
|
6448
|
+
<tr>
|
|
6449
|
+
|
|
6450
|
+
<td class="name"><code>priceStart</code></td>
|
|
6451
|
+
|
|
6452
|
+
|
|
6453
|
+
<td class="type">
|
|
6454
|
+
|
|
6455
|
+
|
|
6456
|
+
<span class="param-type">Number</span>
|
|
6457
|
+
|
|
6458
|
+
|
|
6459
|
+
|
|
6460
|
+
|
|
6461
|
+
</td>
|
|
6462
|
+
|
|
6463
|
+
|
|
6464
|
+
|
|
6465
|
+
|
|
6466
|
+
|
|
6467
|
+
<td class="description last"><p>輸入進場價格</p></td>
|
|
6468
|
+
</tr>
|
|
6469
|
+
|
|
6470
|
+
|
|
6471
|
+
|
|
6472
|
+
<tr>
|
|
6473
|
+
|
|
6474
|
+
<td class="name"><code>priceEnd</code></td>
|
|
6475
|
+
|
|
6476
|
+
|
|
6477
|
+
<td class="type">
|
|
6478
|
+
|
|
6479
|
+
|
|
6480
|
+
<span class="param-type">Number</span>
|
|
6481
|
+
|
|
6482
|
+
|
|
6483
|
+
|
|
6484
|
+
|
|
6485
|
+
</td>
|
|
6486
|
+
|
|
6487
|
+
|
|
6488
|
+
|
|
6489
|
+
|
|
6490
|
+
|
|
6491
|
+
<td class="description last"><p>輸入出場價格</p></td>
|
|
6492
|
+
</tr>
|
|
6493
|
+
|
|
6494
|
+
|
|
6495
|
+
|
|
6496
|
+
<tr>
|
|
6497
|
+
|
|
6498
|
+
<td class="name"><code>uFee</code></td>
|
|
6499
|
+
|
|
6500
|
+
|
|
6501
|
+
<td class="type">
|
|
6502
|
+
|
|
6503
|
+
|
|
6504
|
+
<span class="param-type">Number</span>
|
|
6505
|
+
|
|
6506
|
+
|
|
6507
|
+
|
|
6508
|
+
|
|
6509
|
+
</td>
|
|
6510
|
+
|
|
6511
|
+
|
|
6512
|
+
|
|
6513
|
+
|
|
6514
|
+
|
|
6515
|
+
<td class="description last"><p>輸入單邊手續費(USDT),結算扣2*uFee</p></td>
|
|
6516
|
+
</tr>
|
|
6517
|
+
|
|
6518
|
+
|
|
6519
|
+
</tbody>
|
|
6520
|
+
</table>
|
|
6521
|
+
|
|
6522
|
+
|
|
6523
|
+
|
|
6524
|
+
|
|
6525
|
+
|
|
6526
|
+
|
|
6527
|
+
|
|
6528
|
+
|
|
6529
|
+
|
|
6530
|
+
|
|
6531
|
+
|
|
6532
|
+
|
|
6533
|
+
|
|
6534
|
+
|
|
6535
|
+
|
|
6536
|
+
|
|
6537
|
+
<h5 class="h5-returns">Returns:</h5>
|
|
6538
|
+
|
|
6539
|
+
|
|
6540
|
+
<div class="param-desc">
|
|
6541
|
+
<p>回傳淨盈虧金額(USDT),含手續費</p>
|
|
6542
|
+
</div>
|
|
6543
|
+
|
|
6544
|
+
|
|
6545
|
+
|
|
6546
|
+
<dl class="param-type">
|
|
6547
|
+
<dt>
|
|
6548
|
+
Type
|
|
6549
|
+
</dt>
|
|
6550
|
+
<dd>
|
|
6551
|
+
|
|
6552
|
+
<span class="param-type">Number</span>
|
|
6553
|
+
|
|
6554
|
+
|
|
6555
|
+
|
|
6556
|
+
</dd>
|
|
6557
|
+
</dl>
|
|
6558
|
+
|
|
6559
|
+
|
|
6560
|
+
|
|
6561
|
+
|
|
6562
|
+
|
|
6563
|
+
|
|
5900
6564
|
|
|
5901
6565
|
|
|
5902
6566
|
|
|
@@ -5916,7 +6580,7 @@ console.log(r.summary.numTrade, r.summary.rWin, r.summary.uEquityFinal)
|
|
|
5916
6580
|
<br class="clear">
|
|
5917
6581
|
|
|
5918
6582
|
<footer>
|
|
5919
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
6583
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Tue Aug 18 2026 12:40:44 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
5920
6584
|
</footer>
|
|
5921
6585
|
|
|
5922
6586
|
<script>prettyPrint();</script>
|