@gbozee/ultimate 0.0.2-176 → 0.0.2-177
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/frontend-index.d.ts +106 -4
- package/dist/frontend-index.js +211 -25
- package/dist/index.cjs +256 -58
- package/dist/index.d.ts +132 -9
- package/dist/index.js +256 -58
- package/dist/mcp-server.cjs +256 -58
- package/dist/mcp-server.js +256 -58
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -54645,7 +54645,7 @@ class AppDatabase {
|
|
|
54645
54645
|
table: "positions_view",
|
|
54646
54646
|
params: {
|
|
54647
54647
|
filter: `symbol:lower="${symbol.toLowerCase()}" && p_account.owner:lower="${account.owner.toLowerCase()}" && p_account.exchange:lower="${account.exchange.toLowerCase()}"`,
|
|
54648
|
-
expand: "b_config, account_strategy, p_account, proxy"
|
|
54648
|
+
expand: "b_config, account_strategy, p_account, proxy, compound_instance.ref,support"
|
|
54649
54649
|
}
|
|
54650
54650
|
} : {
|
|
54651
54651
|
table: "positions",
|
|
@@ -55494,6 +55494,137 @@ __export(exports_exchange_account, {
|
|
|
55494
55494
|
// src/exchanges/binance/index.ts
|
|
55495
55495
|
var import_binance = __toESM(require_lib2(), 1);
|
|
55496
55496
|
|
|
55497
|
+
// src/helpers/distributions.ts
|
|
55498
|
+
function generateArithmetic(payload) {
|
|
55499
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f" } = payload;
|
|
55500
|
+
const difference = Math.abs(margin_range[1] - margin_range[0]);
|
|
55501
|
+
const spread = difference / risk_reward;
|
|
55502
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55503
|
+
const price = kind === "long" ? margin_range[1] - spread * i2 : margin_range[0] + spread * i2;
|
|
55504
|
+
return to_f(price, price_places);
|
|
55505
|
+
});
|
|
55506
|
+
}
|
|
55507
|
+
function generateGeometric(payload) {
|
|
55508
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", percent_change } = payload;
|
|
55509
|
+
const effectivePercentChange = percent_change ?? Math.abs(margin_range[1] / margin_range[0] - 1) / risk_reward;
|
|
55510
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55511
|
+
const price = kind === "long" ? margin_range[1] * Math.pow(1 - effectivePercentChange, i2) : margin_range[0] * Math.pow(1 + effectivePercentChange, i2);
|
|
55512
|
+
return to_f(price, price_places);
|
|
55513
|
+
});
|
|
55514
|
+
}
|
|
55515
|
+
function approximateInverseNormal(p) {
|
|
55516
|
+
p = Math.max(0.0001, Math.min(0.9999, p));
|
|
55517
|
+
if (p < 0.5) {
|
|
55518
|
+
const t2 = Math.sqrt(-2 * Math.log(p));
|
|
55519
|
+
const c0 = 2.515517, c1 = 0.802853, c2 = 0.010328;
|
|
55520
|
+
const d1 = 1.432788, d2 = 0.189269, d3 = 0.001308;
|
|
55521
|
+
return -(t2 - (c0 + c1 * t2 + c2 * t2 * t2) / (1 + d1 * t2 + d2 * t2 * t2 + d3 * t2 * t2 * t2));
|
|
55522
|
+
} else {
|
|
55523
|
+
const t2 = Math.sqrt(-2 * Math.log(1 - p));
|
|
55524
|
+
const c0 = 2.515517, c1 = 0.802853, c2 = 0.010328;
|
|
55525
|
+
const d1 = 1.432788, d2 = 0.189269, d3 = 0.001308;
|
|
55526
|
+
return t2 - (c0 + c1 * t2 + c2 * t2 * t2) / (1 + d1 * t2 + d2 * t2 * t2 + d3 * t2 * t2 * t2);
|
|
55527
|
+
}
|
|
55528
|
+
}
|
|
55529
|
+
function generateNormal(payload) {
|
|
55530
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", stdDevFactor = 6 } = payload;
|
|
55531
|
+
const mean = (margin_range[0] + margin_range[1]) / 2;
|
|
55532
|
+
const stdDev = Math.abs(margin_range[1] - margin_range[0]) / stdDevFactor;
|
|
55533
|
+
const skew = kind === "long" ? -0.2 : 0.2;
|
|
55534
|
+
const adjustedMean = mean + stdDev * skew;
|
|
55535
|
+
const entries = Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55536
|
+
const p = (i2 + 0.5) / (risk_reward + 1);
|
|
55537
|
+
const z2 = approximateInverseNormal(p);
|
|
55538
|
+
let price = adjustedMean + stdDev * z2;
|
|
55539
|
+
price = Math.max(margin_range[0], Math.min(margin_range[1], price));
|
|
55540
|
+
return to_f(price, price_places);
|
|
55541
|
+
});
|
|
55542
|
+
return entries.sort((a, b) => a - b);
|
|
55543
|
+
}
|
|
55544
|
+
function generateExponential(payload) {
|
|
55545
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", lambda } = payload;
|
|
55546
|
+
const range = Math.abs(margin_range[1] - margin_range[0]);
|
|
55547
|
+
const effectiveLambda = lambda || 2.5;
|
|
55548
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55549
|
+
const t2 = i2 / risk_reward;
|
|
55550
|
+
const exponentialProgress = 1 - Math.exp(-effectiveLambda * t2);
|
|
55551
|
+
const price = kind === "long" ? margin_range[1] - range * exponentialProgress : margin_range[0] + range * exponentialProgress;
|
|
55552
|
+
return to_f(price, price_places);
|
|
55553
|
+
});
|
|
55554
|
+
}
|
|
55555
|
+
function generateInverseExponential(payload) {
|
|
55556
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", curveFactor = 2 } = payload;
|
|
55557
|
+
const range = Math.abs(margin_range[1] - margin_range[0]);
|
|
55558
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55559
|
+
const t2 = i2 / risk_reward;
|
|
55560
|
+
const progress = (Math.exp(curveFactor * t2) - 1) / (Math.exp(curveFactor) - 1);
|
|
55561
|
+
const price = kind === "long" ? margin_range[1] - range * progress : margin_range[0] + range * progress;
|
|
55562
|
+
return to_f(price, price_places);
|
|
55563
|
+
});
|
|
55564
|
+
}
|
|
55565
|
+
function getEntries(params) {
|
|
55566
|
+
const {
|
|
55567
|
+
kind,
|
|
55568
|
+
distribution,
|
|
55569
|
+
margin_range,
|
|
55570
|
+
risk_reward,
|
|
55571
|
+
price_places = "%.1f",
|
|
55572
|
+
distribution_params = {}
|
|
55573
|
+
} = params;
|
|
55574
|
+
let entries = [];
|
|
55575
|
+
switch (distribution) {
|
|
55576
|
+
case "arithmetic":
|
|
55577
|
+
entries = generateArithmetic({
|
|
55578
|
+
margin_range,
|
|
55579
|
+
risk_reward,
|
|
55580
|
+
kind,
|
|
55581
|
+
price_places,
|
|
55582
|
+
percent_change: distribution_params.curveFactor
|
|
55583
|
+
});
|
|
55584
|
+
break;
|
|
55585
|
+
case "geometric":
|
|
55586
|
+
entries = generateGeometric({
|
|
55587
|
+
margin_range,
|
|
55588
|
+
risk_reward,
|
|
55589
|
+
kind,
|
|
55590
|
+
price_places,
|
|
55591
|
+
percent_change: distribution_params.curveFactor
|
|
55592
|
+
});
|
|
55593
|
+
break;
|
|
55594
|
+
case "normal":
|
|
55595
|
+
entries = generateNormal({
|
|
55596
|
+
margin_range,
|
|
55597
|
+
risk_reward,
|
|
55598
|
+
kind,
|
|
55599
|
+
price_places,
|
|
55600
|
+
stdDevFactor: distribution_params.stdDevFactor
|
|
55601
|
+
});
|
|
55602
|
+
break;
|
|
55603
|
+
case "exponential":
|
|
55604
|
+
entries = generateExponential({
|
|
55605
|
+
margin_range,
|
|
55606
|
+
risk_reward,
|
|
55607
|
+
kind,
|
|
55608
|
+
price_places,
|
|
55609
|
+
lambda: distribution_params.lambda
|
|
55610
|
+
});
|
|
55611
|
+
break;
|
|
55612
|
+
case "inverse-exponential":
|
|
55613
|
+
entries = generateInverseExponential({
|
|
55614
|
+
margin_range,
|
|
55615
|
+
risk_reward,
|
|
55616
|
+
kind,
|
|
55617
|
+
price_places,
|
|
55618
|
+
curveFactor: distribution_params.curveFactor
|
|
55619
|
+
});
|
|
55620
|
+
break;
|
|
55621
|
+
default:
|
|
55622
|
+
throw new Error(`Unknown distribution type: ${distribution}`);
|
|
55623
|
+
}
|
|
55624
|
+
return entries.sort((a, b) => a - b);
|
|
55625
|
+
}
|
|
55626
|
+
var distributions_default = getEntries;
|
|
55627
|
+
|
|
55497
55628
|
// src/helpers/optimizations.ts
|
|
55498
55629
|
function calculateTheoreticalKelly({
|
|
55499
55630
|
current_entry,
|
|
@@ -55763,6 +55894,10 @@ class Signal {
|
|
|
55763
55894
|
kelly_minimum_risk = 0.2;
|
|
55764
55895
|
kelly_func = "theoretical";
|
|
55765
55896
|
symbol;
|
|
55897
|
+
distribution = {
|
|
55898
|
+
long: "arithmetic",
|
|
55899
|
+
short: "geometric"
|
|
55900
|
+
};
|
|
55766
55901
|
constructor({
|
|
55767
55902
|
focus,
|
|
55768
55903
|
symbol,
|
|
@@ -55789,8 +55924,12 @@ class Signal {
|
|
|
55789
55924
|
kelly_prediction_model = "exponential",
|
|
55790
55925
|
kelly_confidence_factor = 0.6,
|
|
55791
55926
|
kelly_minimum_risk = 0.2,
|
|
55792
|
-
kelly_func = "theoretical"
|
|
55927
|
+
kelly_func = "theoretical",
|
|
55928
|
+
full_distribution
|
|
55793
55929
|
}) {
|
|
55930
|
+
if (full_distribution) {
|
|
55931
|
+
this.distribution = full_distribution;
|
|
55932
|
+
}
|
|
55794
55933
|
this.symbol = symbol;
|
|
55795
55934
|
this.minimum_size = minimum_size;
|
|
55796
55935
|
this.first_order_size = first_order_size;
|
|
@@ -55826,7 +55965,8 @@ class Signal {
|
|
|
55826
55965
|
kind = "long",
|
|
55827
55966
|
risk,
|
|
55828
55967
|
no_of_trades = 1,
|
|
55829
|
-
take_profit
|
|
55968
|
+
take_profit,
|
|
55969
|
+
distribution
|
|
55830
55970
|
}) {
|
|
55831
55971
|
let _stop_loss = stop_loss;
|
|
55832
55972
|
if (!_stop_loss && stop_percent) {
|
|
@@ -55835,16 +55975,22 @@ class Signal {
|
|
|
55835
55975
|
const percent_change = _stop_loss ? Math.max(current_price, _stop_loss) / Math.min(current_price, _stop_loss) - 1 : this.percent_change;
|
|
55836
55976
|
const _no_of_trades = no_of_trades || this.risk_reward;
|
|
55837
55977
|
let _resistance = current_price * Math.pow(1 + percent_change, 1);
|
|
55978
|
+
const simple_support = Math.min(current_price, stop_loss);
|
|
55979
|
+
const simple_resistance = Math.max(current_price, stop_loss);
|
|
55838
55980
|
const derivedConfig = {
|
|
55839
55981
|
...this,
|
|
55840
55982
|
percent_change,
|
|
55841
55983
|
focus: current_price,
|
|
55842
|
-
resistance: _resistance,
|
|
55984
|
+
resistance: distribution ? simple_resistance : _resistance,
|
|
55843
55985
|
risk_per_trade: risk / this.risk_reward,
|
|
55844
55986
|
minimum_pnl: pnl,
|
|
55845
55987
|
risk_reward: _no_of_trades,
|
|
55846
55988
|
take_profit: take_profit || this.take_profit,
|
|
55847
|
-
support: kind === "long" ? _stop_loss : this.support
|
|
55989
|
+
support: distribution ? simple_support : kind === "long" ? _stop_loss : this.support,
|
|
55990
|
+
full_distribution: distribution ? {
|
|
55991
|
+
...this.distribution,
|
|
55992
|
+
[kind]: distribution
|
|
55993
|
+
} : undefined
|
|
55848
55994
|
};
|
|
55849
55995
|
const instance = new Signal(derivedConfig);
|
|
55850
55996
|
if (kind === "short") {}
|
|
@@ -56060,12 +56206,31 @@ class Signal {
|
|
|
56060
56206
|
}
|
|
56061
56207
|
this.zone_risk = original;
|
|
56062
56208
|
}
|
|
56209
|
+
get_future_zones_simple({
|
|
56210
|
+
current_price,
|
|
56211
|
+
kind = "long",
|
|
56212
|
+
raw
|
|
56213
|
+
}) {
|
|
56214
|
+
const margin_zones = [this.support, this.resistance];
|
|
56215
|
+
const distribution = this.distribution ? this.distribution[kind] : "geometric";
|
|
56216
|
+
console.log("margin_zones", { margin_zones, distribution });
|
|
56217
|
+
let _kind = distribution === "inverse-exponential" ? kind === "long" ? "short" : "long" : kind;
|
|
56218
|
+
const entries = distributions_default({
|
|
56219
|
+
margin_range: margin_zones,
|
|
56220
|
+
kind: _kind,
|
|
56221
|
+
distribution,
|
|
56222
|
+
risk_reward: this.risk_reward,
|
|
56223
|
+
price_places: this.price_places
|
|
56224
|
+
});
|
|
56225
|
+
return entries.sort((a, b) => a - b);
|
|
56226
|
+
}
|
|
56063
56227
|
get_future_zones({
|
|
56064
56228
|
current_price,
|
|
56065
56229
|
kind = "long",
|
|
56066
56230
|
raw
|
|
56067
56231
|
}) {
|
|
56068
56232
|
if (raw) {}
|
|
56233
|
+
return this.get_future_zones_simple({ current_price, raw, kind });
|
|
56069
56234
|
const margin_range = this.get_margin_range(current_price, kind);
|
|
56070
56235
|
let margin_zones = this.get_margin_zones({ current_price });
|
|
56071
56236
|
let remaining_zones = margin_zones.filter((x) => JSON.stringify(x) != JSON.stringify(margin_range));
|
|
@@ -56724,7 +56889,9 @@ function buildConfig(app_config, {
|
|
|
56724
56889
|
kelly_confidence_factor = 0.95,
|
|
56725
56890
|
kelly_minimum_risk = 0.2,
|
|
56726
56891
|
kelly_prediction_model = "exponential",
|
|
56727
|
-
kelly_func = "theoretical"
|
|
56892
|
+
kelly_func = "theoretical",
|
|
56893
|
+
min_avg_size = 0,
|
|
56894
|
+
distribution
|
|
56728
56895
|
}) {
|
|
56729
56896
|
let fee = app_config.fee / 100;
|
|
56730
56897
|
let working_risk = risk || app_config.risk_per_trade;
|
|
@@ -56771,9 +56938,12 @@ function buildConfig(app_config, {
|
|
|
56771
56938
|
stop_loss: stop,
|
|
56772
56939
|
risk: working_risk,
|
|
56773
56940
|
kind: kind || app_config.kind,
|
|
56774
|
-
no_of_trades: trade_no
|
|
56941
|
+
no_of_trades: trade_no,
|
|
56942
|
+
distribution
|
|
56775
56943
|
}) || [] : [];
|
|
56776
|
-
|
|
56944
|
+
const new_trades = computeTotalAverageForEachTrade(result, config2);
|
|
56945
|
+
let filtered = new_trades.filter((o) => o.avg_size > min_avg_size);
|
|
56946
|
+
return computeTotalAverageForEachTrade(filtered, config2);
|
|
56777
56947
|
}
|
|
56778
56948
|
function buildAvg({
|
|
56779
56949
|
_trades,
|
|
@@ -56838,7 +57008,8 @@ function get_app_config_and_max_size(config2, payload) {
|
|
|
56838
57008
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
56839
57009
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
56840
57010
|
kelly_prediction_model: payload.kelly_prediction_model,
|
|
56841
|
-
kelly_func: payload.kelly_func
|
|
57011
|
+
kelly_func: payload.kelly_func,
|
|
57012
|
+
distribution: payload.distribution
|
|
56842
57013
|
});
|
|
56843
57014
|
const max_size = initialResult[0]?.avg_size;
|
|
56844
57015
|
const last_value = initialResult[0];
|
|
@@ -56876,7 +57047,8 @@ function buildAppConfig(config2, payload) {
|
|
|
56876
57047
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
56877
57048
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
56878
57049
|
kelly_prediction_model: payload.kelly_prediction_model,
|
|
56879
|
-
kelly_func: payload.kelly_func
|
|
57050
|
+
kelly_func: payload.kelly_func,
|
|
57051
|
+
distribution: payload.distribution
|
|
56880
57052
|
});
|
|
56881
57053
|
app_config.max_size = max_size;
|
|
56882
57054
|
app_config.entry = payload.entry || app_config.entry;
|
|
@@ -56893,7 +57065,7 @@ function buildAppConfig(config2, payload) {
|
|
|
56893
57065
|
return app_config;
|
|
56894
57066
|
}
|
|
56895
57067
|
function getOptimumStopAndRisk(app_config, params) {
|
|
56896
|
-
const { max_size, target_stop } = params;
|
|
57068
|
+
const { max_size, target_stop, distribution } = params;
|
|
56897
57069
|
const isLong = app_config.kind === "long";
|
|
56898
57070
|
const stopRange = Math.abs(app_config.entry - target_stop) * 0.5;
|
|
56899
57071
|
let low_stop = isLong ? target_stop - stopRange : Math.max(target_stop - stopRange, app_config.entry);
|
|
@@ -56916,7 +57088,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
56916
57088
|
increase: true,
|
|
56917
57089
|
gap: app_config.gap,
|
|
56918
57090
|
price_places: app_config.price_places,
|
|
56919
|
-
decimal_places: app_config.decimal_places
|
|
57091
|
+
decimal_places: app_config.decimal_places,
|
|
57092
|
+
distribution
|
|
56920
57093
|
});
|
|
56921
57094
|
if (result.length === 0) {
|
|
56922
57095
|
if (isLong) {
|
|
@@ -56970,7 +57143,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
56970
57143
|
increase: true,
|
|
56971
57144
|
gap: app_config.gap,
|
|
56972
57145
|
price_places: app_config.price_places,
|
|
56973
|
-
decimal_places: app_config.decimal_places
|
|
57146
|
+
decimal_places: app_config.decimal_places,
|
|
57147
|
+
distribution
|
|
56974
57148
|
});
|
|
56975
57149
|
if (result.length === 0) {
|
|
56976
57150
|
high_risk = mid_risk;
|
|
@@ -57015,7 +57189,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
57015
57189
|
increase: true,
|
|
57016
57190
|
gap: app_config.gap,
|
|
57017
57191
|
price_places: app_config.price_places,
|
|
57018
|
-
decimal_places: app_config.decimal_places
|
|
57192
|
+
decimal_places: app_config.decimal_places,
|
|
57193
|
+
distribution
|
|
57019
57194
|
});
|
|
57020
57195
|
if (result.length === 0)
|
|
57021
57196
|
continue;
|
|
@@ -57138,7 +57313,8 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
57138
57313
|
}, {
|
|
57139
57314
|
entry: payload.entry,
|
|
57140
57315
|
stop: payload.stop,
|
|
57141
|
-
kind: position2.kind
|
|
57316
|
+
kind: position2.kind,
|
|
57317
|
+
distribution: payload.distribution
|
|
57142
57318
|
});
|
|
57143
57319
|
current_app_config.max_size = max_size;
|
|
57144
57320
|
current_app_config.last_value = last_value;
|
|
@@ -57153,7 +57329,8 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
57153
57329
|
increase: true,
|
|
57154
57330
|
gap: current_app_config.gap,
|
|
57155
57331
|
price_places: current_app_config.price_places,
|
|
57156
|
-
decimal_places: current_app_config.decimal_places
|
|
57332
|
+
decimal_places: current_app_config.decimal_places,
|
|
57333
|
+
distribution: payload.distribution
|
|
57157
57334
|
});
|
|
57158
57335
|
if (full_trades.length === 0) {
|
|
57159
57336
|
high_risk = mid_risk;
|
|
@@ -57217,7 +57394,8 @@ function determineOptimumReward(payload) {
|
|
|
57217
57394
|
increase = true,
|
|
57218
57395
|
low_range = 1,
|
|
57219
57396
|
high_range = 199,
|
|
57220
|
-
target_loss
|
|
57397
|
+
target_loss,
|
|
57398
|
+
distribution
|
|
57221
57399
|
} = payload;
|
|
57222
57400
|
const criterion = app_config.strategy || "quantity";
|
|
57223
57401
|
const risk_rewards = createArray(low_range, high_range, 1);
|
|
@@ -57231,7 +57409,8 @@ function determineOptimumReward(payload) {
|
|
|
57231
57409
|
increase,
|
|
57232
57410
|
kind: app_config.kind,
|
|
57233
57411
|
gap: app_config.gap,
|
|
57234
|
-
decimal_places: app_config.decimal_places
|
|
57412
|
+
decimal_places: app_config.decimal_places,
|
|
57413
|
+
distribution
|
|
57235
57414
|
});
|
|
57236
57415
|
let total = 0;
|
|
57237
57416
|
let max = -Infinity;
|
|
@@ -57396,14 +57575,17 @@ function determineOptimumRisk(config2, payload, params) {
|
|
|
57396
57575
|
};
|
|
57397
57576
|
}
|
|
57398
57577
|
function computeRiskReward(payload) {
|
|
57399
|
-
const { app_config, entry, stop, risk_per_trade, target_loss } = payload;
|
|
57578
|
+
const { app_config, entry, stop, risk_per_trade, target_loss, distribution } = payload;
|
|
57400
57579
|
const kind = entry > stop ? "long" : "short";
|
|
57401
57580
|
app_config.kind = kind;
|
|
57402
57581
|
app_config.entry = entry;
|
|
57403
57582
|
app_config.stop = stop;
|
|
57404
57583
|
app_config.risk_per_trade = risk_per_trade;
|
|
57405
|
-
const result = determineOptimumReward({
|
|
57406
|
-
|
|
57584
|
+
const result = determineOptimumReward({
|
|
57585
|
+
app_config,
|
|
57586
|
+
target_loss,
|
|
57587
|
+
distribution
|
|
57588
|
+
});
|
|
57407
57589
|
return result;
|
|
57408
57590
|
}
|
|
57409
57591
|
function getRiskReward(payload) {
|
|
@@ -57413,21 +57595,24 @@ function getRiskReward(payload) {
|
|
|
57413
57595
|
risk,
|
|
57414
57596
|
global_config,
|
|
57415
57597
|
force_exact_risk = false,
|
|
57416
|
-
target_loss
|
|
57598
|
+
target_loss,
|
|
57599
|
+
distribution
|
|
57417
57600
|
} = payload;
|
|
57418
57601
|
const { entries, last_value, ...app_config } = buildAppConfig(global_config, {
|
|
57419
57602
|
entry,
|
|
57420
57603
|
stop,
|
|
57421
57604
|
risk_reward: 30,
|
|
57422
57605
|
risk,
|
|
57423
|
-
symbol: global_config.symbol
|
|
57606
|
+
symbol: global_config.symbol,
|
|
57607
|
+
distribution
|
|
57424
57608
|
});
|
|
57425
57609
|
const risk_reward = computeRiskReward({
|
|
57426
57610
|
app_config,
|
|
57427
57611
|
entry,
|
|
57428
57612
|
stop,
|
|
57429
57613
|
risk_per_trade: risk,
|
|
57430
|
-
target_loss
|
|
57614
|
+
target_loss,
|
|
57615
|
+
distribution
|
|
57431
57616
|
});
|
|
57432
57617
|
if (force_exact_risk) {
|
|
57433
57618
|
const new_risk_per_trade = determineOptimumRisk(global_config, {
|
|
@@ -57435,7 +57620,8 @@ function getRiskReward(payload) {
|
|
|
57435
57620
|
stop,
|
|
57436
57621
|
risk_reward,
|
|
57437
57622
|
risk,
|
|
57438
|
-
symbol: global_config.symbol
|
|
57623
|
+
symbol: global_config.symbol,
|
|
57624
|
+
distribution
|
|
57439
57625
|
}, {
|
|
57440
57626
|
highest_risk: risk
|
|
57441
57627
|
}).optimal_risk;
|
|
@@ -57890,7 +58076,7 @@ function constructAppConfig(payload) {
|
|
|
57890
58076
|
kelly_minimum_risk: kelly_config?.kelly_minimum_risk ?? kelly?.kelly_minimum_risk,
|
|
57891
58077
|
kelly_prediction_model: kelly_config?.kelly_prediction_model ?? kelly?.kelly_prediction_model
|
|
57892
58078
|
};
|
|
57893
|
-
const appConfig = buildAppConfig(global_config, options);
|
|
58079
|
+
const { entries: _entries, ...appConfig } = buildAppConfig(global_config, options);
|
|
57894
58080
|
return appConfig;
|
|
57895
58081
|
}
|
|
57896
58082
|
function generateDangerousConfig(payload) {
|
|
@@ -60888,6 +61074,19 @@ class ExchangePosition {
|
|
|
60888
61074
|
const { p_account } = this.instance.expand;
|
|
60889
61075
|
return p_account;
|
|
60890
61076
|
}
|
|
61077
|
+
get compound() {
|
|
61078
|
+
const { compound_instance } = this.instance.expand;
|
|
61079
|
+
if (compound_instance) {
|
|
61080
|
+
const { ref } = compound_instance.expand;
|
|
61081
|
+
const profit_percent = ref.profit_percent / 100;
|
|
61082
|
+
return {
|
|
61083
|
+
...compound_instance,
|
|
61084
|
+
profit_percent,
|
|
61085
|
+
amount_to_risk: to_f(compound_instance.risk * profit_percent, "%.2f")
|
|
61086
|
+
};
|
|
61087
|
+
}
|
|
61088
|
+
return compound_instance;
|
|
61089
|
+
}
|
|
60891
61090
|
async getProxyForAccount() {
|
|
60892
61091
|
if (this.instance.expand.proxy) {
|
|
60893
61092
|
const result = this.instance.expand.proxy;
|
|
@@ -61013,7 +61212,8 @@ class ExchangePosition {
|
|
|
61013
61212
|
place,
|
|
61014
61213
|
raw: payload.raw,
|
|
61015
61214
|
use_current,
|
|
61016
|
-
stop_percent: config2.stop_percent || 100
|
|
61215
|
+
stop_percent: config2.stop_percent || 100,
|
|
61216
|
+
distribution: config2.distribution
|
|
61017
61217
|
});
|
|
61018
61218
|
}
|
|
61019
61219
|
}
|
|
@@ -61047,7 +61247,8 @@ class ExchangePosition {
|
|
|
61047
61247
|
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
61048
61248
|
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
61049
61249
|
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
61050
|
-
kelly_func: config2.kelly?.kelly_func
|
|
61250
|
+
kelly_func: config2.kelly?.kelly_func,
|
|
61251
|
+
distribution: config2.distribution
|
|
61051
61252
|
}, false);
|
|
61052
61253
|
if (payload.raw) {
|
|
61053
61254
|
let actual_orders_to_buy = await this.determineAmountToBuy({
|
|
@@ -61170,7 +61371,8 @@ class ExchangePosition {
|
|
|
61170
61371
|
kelly_confidence_factor: solution.kelly_confidence_factor,
|
|
61171
61372
|
kelly_minimum_risk: solution.kelly_minimum_risk,
|
|
61172
61373
|
kelly_prediction_model: solution.kelly_prediction_model,
|
|
61173
|
-
kelly_func: solution.kelly_func
|
|
61374
|
+
kelly_func: solution.kelly_func,
|
|
61375
|
+
distribution: solution.distribution
|
|
61174
61376
|
};
|
|
61175
61377
|
const trades = sortedBuildConfig(app_config, options);
|
|
61176
61378
|
const entry_orders = {
|
|
@@ -61562,6 +61764,7 @@ class ExchangePosition {
|
|
|
61562
61764
|
});
|
|
61563
61765
|
}
|
|
61564
61766
|
async generate_config_params(payload) {
|
|
61767
|
+
const db_config = await this.getConfig();
|
|
61565
61768
|
const { entry, stop, risk_reward, risk, with_trades = false } = payload;
|
|
61566
61769
|
const symbol = this.symbol;
|
|
61567
61770
|
const app_config = await this.buildAppConfig({
|
|
@@ -61594,7 +61797,8 @@ class ExchangePosition {
|
|
|
61594
61797
|
avg_size: 0,
|
|
61595
61798
|
neg_pnl: 0,
|
|
61596
61799
|
min_size: app_config2.min_size,
|
|
61597
|
-
symbol
|
|
61800
|
+
symbol,
|
|
61801
|
+
distribution: db_config.distribution
|
|
61598
61802
|
}, false);
|
|
61599
61803
|
config2.trades = trades;
|
|
61600
61804
|
}
|
|
@@ -61695,7 +61899,8 @@ class ExchangePosition {
|
|
|
61695
61899
|
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
61696
61900
|
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
61697
61901
|
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
61698
|
-
kelly_func: config2.kelly?.kelly_func
|
|
61902
|
+
kelly_func: config2.kelly?.kelly_func,
|
|
61903
|
+
distribution: config2.distribution
|
|
61699
61904
|
});
|
|
61700
61905
|
const position2 = this.instance;
|
|
61701
61906
|
const orders_to_place = await this.determineAmountToBuy({
|
|
@@ -61893,50 +62098,43 @@ class ExchangePosition {
|
|
|
61893
62098
|
increase: false
|
|
61894
62099
|
});
|
|
61895
62100
|
}
|
|
61896
|
-
|
|
61897
|
-
|
|
61898
|
-
|
|
61899
|
-
|
|
61900
|
-
|
|
61901
|
-
|
|
62101
|
+
get support() {
|
|
62102
|
+
return this.instance.expand?.support;
|
|
62103
|
+
}
|
|
62104
|
+
get linkedConfig() {
|
|
62105
|
+
return this.instance.expand?.b_config;
|
|
62106
|
+
}
|
|
62107
|
+
get isActiveTrade() {
|
|
62108
|
+
const config2 = this.linkedConfig;
|
|
61902
62109
|
return {
|
|
61903
62110
|
config: config2,
|
|
61904
|
-
condition:
|
|
61905
|
-
supportTable
|
|
62111
|
+
condition: this.compound && this.support?.price === config2.stop
|
|
61906
62112
|
};
|
|
61907
62113
|
}
|
|
61908
62114
|
async updateCompound(payload) {
|
|
61909
62115
|
const pb = this.app_db.pb;
|
|
61910
|
-
const item =
|
|
61911
|
-
|
|
61912
|
-
}
|
|
61913
|
-
const {
|
|
61914
|
-
expand: { ref }
|
|
61915
|
-
} = item;
|
|
61916
|
-
const risk = item.risk;
|
|
61917
|
-
const percent = ref.profit_percent / 100;
|
|
61918
|
-
const new_risk = risk * (1 + percent);
|
|
61919
|
-
const { condition, supportTable, config: config2 } = await this.isActiveTrade();
|
|
62116
|
+
const item = this.compound;
|
|
62117
|
+
const new_risk = item.risk + item.amount_to_risk;
|
|
62118
|
+
const { condition, config: config2 } = this.isActiveTrade;
|
|
61920
62119
|
if (payload?.place && condition) {
|
|
61921
62120
|
await pb.collection("compound_instances").update(item.id, {
|
|
61922
62121
|
risk: new_risk
|
|
61923
62122
|
});
|
|
61924
62123
|
await pb.collection("scheduled_trades").update(config2.id, {
|
|
61925
|
-
profit: to_f(new_risk *
|
|
62124
|
+
profit: to_f(new_risk * item.profit_percent, "%.3f")
|
|
61926
62125
|
});
|
|
61927
62126
|
}
|
|
61928
62127
|
return {
|
|
61929
|
-
support:
|
|
61930
|
-
counter:
|
|
61931
|
-
new_risk
|
|
62128
|
+
support: this.support?.price,
|
|
62129
|
+
counter: this.support?.counter,
|
|
62130
|
+
new_risk,
|
|
62131
|
+
condition,
|
|
62132
|
+
stop: config2.stop
|
|
61932
62133
|
};
|
|
61933
62134
|
}
|
|
61934
62135
|
async cleanOnActiveCompoundInstance() {
|
|
61935
|
-
const
|
|
61936
|
-
|
|
61937
|
-
});
|
|
61938
|
-
const { condition } = await this.isActiveTrade();
|
|
61939
|
-
if (item && condition && this.instance.quantity === 0) {
|
|
62136
|
+
const { condition } = this.isActiveTrade;
|
|
62137
|
+
if (condition && this.instance.quantity === 0) {
|
|
61940
62138
|
await this.cancelOrders({ limit: true });
|
|
61941
62139
|
}
|
|
61942
62140
|
}
|