@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.cjs
CHANGED
|
@@ -54707,7 +54707,7 @@ class AppDatabase {
|
|
|
54707
54707
|
table: "positions_view",
|
|
54708
54708
|
params: {
|
|
54709
54709
|
filter: `symbol:lower="${symbol.toLowerCase()}" && p_account.owner:lower="${account.owner.toLowerCase()}" && p_account.exchange:lower="${account.exchange.toLowerCase()}"`,
|
|
54710
|
-
expand: "b_config, account_strategy, p_account, proxy"
|
|
54710
|
+
expand: "b_config, account_strategy, p_account, proxy, compound_instance.ref,support"
|
|
54711
54711
|
}
|
|
54712
54712
|
} : {
|
|
54713
54713
|
table: "positions",
|
|
@@ -55556,6 +55556,137 @@ __export(exports_exchange_account, {
|
|
|
55556
55556
|
// src/exchanges/binance/index.ts
|
|
55557
55557
|
var import_binance = __toESM(require_lib2());
|
|
55558
55558
|
|
|
55559
|
+
// src/helpers/distributions.ts
|
|
55560
|
+
function generateArithmetic(payload) {
|
|
55561
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f" } = payload;
|
|
55562
|
+
const difference = Math.abs(margin_range[1] - margin_range[0]);
|
|
55563
|
+
const spread = difference / risk_reward;
|
|
55564
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55565
|
+
const price = kind === "long" ? margin_range[1] - spread * i2 : margin_range[0] + spread * i2;
|
|
55566
|
+
return to_f(price, price_places);
|
|
55567
|
+
});
|
|
55568
|
+
}
|
|
55569
|
+
function generateGeometric(payload) {
|
|
55570
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", percent_change } = payload;
|
|
55571
|
+
const effectivePercentChange = percent_change ?? Math.abs(margin_range[1] / margin_range[0] - 1) / risk_reward;
|
|
55572
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55573
|
+
const price = kind === "long" ? margin_range[1] * Math.pow(1 - effectivePercentChange, i2) : margin_range[0] * Math.pow(1 + effectivePercentChange, i2);
|
|
55574
|
+
return to_f(price, price_places);
|
|
55575
|
+
});
|
|
55576
|
+
}
|
|
55577
|
+
function approximateInverseNormal(p) {
|
|
55578
|
+
p = Math.max(0.0001, Math.min(0.9999, p));
|
|
55579
|
+
if (p < 0.5) {
|
|
55580
|
+
const t2 = Math.sqrt(-2 * Math.log(p));
|
|
55581
|
+
const c0 = 2.515517, c1 = 0.802853, c2 = 0.010328;
|
|
55582
|
+
const d1 = 1.432788, d2 = 0.189269, d3 = 0.001308;
|
|
55583
|
+
return -(t2 - (c0 + c1 * t2 + c2 * t2 * t2) / (1 + d1 * t2 + d2 * t2 * t2 + d3 * t2 * t2 * t2));
|
|
55584
|
+
} else {
|
|
55585
|
+
const t2 = Math.sqrt(-2 * Math.log(1 - p));
|
|
55586
|
+
const c0 = 2.515517, c1 = 0.802853, c2 = 0.010328;
|
|
55587
|
+
const d1 = 1.432788, d2 = 0.189269, d3 = 0.001308;
|
|
55588
|
+
return t2 - (c0 + c1 * t2 + c2 * t2 * t2) / (1 + d1 * t2 + d2 * t2 * t2 + d3 * t2 * t2 * t2);
|
|
55589
|
+
}
|
|
55590
|
+
}
|
|
55591
|
+
function generateNormal(payload) {
|
|
55592
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", stdDevFactor = 6 } = payload;
|
|
55593
|
+
const mean = (margin_range[0] + margin_range[1]) / 2;
|
|
55594
|
+
const stdDev = Math.abs(margin_range[1] - margin_range[0]) / stdDevFactor;
|
|
55595
|
+
const skew = kind === "long" ? -0.2 : 0.2;
|
|
55596
|
+
const adjustedMean = mean + stdDev * skew;
|
|
55597
|
+
const entries = Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55598
|
+
const p = (i2 + 0.5) / (risk_reward + 1);
|
|
55599
|
+
const z2 = approximateInverseNormal(p);
|
|
55600
|
+
let price = adjustedMean + stdDev * z2;
|
|
55601
|
+
price = Math.max(margin_range[0], Math.min(margin_range[1], price));
|
|
55602
|
+
return to_f(price, price_places);
|
|
55603
|
+
});
|
|
55604
|
+
return entries.sort((a, b) => a - b);
|
|
55605
|
+
}
|
|
55606
|
+
function generateExponential(payload) {
|
|
55607
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", lambda } = payload;
|
|
55608
|
+
const range = Math.abs(margin_range[1] - margin_range[0]);
|
|
55609
|
+
const effectiveLambda = lambda || 2.5;
|
|
55610
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55611
|
+
const t2 = i2 / risk_reward;
|
|
55612
|
+
const exponentialProgress = 1 - Math.exp(-effectiveLambda * t2);
|
|
55613
|
+
const price = kind === "long" ? margin_range[1] - range * exponentialProgress : margin_range[0] + range * exponentialProgress;
|
|
55614
|
+
return to_f(price, price_places);
|
|
55615
|
+
});
|
|
55616
|
+
}
|
|
55617
|
+
function generateInverseExponential(payload) {
|
|
55618
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", curveFactor = 2 } = payload;
|
|
55619
|
+
const range = Math.abs(margin_range[1] - margin_range[0]);
|
|
55620
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
55621
|
+
const t2 = i2 / risk_reward;
|
|
55622
|
+
const progress = (Math.exp(curveFactor * t2) - 1) / (Math.exp(curveFactor) - 1);
|
|
55623
|
+
const price = kind === "long" ? margin_range[1] - range * progress : margin_range[0] + range * progress;
|
|
55624
|
+
return to_f(price, price_places);
|
|
55625
|
+
});
|
|
55626
|
+
}
|
|
55627
|
+
function getEntries(params) {
|
|
55628
|
+
const {
|
|
55629
|
+
kind,
|
|
55630
|
+
distribution,
|
|
55631
|
+
margin_range,
|
|
55632
|
+
risk_reward,
|
|
55633
|
+
price_places = "%.1f",
|
|
55634
|
+
distribution_params = {}
|
|
55635
|
+
} = params;
|
|
55636
|
+
let entries = [];
|
|
55637
|
+
switch (distribution) {
|
|
55638
|
+
case "arithmetic":
|
|
55639
|
+
entries = generateArithmetic({
|
|
55640
|
+
margin_range,
|
|
55641
|
+
risk_reward,
|
|
55642
|
+
kind,
|
|
55643
|
+
price_places,
|
|
55644
|
+
percent_change: distribution_params.curveFactor
|
|
55645
|
+
});
|
|
55646
|
+
break;
|
|
55647
|
+
case "geometric":
|
|
55648
|
+
entries = generateGeometric({
|
|
55649
|
+
margin_range,
|
|
55650
|
+
risk_reward,
|
|
55651
|
+
kind,
|
|
55652
|
+
price_places,
|
|
55653
|
+
percent_change: distribution_params.curveFactor
|
|
55654
|
+
});
|
|
55655
|
+
break;
|
|
55656
|
+
case "normal":
|
|
55657
|
+
entries = generateNormal({
|
|
55658
|
+
margin_range,
|
|
55659
|
+
risk_reward,
|
|
55660
|
+
kind,
|
|
55661
|
+
price_places,
|
|
55662
|
+
stdDevFactor: distribution_params.stdDevFactor
|
|
55663
|
+
});
|
|
55664
|
+
break;
|
|
55665
|
+
case "exponential":
|
|
55666
|
+
entries = generateExponential({
|
|
55667
|
+
margin_range,
|
|
55668
|
+
risk_reward,
|
|
55669
|
+
kind,
|
|
55670
|
+
price_places,
|
|
55671
|
+
lambda: distribution_params.lambda
|
|
55672
|
+
});
|
|
55673
|
+
break;
|
|
55674
|
+
case "inverse-exponential":
|
|
55675
|
+
entries = generateInverseExponential({
|
|
55676
|
+
margin_range,
|
|
55677
|
+
risk_reward,
|
|
55678
|
+
kind,
|
|
55679
|
+
price_places,
|
|
55680
|
+
curveFactor: distribution_params.curveFactor
|
|
55681
|
+
});
|
|
55682
|
+
break;
|
|
55683
|
+
default:
|
|
55684
|
+
throw new Error(`Unknown distribution type: ${distribution}`);
|
|
55685
|
+
}
|
|
55686
|
+
return entries.sort((a, b) => a - b);
|
|
55687
|
+
}
|
|
55688
|
+
var distributions_default = getEntries;
|
|
55689
|
+
|
|
55559
55690
|
// src/helpers/optimizations.ts
|
|
55560
55691
|
function calculateTheoreticalKelly({
|
|
55561
55692
|
current_entry,
|
|
@@ -55825,6 +55956,10 @@ class Signal {
|
|
|
55825
55956
|
kelly_minimum_risk = 0.2;
|
|
55826
55957
|
kelly_func = "theoretical";
|
|
55827
55958
|
symbol;
|
|
55959
|
+
distribution = {
|
|
55960
|
+
long: "arithmetic",
|
|
55961
|
+
short: "geometric"
|
|
55962
|
+
};
|
|
55828
55963
|
constructor({
|
|
55829
55964
|
focus,
|
|
55830
55965
|
symbol,
|
|
@@ -55851,8 +55986,12 @@ class Signal {
|
|
|
55851
55986
|
kelly_prediction_model = "exponential",
|
|
55852
55987
|
kelly_confidence_factor = 0.6,
|
|
55853
55988
|
kelly_minimum_risk = 0.2,
|
|
55854
|
-
kelly_func = "theoretical"
|
|
55989
|
+
kelly_func = "theoretical",
|
|
55990
|
+
full_distribution
|
|
55855
55991
|
}) {
|
|
55992
|
+
if (full_distribution) {
|
|
55993
|
+
this.distribution = full_distribution;
|
|
55994
|
+
}
|
|
55856
55995
|
this.symbol = symbol;
|
|
55857
55996
|
this.minimum_size = minimum_size;
|
|
55858
55997
|
this.first_order_size = first_order_size;
|
|
@@ -55888,7 +56027,8 @@ class Signal {
|
|
|
55888
56027
|
kind = "long",
|
|
55889
56028
|
risk,
|
|
55890
56029
|
no_of_trades = 1,
|
|
55891
|
-
take_profit
|
|
56030
|
+
take_profit,
|
|
56031
|
+
distribution
|
|
55892
56032
|
}) {
|
|
55893
56033
|
let _stop_loss = stop_loss;
|
|
55894
56034
|
if (!_stop_loss && stop_percent) {
|
|
@@ -55897,16 +56037,22 @@ class Signal {
|
|
|
55897
56037
|
const percent_change = _stop_loss ? Math.max(current_price, _stop_loss) / Math.min(current_price, _stop_loss) - 1 : this.percent_change;
|
|
55898
56038
|
const _no_of_trades = no_of_trades || this.risk_reward;
|
|
55899
56039
|
let _resistance = current_price * Math.pow(1 + percent_change, 1);
|
|
56040
|
+
const simple_support = Math.min(current_price, stop_loss);
|
|
56041
|
+
const simple_resistance = Math.max(current_price, stop_loss);
|
|
55900
56042
|
const derivedConfig = {
|
|
55901
56043
|
...this,
|
|
55902
56044
|
percent_change,
|
|
55903
56045
|
focus: current_price,
|
|
55904
|
-
resistance: _resistance,
|
|
56046
|
+
resistance: distribution ? simple_resistance : _resistance,
|
|
55905
56047
|
risk_per_trade: risk / this.risk_reward,
|
|
55906
56048
|
minimum_pnl: pnl,
|
|
55907
56049
|
risk_reward: _no_of_trades,
|
|
55908
56050
|
take_profit: take_profit || this.take_profit,
|
|
55909
|
-
support: kind === "long" ? _stop_loss : this.support
|
|
56051
|
+
support: distribution ? simple_support : kind === "long" ? _stop_loss : this.support,
|
|
56052
|
+
full_distribution: distribution ? {
|
|
56053
|
+
...this.distribution,
|
|
56054
|
+
[kind]: distribution
|
|
56055
|
+
} : undefined
|
|
55910
56056
|
};
|
|
55911
56057
|
const instance = new Signal(derivedConfig);
|
|
55912
56058
|
if (kind === "short") {}
|
|
@@ -56122,12 +56268,31 @@ class Signal {
|
|
|
56122
56268
|
}
|
|
56123
56269
|
this.zone_risk = original;
|
|
56124
56270
|
}
|
|
56271
|
+
get_future_zones_simple({
|
|
56272
|
+
current_price,
|
|
56273
|
+
kind = "long",
|
|
56274
|
+
raw
|
|
56275
|
+
}) {
|
|
56276
|
+
const margin_zones = [this.support, this.resistance];
|
|
56277
|
+
const distribution = this.distribution ? this.distribution[kind] : "geometric";
|
|
56278
|
+
console.log("margin_zones", { margin_zones, distribution });
|
|
56279
|
+
let _kind = distribution === "inverse-exponential" ? kind === "long" ? "short" : "long" : kind;
|
|
56280
|
+
const entries = distributions_default({
|
|
56281
|
+
margin_range: margin_zones,
|
|
56282
|
+
kind: _kind,
|
|
56283
|
+
distribution,
|
|
56284
|
+
risk_reward: this.risk_reward,
|
|
56285
|
+
price_places: this.price_places
|
|
56286
|
+
});
|
|
56287
|
+
return entries.sort((a, b) => a - b);
|
|
56288
|
+
}
|
|
56125
56289
|
get_future_zones({
|
|
56126
56290
|
current_price,
|
|
56127
56291
|
kind = "long",
|
|
56128
56292
|
raw
|
|
56129
56293
|
}) {
|
|
56130
56294
|
if (raw) {}
|
|
56295
|
+
return this.get_future_zones_simple({ current_price, raw, kind });
|
|
56131
56296
|
const margin_range = this.get_margin_range(current_price, kind);
|
|
56132
56297
|
let margin_zones = this.get_margin_zones({ current_price });
|
|
56133
56298
|
let remaining_zones = margin_zones.filter((x) => JSON.stringify(x) != JSON.stringify(margin_range));
|
|
@@ -56786,7 +56951,9 @@ function buildConfig(app_config, {
|
|
|
56786
56951
|
kelly_confidence_factor = 0.95,
|
|
56787
56952
|
kelly_minimum_risk = 0.2,
|
|
56788
56953
|
kelly_prediction_model = "exponential",
|
|
56789
|
-
kelly_func = "theoretical"
|
|
56954
|
+
kelly_func = "theoretical",
|
|
56955
|
+
min_avg_size = 0,
|
|
56956
|
+
distribution
|
|
56790
56957
|
}) {
|
|
56791
56958
|
let fee = app_config.fee / 100;
|
|
56792
56959
|
let working_risk = risk || app_config.risk_per_trade;
|
|
@@ -56833,9 +57000,12 @@ function buildConfig(app_config, {
|
|
|
56833
57000
|
stop_loss: stop,
|
|
56834
57001
|
risk: working_risk,
|
|
56835
57002
|
kind: kind || app_config.kind,
|
|
56836
|
-
no_of_trades: trade_no
|
|
57003
|
+
no_of_trades: trade_no,
|
|
57004
|
+
distribution
|
|
56837
57005
|
}) || [] : [];
|
|
56838
|
-
|
|
57006
|
+
const new_trades = computeTotalAverageForEachTrade(result, config2);
|
|
57007
|
+
let filtered = new_trades.filter((o) => o.avg_size > min_avg_size);
|
|
57008
|
+
return computeTotalAverageForEachTrade(filtered, config2);
|
|
56839
57009
|
}
|
|
56840
57010
|
function buildAvg({
|
|
56841
57011
|
_trades,
|
|
@@ -56900,7 +57070,8 @@ function get_app_config_and_max_size(config2, payload) {
|
|
|
56900
57070
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
56901
57071
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
56902
57072
|
kelly_prediction_model: payload.kelly_prediction_model,
|
|
56903
|
-
kelly_func: payload.kelly_func
|
|
57073
|
+
kelly_func: payload.kelly_func,
|
|
57074
|
+
distribution: payload.distribution
|
|
56904
57075
|
});
|
|
56905
57076
|
const max_size = initialResult[0]?.avg_size;
|
|
56906
57077
|
const last_value = initialResult[0];
|
|
@@ -56938,7 +57109,8 @@ function buildAppConfig(config2, payload) {
|
|
|
56938
57109
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
56939
57110
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
56940
57111
|
kelly_prediction_model: payload.kelly_prediction_model,
|
|
56941
|
-
kelly_func: payload.kelly_func
|
|
57112
|
+
kelly_func: payload.kelly_func,
|
|
57113
|
+
distribution: payload.distribution
|
|
56942
57114
|
});
|
|
56943
57115
|
app_config.max_size = max_size;
|
|
56944
57116
|
app_config.entry = payload.entry || app_config.entry;
|
|
@@ -56955,7 +57127,7 @@ function buildAppConfig(config2, payload) {
|
|
|
56955
57127
|
return app_config;
|
|
56956
57128
|
}
|
|
56957
57129
|
function getOptimumStopAndRisk(app_config, params) {
|
|
56958
|
-
const { max_size, target_stop } = params;
|
|
57130
|
+
const { max_size, target_stop, distribution } = params;
|
|
56959
57131
|
const isLong = app_config.kind === "long";
|
|
56960
57132
|
const stopRange = Math.abs(app_config.entry - target_stop) * 0.5;
|
|
56961
57133
|
let low_stop = isLong ? target_stop - stopRange : Math.max(target_stop - stopRange, app_config.entry);
|
|
@@ -56978,7 +57150,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
56978
57150
|
increase: true,
|
|
56979
57151
|
gap: app_config.gap,
|
|
56980
57152
|
price_places: app_config.price_places,
|
|
56981
|
-
decimal_places: app_config.decimal_places
|
|
57153
|
+
decimal_places: app_config.decimal_places,
|
|
57154
|
+
distribution
|
|
56982
57155
|
});
|
|
56983
57156
|
if (result.length === 0) {
|
|
56984
57157
|
if (isLong) {
|
|
@@ -57032,7 +57205,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
57032
57205
|
increase: true,
|
|
57033
57206
|
gap: app_config.gap,
|
|
57034
57207
|
price_places: app_config.price_places,
|
|
57035
|
-
decimal_places: app_config.decimal_places
|
|
57208
|
+
decimal_places: app_config.decimal_places,
|
|
57209
|
+
distribution
|
|
57036
57210
|
});
|
|
57037
57211
|
if (result.length === 0) {
|
|
57038
57212
|
high_risk = mid_risk;
|
|
@@ -57077,7 +57251,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
57077
57251
|
increase: true,
|
|
57078
57252
|
gap: app_config.gap,
|
|
57079
57253
|
price_places: app_config.price_places,
|
|
57080
|
-
decimal_places: app_config.decimal_places
|
|
57254
|
+
decimal_places: app_config.decimal_places,
|
|
57255
|
+
distribution
|
|
57081
57256
|
});
|
|
57082
57257
|
if (result.length === 0)
|
|
57083
57258
|
continue;
|
|
@@ -57200,7 +57375,8 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
57200
57375
|
}, {
|
|
57201
57376
|
entry: payload.entry,
|
|
57202
57377
|
stop: payload.stop,
|
|
57203
|
-
kind: position2.kind
|
|
57378
|
+
kind: position2.kind,
|
|
57379
|
+
distribution: payload.distribution
|
|
57204
57380
|
});
|
|
57205
57381
|
current_app_config.max_size = max_size;
|
|
57206
57382
|
current_app_config.last_value = last_value;
|
|
@@ -57215,7 +57391,8 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
57215
57391
|
increase: true,
|
|
57216
57392
|
gap: current_app_config.gap,
|
|
57217
57393
|
price_places: current_app_config.price_places,
|
|
57218
|
-
decimal_places: current_app_config.decimal_places
|
|
57394
|
+
decimal_places: current_app_config.decimal_places,
|
|
57395
|
+
distribution: payload.distribution
|
|
57219
57396
|
});
|
|
57220
57397
|
if (full_trades.length === 0) {
|
|
57221
57398
|
high_risk = mid_risk;
|
|
@@ -57279,7 +57456,8 @@ function determineOptimumReward(payload) {
|
|
|
57279
57456
|
increase = true,
|
|
57280
57457
|
low_range = 1,
|
|
57281
57458
|
high_range = 199,
|
|
57282
|
-
target_loss
|
|
57459
|
+
target_loss,
|
|
57460
|
+
distribution
|
|
57283
57461
|
} = payload;
|
|
57284
57462
|
const criterion = app_config.strategy || "quantity";
|
|
57285
57463
|
const risk_rewards = createArray(low_range, high_range, 1);
|
|
@@ -57293,7 +57471,8 @@ function determineOptimumReward(payload) {
|
|
|
57293
57471
|
increase,
|
|
57294
57472
|
kind: app_config.kind,
|
|
57295
57473
|
gap: app_config.gap,
|
|
57296
|
-
decimal_places: app_config.decimal_places
|
|
57474
|
+
decimal_places: app_config.decimal_places,
|
|
57475
|
+
distribution
|
|
57297
57476
|
});
|
|
57298
57477
|
let total = 0;
|
|
57299
57478
|
let max = -Infinity;
|
|
@@ -57458,14 +57637,17 @@ function determineOptimumRisk(config2, payload, params) {
|
|
|
57458
57637
|
};
|
|
57459
57638
|
}
|
|
57460
57639
|
function computeRiskReward(payload) {
|
|
57461
|
-
const { app_config, entry, stop, risk_per_trade, target_loss } = payload;
|
|
57640
|
+
const { app_config, entry, stop, risk_per_trade, target_loss, distribution } = payload;
|
|
57462
57641
|
const kind = entry > stop ? "long" : "short";
|
|
57463
57642
|
app_config.kind = kind;
|
|
57464
57643
|
app_config.entry = entry;
|
|
57465
57644
|
app_config.stop = stop;
|
|
57466
57645
|
app_config.risk_per_trade = risk_per_trade;
|
|
57467
|
-
const result = determineOptimumReward({
|
|
57468
|
-
|
|
57646
|
+
const result = determineOptimumReward({
|
|
57647
|
+
app_config,
|
|
57648
|
+
target_loss,
|
|
57649
|
+
distribution
|
|
57650
|
+
});
|
|
57469
57651
|
return result;
|
|
57470
57652
|
}
|
|
57471
57653
|
function getRiskReward(payload) {
|
|
@@ -57475,21 +57657,24 @@ function getRiskReward(payload) {
|
|
|
57475
57657
|
risk,
|
|
57476
57658
|
global_config,
|
|
57477
57659
|
force_exact_risk = false,
|
|
57478
|
-
target_loss
|
|
57660
|
+
target_loss,
|
|
57661
|
+
distribution
|
|
57479
57662
|
} = payload;
|
|
57480
57663
|
const { entries, last_value, ...app_config } = buildAppConfig(global_config, {
|
|
57481
57664
|
entry,
|
|
57482
57665
|
stop,
|
|
57483
57666
|
risk_reward: 30,
|
|
57484
57667
|
risk,
|
|
57485
|
-
symbol: global_config.symbol
|
|
57668
|
+
symbol: global_config.symbol,
|
|
57669
|
+
distribution
|
|
57486
57670
|
});
|
|
57487
57671
|
const risk_reward = computeRiskReward({
|
|
57488
57672
|
app_config,
|
|
57489
57673
|
entry,
|
|
57490
57674
|
stop,
|
|
57491
57675
|
risk_per_trade: risk,
|
|
57492
|
-
target_loss
|
|
57676
|
+
target_loss,
|
|
57677
|
+
distribution
|
|
57493
57678
|
});
|
|
57494
57679
|
if (force_exact_risk) {
|
|
57495
57680
|
const new_risk_per_trade = determineOptimumRisk(global_config, {
|
|
@@ -57497,7 +57682,8 @@ function getRiskReward(payload) {
|
|
|
57497
57682
|
stop,
|
|
57498
57683
|
risk_reward,
|
|
57499
57684
|
risk,
|
|
57500
|
-
symbol: global_config.symbol
|
|
57685
|
+
symbol: global_config.symbol,
|
|
57686
|
+
distribution
|
|
57501
57687
|
}, {
|
|
57502
57688
|
highest_risk: risk
|
|
57503
57689
|
}).optimal_risk;
|
|
@@ -57952,7 +58138,7 @@ function constructAppConfig(payload) {
|
|
|
57952
58138
|
kelly_minimum_risk: kelly_config?.kelly_minimum_risk ?? kelly?.kelly_minimum_risk,
|
|
57953
58139
|
kelly_prediction_model: kelly_config?.kelly_prediction_model ?? kelly?.kelly_prediction_model
|
|
57954
58140
|
};
|
|
57955
|
-
const appConfig = buildAppConfig(global_config, options);
|
|
58141
|
+
const { entries: _entries, ...appConfig } = buildAppConfig(global_config, options);
|
|
57956
58142
|
return appConfig;
|
|
57957
58143
|
}
|
|
57958
58144
|
function generateDangerousConfig(payload) {
|
|
@@ -60950,6 +61136,19 @@ class ExchangePosition {
|
|
|
60950
61136
|
const { p_account } = this.instance.expand;
|
|
60951
61137
|
return p_account;
|
|
60952
61138
|
}
|
|
61139
|
+
get compound() {
|
|
61140
|
+
const { compound_instance } = this.instance.expand;
|
|
61141
|
+
if (compound_instance) {
|
|
61142
|
+
const { ref } = compound_instance.expand;
|
|
61143
|
+
const profit_percent = ref.profit_percent / 100;
|
|
61144
|
+
return {
|
|
61145
|
+
...compound_instance,
|
|
61146
|
+
profit_percent,
|
|
61147
|
+
amount_to_risk: to_f(compound_instance.risk * profit_percent, "%.2f")
|
|
61148
|
+
};
|
|
61149
|
+
}
|
|
61150
|
+
return compound_instance;
|
|
61151
|
+
}
|
|
60953
61152
|
async getProxyForAccount() {
|
|
60954
61153
|
if (this.instance.expand.proxy) {
|
|
60955
61154
|
const result = this.instance.expand.proxy;
|
|
@@ -61075,7 +61274,8 @@ class ExchangePosition {
|
|
|
61075
61274
|
place,
|
|
61076
61275
|
raw: payload.raw,
|
|
61077
61276
|
use_current,
|
|
61078
|
-
stop_percent: config2.stop_percent || 100
|
|
61277
|
+
stop_percent: config2.stop_percent || 100,
|
|
61278
|
+
distribution: config2.distribution
|
|
61079
61279
|
});
|
|
61080
61280
|
}
|
|
61081
61281
|
}
|
|
@@ -61109,7 +61309,8 @@ class ExchangePosition {
|
|
|
61109
61309
|
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
61110
61310
|
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
61111
61311
|
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
61112
|
-
kelly_func: config2.kelly?.kelly_func
|
|
61312
|
+
kelly_func: config2.kelly?.kelly_func,
|
|
61313
|
+
distribution: config2.distribution
|
|
61113
61314
|
}, false);
|
|
61114
61315
|
if (payload.raw) {
|
|
61115
61316
|
let actual_orders_to_buy = await this.determineAmountToBuy({
|
|
@@ -61232,7 +61433,8 @@ class ExchangePosition {
|
|
|
61232
61433
|
kelly_confidence_factor: solution.kelly_confidence_factor,
|
|
61233
61434
|
kelly_minimum_risk: solution.kelly_minimum_risk,
|
|
61234
61435
|
kelly_prediction_model: solution.kelly_prediction_model,
|
|
61235
|
-
kelly_func: solution.kelly_func
|
|
61436
|
+
kelly_func: solution.kelly_func,
|
|
61437
|
+
distribution: solution.distribution
|
|
61236
61438
|
};
|
|
61237
61439
|
const trades = sortedBuildConfig(app_config, options);
|
|
61238
61440
|
const entry_orders = {
|
|
@@ -61624,6 +61826,7 @@ class ExchangePosition {
|
|
|
61624
61826
|
});
|
|
61625
61827
|
}
|
|
61626
61828
|
async generate_config_params(payload) {
|
|
61829
|
+
const db_config = await this.getConfig();
|
|
61627
61830
|
const { entry, stop, risk_reward, risk, with_trades = false } = payload;
|
|
61628
61831
|
const symbol = this.symbol;
|
|
61629
61832
|
const app_config = await this.buildAppConfig({
|
|
@@ -61656,7 +61859,8 @@ class ExchangePosition {
|
|
|
61656
61859
|
avg_size: 0,
|
|
61657
61860
|
neg_pnl: 0,
|
|
61658
61861
|
min_size: app_config2.min_size,
|
|
61659
|
-
symbol
|
|
61862
|
+
symbol,
|
|
61863
|
+
distribution: db_config.distribution
|
|
61660
61864
|
}, false);
|
|
61661
61865
|
config2.trades = trades;
|
|
61662
61866
|
}
|
|
@@ -61757,7 +61961,8 @@ class ExchangePosition {
|
|
|
61757
61961
|
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
61758
61962
|
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
61759
61963
|
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
61760
|
-
kelly_func: config2.kelly?.kelly_func
|
|
61964
|
+
kelly_func: config2.kelly?.kelly_func,
|
|
61965
|
+
distribution: config2.distribution
|
|
61761
61966
|
});
|
|
61762
61967
|
const position2 = this.instance;
|
|
61763
61968
|
const orders_to_place = await this.determineAmountToBuy({
|
|
@@ -61955,50 +62160,43 @@ class ExchangePosition {
|
|
|
61955
62160
|
increase: false
|
|
61956
62161
|
});
|
|
61957
62162
|
}
|
|
61958
|
-
|
|
61959
|
-
|
|
61960
|
-
|
|
61961
|
-
|
|
61962
|
-
|
|
61963
|
-
|
|
62163
|
+
get support() {
|
|
62164
|
+
return this.instance.expand?.support;
|
|
62165
|
+
}
|
|
62166
|
+
get linkedConfig() {
|
|
62167
|
+
return this.instance.expand?.b_config;
|
|
62168
|
+
}
|
|
62169
|
+
get isActiveTrade() {
|
|
62170
|
+
const config2 = this.linkedConfig;
|
|
61964
62171
|
return {
|
|
61965
62172
|
config: config2,
|
|
61966
|
-
condition:
|
|
61967
|
-
supportTable
|
|
62173
|
+
condition: this.compound && this.support?.price === config2.stop
|
|
61968
62174
|
};
|
|
61969
62175
|
}
|
|
61970
62176
|
async updateCompound(payload) {
|
|
61971
62177
|
const pb = this.app_db.pb;
|
|
61972
|
-
const item =
|
|
61973
|
-
|
|
61974
|
-
}
|
|
61975
|
-
const {
|
|
61976
|
-
expand: { ref }
|
|
61977
|
-
} = item;
|
|
61978
|
-
const risk = item.risk;
|
|
61979
|
-
const percent = ref.profit_percent / 100;
|
|
61980
|
-
const new_risk = risk * (1 + percent);
|
|
61981
|
-
const { condition, supportTable, config: config2 } = await this.isActiveTrade();
|
|
62178
|
+
const item = this.compound;
|
|
62179
|
+
const new_risk = item.risk + item.amount_to_risk;
|
|
62180
|
+
const { condition, config: config2 } = this.isActiveTrade;
|
|
61982
62181
|
if (payload?.place && condition) {
|
|
61983
62182
|
await pb.collection("compound_instances").update(item.id, {
|
|
61984
62183
|
risk: new_risk
|
|
61985
62184
|
});
|
|
61986
62185
|
await pb.collection("scheduled_trades").update(config2.id, {
|
|
61987
|
-
profit: to_f(new_risk *
|
|
62186
|
+
profit: to_f(new_risk * item.profit_percent, "%.3f")
|
|
61988
62187
|
});
|
|
61989
62188
|
}
|
|
61990
62189
|
return {
|
|
61991
|
-
support:
|
|
61992
|
-
counter:
|
|
61993
|
-
new_risk
|
|
62190
|
+
support: this.support?.price,
|
|
62191
|
+
counter: this.support?.counter,
|
|
62192
|
+
new_risk,
|
|
62193
|
+
condition,
|
|
62194
|
+
stop: config2.stop
|
|
61994
62195
|
};
|
|
61995
62196
|
}
|
|
61996
62197
|
async cleanOnActiveCompoundInstance() {
|
|
61997
|
-
const
|
|
61998
|
-
|
|
61999
|
-
});
|
|
62000
|
-
const { condition } = await this.isActiveTrade();
|
|
62001
|
-
if (item && condition && this.instance.quantity === 0) {
|
|
62198
|
+
const { condition } = this.isActiveTrade;
|
|
62199
|
+
if (condition && this.instance.quantity === 0) {
|
|
62002
62200
|
await this.cancelOrders({ limit: true });
|
|
62003
62201
|
}
|
|
62004
62202
|
}
|