@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/mcp-server.cjs
CHANGED
|
@@ -61401,7 +61401,7 @@ class AppDatabase {
|
|
|
61401
61401
|
table: "positions_view",
|
|
61402
61402
|
params: {
|
|
61403
61403
|
filter: `symbol:lower="${symbol.toLowerCase()}" && p_account.owner:lower="${account.owner.toLowerCase()}" && p_account.exchange:lower="${account.exchange.toLowerCase()}"`,
|
|
61404
|
-
expand: "b_config, account_strategy, p_account, proxy"
|
|
61404
|
+
expand: "b_config, account_strategy, p_account, proxy, compound_instance.ref,support"
|
|
61405
61405
|
}
|
|
61406
61406
|
} : {
|
|
61407
61407
|
table: "positions",
|
|
@@ -62243,6 +62243,137 @@ class AppDatabase {
|
|
|
62243
62243
|
// src/exchanges/binance/index.ts
|
|
62244
62244
|
var import_binance = __toESM(require_lib2());
|
|
62245
62245
|
|
|
62246
|
+
// src/helpers/distributions.ts
|
|
62247
|
+
function generateArithmetic(payload) {
|
|
62248
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f" } = payload;
|
|
62249
|
+
const difference = Math.abs(margin_range[1] - margin_range[0]);
|
|
62250
|
+
const spread = difference / risk_reward;
|
|
62251
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
62252
|
+
const price = kind === "long" ? margin_range[1] - spread * i2 : margin_range[0] + spread * i2;
|
|
62253
|
+
return to_f(price, price_places);
|
|
62254
|
+
});
|
|
62255
|
+
}
|
|
62256
|
+
function generateGeometric(payload) {
|
|
62257
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", percent_change } = payload;
|
|
62258
|
+
const effectivePercentChange = percent_change ?? Math.abs(margin_range[1] / margin_range[0] - 1) / risk_reward;
|
|
62259
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
62260
|
+
const price = kind === "long" ? margin_range[1] * Math.pow(1 - effectivePercentChange, i2) : margin_range[0] * Math.pow(1 + effectivePercentChange, i2);
|
|
62261
|
+
return to_f(price, price_places);
|
|
62262
|
+
});
|
|
62263
|
+
}
|
|
62264
|
+
function approximateInverseNormal(p) {
|
|
62265
|
+
p = Math.max(0.0001, Math.min(0.9999, p));
|
|
62266
|
+
if (p < 0.5) {
|
|
62267
|
+
const t2 = Math.sqrt(-2 * Math.log(p));
|
|
62268
|
+
const c0 = 2.515517, c1 = 0.802853, c2 = 0.010328;
|
|
62269
|
+
const d1 = 1.432788, d2 = 0.189269, d3 = 0.001308;
|
|
62270
|
+
return -(t2 - (c0 + c1 * t2 + c2 * t2 * t2) / (1 + d1 * t2 + d2 * t2 * t2 + d3 * t2 * t2 * t2));
|
|
62271
|
+
} else {
|
|
62272
|
+
const t2 = Math.sqrt(-2 * Math.log(1 - p));
|
|
62273
|
+
const c0 = 2.515517, c1 = 0.802853, c2 = 0.010328;
|
|
62274
|
+
const d1 = 1.432788, d2 = 0.189269, d3 = 0.001308;
|
|
62275
|
+
return t2 - (c0 + c1 * t2 + c2 * t2 * t2) / (1 + d1 * t2 + d2 * t2 * t2 + d3 * t2 * t2 * t2);
|
|
62276
|
+
}
|
|
62277
|
+
}
|
|
62278
|
+
function generateNormal(payload) {
|
|
62279
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", stdDevFactor = 6 } = payload;
|
|
62280
|
+
const mean = (margin_range[0] + margin_range[1]) / 2;
|
|
62281
|
+
const stdDev = Math.abs(margin_range[1] - margin_range[0]) / stdDevFactor;
|
|
62282
|
+
const skew = kind === "long" ? -0.2 : 0.2;
|
|
62283
|
+
const adjustedMean = mean + stdDev * skew;
|
|
62284
|
+
const entries = Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
62285
|
+
const p = (i2 + 0.5) / (risk_reward + 1);
|
|
62286
|
+
const z3 = approximateInverseNormal(p);
|
|
62287
|
+
let price = adjustedMean + stdDev * z3;
|
|
62288
|
+
price = Math.max(margin_range[0], Math.min(margin_range[1], price));
|
|
62289
|
+
return to_f(price, price_places);
|
|
62290
|
+
});
|
|
62291
|
+
return entries.sort((a, b) => a - b);
|
|
62292
|
+
}
|
|
62293
|
+
function generateExponential(payload) {
|
|
62294
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", lambda } = payload;
|
|
62295
|
+
const range = Math.abs(margin_range[1] - margin_range[0]);
|
|
62296
|
+
const effectiveLambda = lambda || 2.5;
|
|
62297
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
62298
|
+
const t2 = i2 / risk_reward;
|
|
62299
|
+
const exponentialProgress = 1 - Math.exp(-effectiveLambda * t2);
|
|
62300
|
+
const price = kind === "long" ? margin_range[1] - range * exponentialProgress : margin_range[0] + range * exponentialProgress;
|
|
62301
|
+
return to_f(price, price_places);
|
|
62302
|
+
});
|
|
62303
|
+
}
|
|
62304
|
+
function generateInverseExponential(payload) {
|
|
62305
|
+
const { margin_range, risk_reward, kind, price_places = "%.1f", curveFactor = 2 } = payload;
|
|
62306
|
+
const range = Math.abs(margin_range[1] - margin_range[0]);
|
|
62307
|
+
return Array.from({ length: risk_reward + 1 }, (_, i2) => {
|
|
62308
|
+
const t2 = i2 / risk_reward;
|
|
62309
|
+
const progress = (Math.exp(curveFactor * t2) - 1) / (Math.exp(curveFactor) - 1);
|
|
62310
|
+
const price = kind === "long" ? margin_range[1] - range * progress : margin_range[0] + range * progress;
|
|
62311
|
+
return to_f(price, price_places);
|
|
62312
|
+
});
|
|
62313
|
+
}
|
|
62314
|
+
function getEntries(params) {
|
|
62315
|
+
const {
|
|
62316
|
+
kind,
|
|
62317
|
+
distribution,
|
|
62318
|
+
margin_range,
|
|
62319
|
+
risk_reward,
|
|
62320
|
+
price_places = "%.1f",
|
|
62321
|
+
distribution_params = {}
|
|
62322
|
+
} = params;
|
|
62323
|
+
let entries = [];
|
|
62324
|
+
switch (distribution) {
|
|
62325
|
+
case "arithmetic":
|
|
62326
|
+
entries = generateArithmetic({
|
|
62327
|
+
margin_range,
|
|
62328
|
+
risk_reward,
|
|
62329
|
+
kind,
|
|
62330
|
+
price_places,
|
|
62331
|
+
percent_change: distribution_params.curveFactor
|
|
62332
|
+
});
|
|
62333
|
+
break;
|
|
62334
|
+
case "geometric":
|
|
62335
|
+
entries = generateGeometric({
|
|
62336
|
+
margin_range,
|
|
62337
|
+
risk_reward,
|
|
62338
|
+
kind,
|
|
62339
|
+
price_places,
|
|
62340
|
+
percent_change: distribution_params.curveFactor
|
|
62341
|
+
});
|
|
62342
|
+
break;
|
|
62343
|
+
case "normal":
|
|
62344
|
+
entries = generateNormal({
|
|
62345
|
+
margin_range,
|
|
62346
|
+
risk_reward,
|
|
62347
|
+
kind,
|
|
62348
|
+
price_places,
|
|
62349
|
+
stdDevFactor: distribution_params.stdDevFactor
|
|
62350
|
+
});
|
|
62351
|
+
break;
|
|
62352
|
+
case "exponential":
|
|
62353
|
+
entries = generateExponential({
|
|
62354
|
+
margin_range,
|
|
62355
|
+
risk_reward,
|
|
62356
|
+
kind,
|
|
62357
|
+
price_places,
|
|
62358
|
+
lambda: distribution_params.lambda
|
|
62359
|
+
});
|
|
62360
|
+
break;
|
|
62361
|
+
case "inverse-exponential":
|
|
62362
|
+
entries = generateInverseExponential({
|
|
62363
|
+
margin_range,
|
|
62364
|
+
risk_reward,
|
|
62365
|
+
kind,
|
|
62366
|
+
price_places,
|
|
62367
|
+
curveFactor: distribution_params.curveFactor
|
|
62368
|
+
});
|
|
62369
|
+
break;
|
|
62370
|
+
default:
|
|
62371
|
+
throw new Error(`Unknown distribution type: ${distribution}`);
|
|
62372
|
+
}
|
|
62373
|
+
return entries.sort((a, b) => a - b);
|
|
62374
|
+
}
|
|
62375
|
+
var distributions_default = getEntries;
|
|
62376
|
+
|
|
62246
62377
|
// src/helpers/optimizations.ts
|
|
62247
62378
|
function calculateTheoreticalKelly({
|
|
62248
62379
|
current_entry,
|
|
@@ -62512,6 +62643,10 @@ class Signal {
|
|
|
62512
62643
|
kelly_minimum_risk = 0.2;
|
|
62513
62644
|
kelly_func = "theoretical";
|
|
62514
62645
|
symbol;
|
|
62646
|
+
distribution = {
|
|
62647
|
+
long: "arithmetic",
|
|
62648
|
+
short: "geometric"
|
|
62649
|
+
};
|
|
62515
62650
|
constructor({
|
|
62516
62651
|
focus,
|
|
62517
62652
|
symbol,
|
|
@@ -62538,8 +62673,12 @@ class Signal {
|
|
|
62538
62673
|
kelly_prediction_model = "exponential",
|
|
62539
62674
|
kelly_confidence_factor = 0.6,
|
|
62540
62675
|
kelly_minimum_risk = 0.2,
|
|
62541
|
-
kelly_func = "theoretical"
|
|
62676
|
+
kelly_func = "theoretical",
|
|
62677
|
+
full_distribution
|
|
62542
62678
|
}) {
|
|
62679
|
+
if (full_distribution) {
|
|
62680
|
+
this.distribution = full_distribution;
|
|
62681
|
+
}
|
|
62543
62682
|
this.symbol = symbol;
|
|
62544
62683
|
this.minimum_size = minimum_size;
|
|
62545
62684
|
this.first_order_size = first_order_size;
|
|
@@ -62575,7 +62714,8 @@ class Signal {
|
|
|
62575
62714
|
kind = "long",
|
|
62576
62715
|
risk,
|
|
62577
62716
|
no_of_trades = 1,
|
|
62578
|
-
take_profit
|
|
62717
|
+
take_profit,
|
|
62718
|
+
distribution
|
|
62579
62719
|
}) {
|
|
62580
62720
|
let _stop_loss = stop_loss;
|
|
62581
62721
|
if (!_stop_loss && stop_percent) {
|
|
@@ -62584,16 +62724,22 @@ class Signal {
|
|
|
62584
62724
|
const percent_change = _stop_loss ? Math.max(current_price, _stop_loss) / Math.min(current_price, _stop_loss) - 1 : this.percent_change;
|
|
62585
62725
|
const _no_of_trades = no_of_trades || this.risk_reward;
|
|
62586
62726
|
let _resistance = current_price * Math.pow(1 + percent_change, 1);
|
|
62727
|
+
const simple_support = Math.min(current_price, stop_loss);
|
|
62728
|
+
const simple_resistance = Math.max(current_price, stop_loss);
|
|
62587
62729
|
const derivedConfig = {
|
|
62588
62730
|
...this,
|
|
62589
62731
|
percent_change,
|
|
62590
62732
|
focus: current_price,
|
|
62591
|
-
resistance: _resistance,
|
|
62733
|
+
resistance: distribution ? simple_resistance : _resistance,
|
|
62592
62734
|
risk_per_trade: risk / this.risk_reward,
|
|
62593
62735
|
minimum_pnl: pnl,
|
|
62594
62736
|
risk_reward: _no_of_trades,
|
|
62595
62737
|
take_profit: take_profit || this.take_profit,
|
|
62596
|
-
support: kind === "long" ? _stop_loss : this.support
|
|
62738
|
+
support: distribution ? simple_support : kind === "long" ? _stop_loss : this.support,
|
|
62739
|
+
full_distribution: distribution ? {
|
|
62740
|
+
...this.distribution,
|
|
62741
|
+
[kind]: distribution
|
|
62742
|
+
} : undefined
|
|
62597
62743
|
};
|
|
62598
62744
|
const instance = new Signal(derivedConfig);
|
|
62599
62745
|
if (kind === "short") {}
|
|
@@ -62809,12 +62955,31 @@ class Signal {
|
|
|
62809
62955
|
}
|
|
62810
62956
|
this.zone_risk = original;
|
|
62811
62957
|
}
|
|
62958
|
+
get_future_zones_simple({
|
|
62959
|
+
current_price,
|
|
62960
|
+
kind = "long",
|
|
62961
|
+
raw
|
|
62962
|
+
}) {
|
|
62963
|
+
const margin_zones = [this.support, this.resistance];
|
|
62964
|
+
const distribution = this.distribution ? this.distribution[kind] : "geometric";
|
|
62965
|
+
console.log("margin_zones", { margin_zones, distribution });
|
|
62966
|
+
let _kind = distribution === "inverse-exponential" ? kind === "long" ? "short" : "long" : kind;
|
|
62967
|
+
const entries = distributions_default({
|
|
62968
|
+
margin_range: margin_zones,
|
|
62969
|
+
kind: _kind,
|
|
62970
|
+
distribution,
|
|
62971
|
+
risk_reward: this.risk_reward,
|
|
62972
|
+
price_places: this.price_places
|
|
62973
|
+
});
|
|
62974
|
+
return entries.sort((a, b) => a - b);
|
|
62975
|
+
}
|
|
62812
62976
|
get_future_zones({
|
|
62813
62977
|
current_price,
|
|
62814
62978
|
kind = "long",
|
|
62815
62979
|
raw
|
|
62816
62980
|
}) {
|
|
62817
62981
|
if (raw) {}
|
|
62982
|
+
return this.get_future_zones_simple({ current_price, raw, kind });
|
|
62818
62983
|
const margin_range = this.get_margin_range(current_price, kind);
|
|
62819
62984
|
let margin_zones = this.get_margin_zones({ current_price });
|
|
62820
62985
|
let remaining_zones = margin_zones.filter((x) => JSON.stringify(x) != JSON.stringify(margin_range));
|
|
@@ -63473,7 +63638,9 @@ function buildConfig(app_config, {
|
|
|
63473
63638
|
kelly_confidence_factor = 0.95,
|
|
63474
63639
|
kelly_minimum_risk = 0.2,
|
|
63475
63640
|
kelly_prediction_model = "exponential",
|
|
63476
|
-
kelly_func = "theoretical"
|
|
63641
|
+
kelly_func = "theoretical",
|
|
63642
|
+
min_avg_size = 0,
|
|
63643
|
+
distribution
|
|
63477
63644
|
}) {
|
|
63478
63645
|
let fee = app_config.fee / 100;
|
|
63479
63646
|
let working_risk = risk || app_config.risk_per_trade;
|
|
@@ -63520,9 +63687,12 @@ function buildConfig(app_config, {
|
|
|
63520
63687
|
stop_loss: stop,
|
|
63521
63688
|
risk: working_risk,
|
|
63522
63689
|
kind: kind || app_config.kind,
|
|
63523
|
-
no_of_trades: trade_no
|
|
63690
|
+
no_of_trades: trade_no,
|
|
63691
|
+
distribution
|
|
63524
63692
|
}) || [] : [];
|
|
63525
|
-
|
|
63693
|
+
const new_trades = computeTotalAverageForEachTrade(result, config2);
|
|
63694
|
+
let filtered = new_trades.filter((o) => o.avg_size > min_avg_size);
|
|
63695
|
+
return computeTotalAverageForEachTrade(filtered, config2);
|
|
63526
63696
|
}
|
|
63527
63697
|
function sortedBuildConfig(app_config, options) {
|
|
63528
63698
|
const sorted = buildConfig(app_config, options).sort((a, b) => app_config.kind === "long" ? a.entry - b.entry : b.entry - b.entry).filter((x) => {
|
|
@@ -63574,7 +63744,8 @@ function get_app_config_and_max_size(config2, payload) {
|
|
|
63574
63744
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
63575
63745
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
63576
63746
|
kelly_prediction_model: payload.kelly_prediction_model,
|
|
63577
|
-
kelly_func: payload.kelly_func
|
|
63747
|
+
kelly_func: payload.kelly_func,
|
|
63748
|
+
distribution: payload.distribution
|
|
63578
63749
|
});
|
|
63579
63750
|
const max_size = initialResult[0]?.avg_size;
|
|
63580
63751
|
const last_value = initialResult[0];
|
|
@@ -63612,7 +63783,8 @@ function buildAppConfig(config2, payload) {
|
|
|
63612
63783
|
kelly_confidence_factor: payload.kelly_confidence_factor,
|
|
63613
63784
|
kelly_minimum_risk: payload.kelly_minimum_risk,
|
|
63614
63785
|
kelly_prediction_model: payload.kelly_prediction_model,
|
|
63615
|
-
kelly_func: payload.kelly_func
|
|
63786
|
+
kelly_func: payload.kelly_func,
|
|
63787
|
+
distribution: payload.distribution
|
|
63616
63788
|
});
|
|
63617
63789
|
app_config.max_size = max_size;
|
|
63618
63790
|
app_config.entry = payload.entry || app_config.entry;
|
|
@@ -63629,7 +63801,7 @@ function buildAppConfig(config2, payload) {
|
|
|
63629
63801
|
return app_config;
|
|
63630
63802
|
}
|
|
63631
63803
|
function getOptimumStopAndRisk(app_config, params) {
|
|
63632
|
-
const { max_size, target_stop } = params;
|
|
63804
|
+
const { max_size, target_stop, distribution } = params;
|
|
63633
63805
|
const isLong = app_config.kind === "long";
|
|
63634
63806
|
const stopRange = Math.abs(app_config.entry - target_stop) * 0.5;
|
|
63635
63807
|
let low_stop = isLong ? target_stop - stopRange : Math.max(target_stop - stopRange, app_config.entry);
|
|
@@ -63652,7 +63824,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
63652
63824
|
increase: true,
|
|
63653
63825
|
gap: app_config.gap,
|
|
63654
63826
|
price_places: app_config.price_places,
|
|
63655
|
-
decimal_places: app_config.decimal_places
|
|
63827
|
+
decimal_places: app_config.decimal_places,
|
|
63828
|
+
distribution
|
|
63656
63829
|
});
|
|
63657
63830
|
if (result.length === 0) {
|
|
63658
63831
|
if (isLong) {
|
|
@@ -63706,7 +63879,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
63706
63879
|
increase: true,
|
|
63707
63880
|
gap: app_config.gap,
|
|
63708
63881
|
price_places: app_config.price_places,
|
|
63709
|
-
decimal_places: app_config.decimal_places
|
|
63882
|
+
decimal_places: app_config.decimal_places,
|
|
63883
|
+
distribution
|
|
63710
63884
|
});
|
|
63711
63885
|
if (result.length === 0) {
|
|
63712
63886
|
high_risk = mid_risk;
|
|
@@ -63751,7 +63925,8 @@ function getOptimumStopAndRisk(app_config, params) {
|
|
|
63751
63925
|
increase: true,
|
|
63752
63926
|
gap: app_config.gap,
|
|
63753
63927
|
price_places: app_config.price_places,
|
|
63754
|
-
decimal_places: app_config.decimal_places
|
|
63928
|
+
decimal_places: app_config.decimal_places,
|
|
63929
|
+
distribution
|
|
63755
63930
|
});
|
|
63756
63931
|
if (result.length === 0)
|
|
63757
63932
|
continue;
|
|
@@ -63874,7 +64049,8 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
63874
64049
|
}, {
|
|
63875
64050
|
entry: payload.entry,
|
|
63876
64051
|
stop: payload.stop,
|
|
63877
|
-
kind: position2.kind
|
|
64052
|
+
kind: position2.kind,
|
|
64053
|
+
distribution: payload.distribution
|
|
63878
64054
|
});
|
|
63879
64055
|
current_app_config.max_size = max_size;
|
|
63880
64056
|
current_app_config.last_value = last_value;
|
|
@@ -63889,7 +64065,8 @@ function generateOptimumAppConfig(config2, payload, position2) {
|
|
|
63889
64065
|
increase: true,
|
|
63890
64066
|
gap: current_app_config.gap,
|
|
63891
64067
|
price_places: current_app_config.price_places,
|
|
63892
|
-
decimal_places: current_app_config.decimal_places
|
|
64068
|
+
decimal_places: current_app_config.decimal_places,
|
|
64069
|
+
distribution: payload.distribution
|
|
63893
64070
|
});
|
|
63894
64071
|
if (full_trades.length === 0) {
|
|
63895
64072
|
high_risk = mid_risk;
|
|
@@ -63953,7 +64130,8 @@ function determineOptimumReward(payload) {
|
|
|
63953
64130
|
increase = true,
|
|
63954
64131
|
low_range = 1,
|
|
63955
64132
|
high_range = 199,
|
|
63956
|
-
target_loss
|
|
64133
|
+
target_loss,
|
|
64134
|
+
distribution
|
|
63957
64135
|
} = payload;
|
|
63958
64136
|
const criterion = app_config.strategy || "quantity";
|
|
63959
64137
|
const risk_rewards = createArray(low_range, high_range, 1);
|
|
@@ -63967,7 +64145,8 @@ function determineOptimumReward(payload) {
|
|
|
63967
64145
|
increase,
|
|
63968
64146
|
kind: app_config.kind,
|
|
63969
64147
|
gap: app_config.gap,
|
|
63970
|
-
decimal_places: app_config.decimal_places
|
|
64148
|
+
decimal_places: app_config.decimal_places,
|
|
64149
|
+
distribution
|
|
63971
64150
|
});
|
|
63972
64151
|
let total = 0;
|
|
63973
64152
|
let max = -Infinity;
|
|
@@ -64132,14 +64311,17 @@ function determineOptimumRisk(config2, payload, params) {
|
|
|
64132
64311
|
};
|
|
64133
64312
|
}
|
|
64134
64313
|
function computeRiskReward(payload) {
|
|
64135
|
-
const { app_config, entry, stop, risk_per_trade, target_loss } = payload;
|
|
64314
|
+
const { app_config, entry, stop, risk_per_trade, target_loss, distribution } = payload;
|
|
64136
64315
|
const kind = entry > stop ? "long" : "short";
|
|
64137
64316
|
app_config.kind = kind;
|
|
64138
64317
|
app_config.entry = entry;
|
|
64139
64318
|
app_config.stop = stop;
|
|
64140
64319
|
app_config.risk_per_trade = risk_per_trade;
|
|
64141
|
-
const result = determineOptimumReward({
|
|
64142
|
-
|
|
64320
|
+
const result = determineOptimumReward({
|
|
64321
|
+
app_config,
|
|
64322
|
+
target_loss,
|
|
64323
|
+
distribution
|
|
64324
|
+
});
|
|
64143
64325
|
return result;
|
|
64144
64326
|
}
|
|
64145
64327
|
function getRiskReward(payload) {
|
|
@@ -64149,21 +64331,24 @@ function getRiskReward(payload) {
|
|
|
64149
64331
|
risk,
|
|
64150
64332
|
global_config,
|
|
64151
64333
|
force_exact_risk = false,
|
|
64152
|
-
target_loss
|
|
64334
|
+
target_loss,
|
|
64335
|
+
distribution
|
|
64153
64336
|
} = payload;
|
|
64154
64337
|
const { entries, last_value, ...app_config } = buildAppConfig(global_config, {
|
|
64155
64338
|
entry,
|
|
64156
64339
|
stop,
|
|
64157
64340
|
risk_reward: 30,
|
|
64158
64341
|
risk,
|
|
64159
|
-
symbol: global_config.symbol
|
|
64342
|
+
symbol: global_config.symbol,
|
|
64343
|
+
distribution
|
|
64160
64344
|
});
|
|
64161
64345
|
const risk_reward = computeRiskReward({
|
|
64162
64346
|
app_config,
|
|
64163
64347
|
entry,
|
|
64164
64348
|
stop,
|
|
64165
64349
|
risk_per_trade: risk,
|
|
64166
|
-
target_loss
|
|
64350
|
+
target_loss,
|
|
64351
|
+
distribution
|
|
64167
64352
|
});
|
|
64168
64353
|
if (force_exact_risk) {
|
|
64169
64354
|
const new_risk_per_trade = determineOptimumRisk(global_config, {
|
|
@@ -64171,7 +64356,8 @@ function getRiskReward(payload) {
|
|
|
64171
64356
|
stop,
|
|
64172
64357
|
risk_reward,
|
|
64173
64358
|
risk,
|
|
64174
|
-
symbol: global_config.symbol
|
|
64359
|
+
symbol: global_config.symbol,
|
|
64360
|
+
distribution
|
|
64175
64361
|
}, {
|
|
64176
64362
|
highest_risk: risk
|
|
64177
64363
|
}).optimal_risk;
|
|
@@ -64528,7 +64714,7 @@ function constructAppConfig(payload) {
|
|
|
64528
64714
|
kelly_minimum_risk: kelly_config?.kelly_minimum_risk ?? kelly?.kelly_minimum_risk,
|
|
64529
64715
|
kelly_prediction_model: kelly_config?.kelly_prediction_model ?? kelly?.kelly_prediction_model
|
|
64530
64716
|
};
|
|
64531
|
-
const appConfig = buildAppConfig(global_config, options);
|
|
64717
|
+
const { entries: _entries, ...appConfig } = buildAppConfig(global_config, options);
|
|
64532
64718
|
return appConfig;
|
|
64533
64719
|
}
|
|
64534
64720
|
function generateDangerousConfig(payload) {
|
|
@@ -67526,6 +67712,19 @@ class ExchangePosition {
|
|
|
67526
67712
|
const { p_account } = this.instance.expand;
|
|
67527
67713
|
return p_account;
|
|
67528
67714
|
}
|
|
67715
|
+
get compound() {
|
|
67716
|
+
const { compound_instance } = this.instance.expand;
|
|
67717
|
+
if (compound_instance) {
|
|
67718
|
+
const { ref } = compound_instance.expand;
|
|
67719
|
+
const profit_percent = ref.profit_percent / 100;
|
|
67720
|
+
return {
|
|
67721
|
+
...compound_instance,
|
|
67722
|
+
profit_percent,
|
|
67723
|
+
amount_to_risk: to_f(compound_instance.risk * profit_percent, "%.2f")
|
|
67724
|
+
};
|
|
67725
|
+
}
|
|
67726
|
+
return compound_instance;
|
|
67727
|
+
}
|
|
67529
67728
|
async getProxyForAccount() {
|
|
67530
67729
|
if (this.instance.expand.proxy) {
|
|
67531
67730
|
const result = this.instance.expand.proxy;
|
|
@@ -67651,7 +67850,8 @@ class ExchangePosition {
|
|
|
67651
67850
|
place,
|
|
67652
67851
|
raw: payload.raw,
|
|
67653
67852
|
use_current,
|
|
67654
|
-
stop_percent: config2.stop_percent || 100
|
|
67853
|
+
stop_percent: config2.stop_percent || 100,
|
|
67854
|
+
distribution: config2.distribution
|
|
67655
67855
|
});
|
|
67656
67856
|
}
|
|
67657
67857
|
}
|
|
@@ -67685,7 +67885,8 @@ class ExchangePosition {
|
|
|
67685
67885
|
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
67686
67886
|
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
67687
67887
|
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
67688
|
-
kelly_func: config2.kelly?.kelly_func
|
|
67888
|
+
kelly_func: config2.kelly?.kelly_func,
|
|
67889
|
+
distribution: config2.distribution
|
|
67689
67890
|
}, false);
|
|
67690
67891
|
if (payload.raw) {
|
|
67691
67892
|
let actual_orders_to_buy = await this.determineAmountToBuy({
|
|
@@ -67808,7 +68009,8 @@ class ExchangePosition {
|
|
|
67808
68009
|
kelly_confidence_factor: solution.kelly_confidence_factor,
|
|
67809
68010
|
kelly_minimum_risk: solution.kelly_minimum_risk,
|
|
67810
68011
|
kelly_prediction_model: solution.kelly_prediction_model,
|
|
67811
|
-
kelly_func: solution.kelly_func
|
|
68012
|
+
kelly_func: solution.kelly_func,
|
|
68013
|
+
distribution: solution.distribution
|
|
67812
68014
|
};
|
|
67813
68015
|
const trades = sortedBuildConfig(app_config, options);
|
|
67814
68016
|
const entry_orders = {
|
|
@@ -68200,6 +68402,7 @@ class ExchangePosition {
|
|
|
68200
68402
|
});
|
|
68201
68403
|
}
|
|
68202
68404
|
async generate_config_params(payload) {
|
|
68405
|
+
const db_config = await this.getConfig();
|
|
68203
68406
|
const { entry, stop, risk_reward, risk, with_trades = false } = payload;
|
|
68204
68407
|
const symbol = this.symbol;
|
|
68205
68408
|
const app_config = await this.buildAppConfig({
|
|
@@ -68232,7 +68435,8 @@ class ExchangePosition {
|
|
|
68232
68435
|
avg_size: 0,
|
|
68233
68436
|
neg_pnl: 0,
|
|
68234
68437
|
min_size: app_config2.min_size,
|
|
68235
|
-
symbol
|
|
68438
|
+
symbol,
|
|
68439
|
+
distribution: db_config.distribution
|
|
68236
68440
|
}, false);
|
|
68237
68441
|
config2.trades = trades;
|
|
68238
68442
|
}
|
|
@@ -68333,7 +68537,8 @@ class ExchangePosition {
|
|
|
68333
68537
|
kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
|
|
68334
68538
|
kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
|
|
68335
68539
|
kelly_prediction_model: config2.kelly?.kelly_prediction_model,
|
|
68336
|
-
kelly_func: config2.kelly?.kelly_func
|
|
68540
|
+
kelly_func: config2.kelly?.kelly_func,
|
|
68541
|
+
distribution: config2.distribution
|
|
68337
68542
|
});
|
|
68338
68543
|
const position2 = this.instance;
|
|
68339
68544
|
const orders_to_place = await this.determineAmountToBuy({
|
|
@@ -68531,50 +68736,43 @@ class ExchangePosition {
|
|
|
68531
68736
|
increase: false
|
|
68532
68737
|
});
|
|
68533
68738
|
}
|
|
68534
|
-
|
|
68535
|
-
|
|
68536
|
-
|
|
68537
|
-
|
|
68538
|
-
|
|
68539
|
-
|
|
68739
|
+
get support() {
|
|
68740
|
+
return this.instance.expand?.support;
|
|
68741
|
+
}
|
|
68742
|
+
get linkedConfig() {
|
|
68743
|
+
return this.instance.expand?.b_config;
|
|
68744
|
+
}
|
|
68745
|
+
get isActiveTrade() {
|
|
68746
|
+
const config2 = this.linkedConfig;
|
|
68540
68747
|
return {
|
|
68541
68748
|
config: config2,
|
|
68542
|
-
condition:
|
|
68543
|
-
supportTable
|
|
68749
|
+
condition: this.compound && this.support?.price === config2.stop
|
|
68544
68750
|
};
|
|
68545
68751
|
}
|
|
68546
68752
|
async updateCompound(payload) {
|
|
68547
68753
|
const pb = this.app_db.pb;
|
|
68548
|
-
const item =
|
|
68549
|
-
|
|
68550
|
-
}
|
|
68551
|
-
const {
|
|
68552
|
-
expand: { ref }
|
|
68553
|
-
} = item;
|
|
68554
|
-
const risk = item.risk;
|
|
68555
|
-
const percent = ref.profit_percent / 100;
|
|
68556
|
-
const new_risk = risk * (1 + percent);
|
|
68557
|
-
const { condition, supportTable, config: config2 } = await this.isActiveTrade();
|
|
68754
|
+
const item = this.compound;
|
|
68755
|
+
const new_risk = item.risk + item.amount_to_risk;
|
|
68756
|
+
const { condition, config: config2 } = this.isActiveTrade;
|
|
68558
68757
|
if (payload?.place && condition) {
|
|
68559
68758
|
await pb.collection("compound_instances").update(item.id, {
|
|
68560
68759
|
risk: new_risk
|
|
68561
68760
|
});
|
|
68562
68761
|
await pb.collection("scheduled_trades").update(config2.id, {
|
|
68563
|
-
profit: to_f(new_risk *
|
|
68762
|
+
profit: to_f(new_risk * item.profit_percent, "%.3f")
|
|
68564
68763
|
});
|
|
68565
68764
|
}
|
|
68566
68765
|
return {
|
|
68567
|
-
support:
|
|
68568
|
-
counter:
|
|
68569
|
-
new_risk
|
|
68766
|
+
support: this.support?.price,
|
|
68767
|
+
counter: this.support?.counter,
|
|
68768
|
+
new_risk,
|
|
68769
|
+
condition,
|
|
68770
|
+
stop: config2.stop
|
|
68570
68771
|
};
|
|
68571
68772
|
}
|
|
68572
68773
|
async cleanOnActiveCompoundInstance() {
|
|
68573
|
-
const
|
|
68574
|
-
|
|
68575
|
-
});
|
|
68576
|
-
const { condition } = await this.isActiveTrade();
|
|
68577
|
-
if (item && condition && this.instance.quantity === 0) {
|
|
68774
|
+
const { condition } = this.isActiveTrade;
|
|
68775
|
+
if (condition && this.instance.quantity === 0) {
|
|
68578
68776
|
await this.cancelOrders({ limit: true });
|
|
68579
68777
|
}
|
|
68580
68778
|
}
|