@gbozee/ultimate 0.0.2-200 → 0.0.2-202

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/index.js CHANGED
@@ -38652,20 +38652,20 @@ var require_axios2 = __commonJS((exports, module) => {
38652
38652
  var reduceDescriptors = (obj, reducer) => {
38653
38653
  const descriptors2 = Object.getOwnPropertyDescriptors(obj);
38654
38654
  const reducedDescriptors = {};
38655
- forEach2(descriptors2, (descriptor, name3) => {
38655
+ forEach2(descriptors2, (descriptor, name2) => {
38656
38656
  let ret;
38657
- if ((ret = reducer(descriptor, name3, obj)) !== false) {
38658
- reducedDescriptors[name3] = ret || descriptor;
38657
+ if ((ret = reducer(descriptor, name2, obj)) !== false) {
38658
+ reducedDescriptors[name2] = ret || descriptor;
38659
38659
  }
38660
38660
  });
38661
38661
  Object.defineProperties(obj, reducedDescriptors);
38662
38662
  };
38663
38663
  var freezeMethods = (obj) => {
38664
- reduceDescriptors(obj, (descriptor, name3) => {
38665
- if (isFunction(obj) && ["arguments", "caller", "callee"].indexOf(name3) !== -1) {
38664
+ reduceDescriptors(obj, (descriptor, name2) => {
38665
+ if (isFunction(obj) && ["arguments", "caller", "callee"].indexOf(name2) !== -1) {
38666
38666
  return false;
38667
38667
  }
38668
- const value2 = obj[name3];
38668
+ const value2 = obj[name2];
38669
38669
  if (!isFunction(value2))
38670
38670
  return;
38671
38671
  descriptor.enumerable = false;
@@ -38675,7 +38675,7 @@ var require_axios2 = __commonJS((exports, module) => {
38675
38675
  }
38676
38676
  if (!descriptor.set) {
38677
38677
  descriptor.set = () => {
38678
- throw Error("Can not rewrite read-only method '" + name3 + "'");
38678
+ throw Error("Can not rewrite read-only method '" + name2 + "'");
38679
38679
  };
38680
38680
  }
38681
38681
  });
@@ -38983,8 +38983,8 @@ var require_axios2 = __commonJS((exports, module) => {
38983
38983
  params && toFormData(params, this, options);
38984
38984
  }
38985
38985
  var prototype = AxiosURLSearchParams.prototype;
38986
- prototype.append = function append(name3, value2) {
38987
- this._pairs.push([name3, value2]);
38986
+ prototype.append = function append(name2, value2) {
38987
+ this._pairs.push([name2, value2]);
38988
38988
  };
38989
38989
  prototype.toString = function toString(encoder2) {
38990
38990
  const _encode = encoder2 ? function(value2) {
@@ -39120,8 +39120,8 @@ var require_axios2 = __commonJS((exports, module) => {
39120
39120
  }
39121
39121
  }, options));
39122
39122
  }
39123
- function parsePropPath(name3) {
39124
- return utils$1.matchAll(/\w+|\[(\w*)]/g, name3).map((match) => {
39123
+ function parsePropPath(name2) {
39124
+ return utils$1.matchAll(/\w+|\[(\w*)]/g, name2).map((match) => {
39125
39125
  return match[0] === "[]" ? "" : match[1] || match[0];
39126
39126
  });
39127
39127
  }
@@ -39139,33 +39139,33 @@ var require_axios2 = __commonJS((exports, module) => {
39139
39139
  }
39140
39140
  function formDataToJSON(formData) {
39141
39141
  function buildPath(path, value2, target, index) {
39142
- let name3 = path[index++];
39143
- if (name3 === "__proto__")
39142
+ let name2 = path[index++];
39143
+ if (name2 === "__proto__")
39144
39144
  return true;
39145
- const isNumericKey = Number.isFinite(+name3);
39145
+ const isNumericKey = Number.isFinite(+name2);
39146
39146
  const isLast = index >= path.length;
39147
- name3 = !name3 && utils$1.isArray(target) ? target.length : name3;
39147
+ name2 = !name2 && utils$1.isArray(target) ? target.length : name2;
39148
39148
  if (isLast) {
39149
- if (utils$1.hasOwnProp(target, name3)) {
39150
- target[name3] = [target[name3], value2];
39149
+ if (utils$1.hasOwnProp(target, name2)) {
39150
+ target[name2] = [target[name2], value2];
39151
39151
  } else {
39152
- target[name3] = value2;
39152
+ target[name2] = value2;
39153
39153
  }
39154
39154
  return !isNumericKey;
39155
39155
  }
39156
- if (!target[name3] || !utils$1.isObject(target[name3])) {
39157
- target[name3] = [];
39156
+ if (!target[name2] || !utils$1.isObject(target[name2])) {
39157
+ target[name2] = [];
39158
39158
  }
39159
- const result = buildPath(path, value2, target[name3], index);
39160
- if (result && utils$1.isArray(target[name3])) {
39161
- target[name3] = arrayToObject(target[name3]);
39159
+ const result = buildPath(path, value2, target[name2], index);
39160
+ if (result && utils$1.isArray(target[name2])) {
39161
+ target[name2] = arrayToObject(target[name2]);
39162
39162
  }
39163
39163
  return !isNumericKey;
39164
39164
  }
39165
39165
  if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
39166
39166
  const obj = {};
39167
- utils$1.forEachEntry(formData, (name3, value2) => {
39168
- buildPath(parsePropPath(name3), value2, obj, 0);
39167
+ utils$1.forEachEntry(formData, (name2, value2) => {
39168
+ buildPath(parsePropPath(name2), value2, obj, 0);
39169
39169
  });
39170
39170
  return obj;
39171
39171
  }
@@ -39744,10 +39744,10 @@ var require_axios2 = __commonJS((exports, module) => {
39744
39744
  var CRLF_BYTES_COUNT = 2;
39745
39745
 
39746
39746
  class FormDataPart {
39747
- constructor(name3, value2) {
39747
+ constructor(name2, value2) {
39748
39748
  const { escapeName } = this.constructor;
39749
39749
  const isStringValue = utils$1.isString(value2);
39750
- let headers = `Content-Disposition: form-data; name="${escapeName(name3)}"${!isStringValue && value2.name ? `; filename="${escapeName(value2.name)}"` : ""}${CRLF}`;
39750
+ let headers = `Content-Disposition: form-data; name="${escapeName(name2)}"${!isStringValue && value2.name ? `; filename="${escapeName(value2.name)}"` : ""}${CRLF}`;
39751
39751
  if (isStringValue) {
39752
39752
  value2 = textEncoder.encode(String(value2).replace(/\r?\n|\r\n?/g, CRLF));
39753
39753
  } else {
@@ -39756,7 +39756,7 @@ var require_axios2 = __commonJS((exports, module) => {
39756
39756
  this.headers = textEncoder.encode(headers + CRLF);
39757
39757
  this.contentLength = isStringValue ? value2.byteLength : value2.size;
39758
39758
  this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
39759
- this.name = name3;
39759
+ this.name = name2;
39760
39760
  this.value = value2;
39761
39761
  }
39762
39762
  async* encode() {
@@ -39769,8 +39769,8 @@ var require_axios2 = __commonJS((exports, module) => {
39769
39769
  }
39770
39770
  yield CRLF_BYTES;
39771
39771
  }
39772
- static escapeName(name3) {
39773
- return String(name3).replace(/[\r\n"]/g, (match) => ({
39772
+ static escapeName(name2) {
39773
+ return String(name2).replace(/[\r\n"]/g, (match) => ({
39774
39774
  "\r": "%0D",
39775
39775
  "\n": "%0A",
39776
39776
  '"': "%22"
@@ -39792,8 +39792,8 @@ var require_axios2 = __commonJS((exports, module) => {
39792
39792
  const boundaryBytes = textEncoder.encode("--" + boundary + CRLF);
39793
39793
  const footerBytes = textEncoder.encode("--" + boundary + "--" + CRLF + CRLF);
39794
39794
  let contentLength = footerBytes.byteLength;
39795
- const parts = Array.from(form.entries()).map(([name3, value2]) => {
39796
- const part = new FormDataPart(name3, value2);
39795
+ const parts = Array.from(form.entries()).map(([name2, value2]) => {
39796
+ const part = new FormDataPart(name2, value2);
39797
39797
  contentLength += part.size;
39798
39798
  return part;
39799
39799
  });
@@ -40401,20 +40401,20 @@ var require_axios2 = __commonJS((exports, module) => {
40401
40401
  return origin2.protocol === url2.protocol && origin2.host === url2.host && (isMSIE || origin2.port === url2.port);
40402
40402
  })(new URL(platform.origin), platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)) : () => true;
40403
40403
  var cookies = platform.hasStandardBrowserEnv ? {
40404
- write(name3, value2, expires, path, domain, secure) {
40405
- const cookie = [name3 + "=" + encodeURIComponent(value2)];
40404
+ write(name2, value2, expires, path, domain, secure) {
40405
+ const cookie = [name2 + "=" + encodeURIComponent(value2)];
40406
40406
  utils$1.isNumber(expires) && cookie.push("expires=" + new Date(expires).toGMTString());
40407
40407
  utils$1.isString(path) && cookie.push("path=" + path);
40408
40408
  utils$1.isString(domain) && cookie.push("domain=" + domain);
40409
40409
  secure === true && cookie.push("secure");
40410
40410
  document.cookie = cookie.join("; ");
40411
40411
  },
40412
- read(name3) {
40413
- const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name3 + ")=([^;]*)"));
40412
+ read(name2) {
40413
+ const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name2 + ")=([^;]*)"));
40414
40414
  return match ? decodeURIComponent(match[3]) : null;
40415
40415
  },
40416
- remove(name3) {
40417
- this.write(name3, "", Date.now() - 86400000);
40416
+ remove(name2) {
40417
+ this.write(name2, "", Date.now() - 86400000);
40418
40418
  }
40419
40419
  } : {
40420
40420
  write() {},
@@ -56087,7 +56087,6 @@ class Signal {
56087
56087
  let potentials = new_result.filter((x) => condition(x["entry"], i2["risk_sell"])).map((x) => x["entry"]);
56088
56088
  if (potentials.length && max_index) {
56089
56089
  if (kind === "long") {
56090
- console.log("slice: ", potentials.slice(0, max_index));
56091
56090
  i2["risk_sell"] = Math.max(...potentials.slice(0, max_index));
56092
56091
  } else {
56093
56092
  i2["risk_sell"] = Math.min(...potentials.slice(0, max_index));
@@ -56151,7 +56150,6 @@ class Signal {
56151
56150
  }) {
56152
56151
  const margin_zones = [this.support, this.resistance];
56153
56152
  const distribution = this.distribution ? this.distribution[kind] : "geometric";
56154
- console.log("margin_zones", { margin_zones, distribution });
56155
56153
  let _kind = distribution === "inverse-exponential" ? kind === "long" ? "short" : "long" : kind;
56156
56154
  const entries = distributions_default({
56157
56155
  margin_range: margin_zones,
@@ -56370,7 +56368,6 @@ class Signal {
56370
56368
  }
56371
56369
  });
56372
56370
  risk_to_use = theoretical_kelly * risk_per_trade / this.kelly_minimum_risk;
56373
- console.log({ risk_per_trade, theoretical_kelly });
56374
56371
  }
56375
56372
  const y = this.build_trade_dict({
56376
56373
  entry: x,
@@ -56870,7 +56867,6 @@ function buildConfig(app_config, {
56870
56867
  }
56871
56868
  const condition = (kind === "long" ? entry > app_config.support : entry >= app_config.support) && stop >= app_config.support * 0.999;
56872
56869
  if (kind === "short") {}
56873
- console.log({ entry, stop, condition, working_risk, config: config2 });
56874
56870
  const result = entry === stop ? [] : condition ? instance.build_entry({
56875
56871
  current_price: entry,
56876
56872
  stop_loss: stop,
@@ -57526,6 +57522,7 @@ function computeRiskReward(payload) {
57526
57522
  risk_per_trade,
57527
57523
  target_loss,
57528
57524
  distribution,
57525
+ high_range,
57529
57526
  max_size
57530
57527
  } = payload;
57531
57528
  const kind = entry > stop ? "long" : "short";
@@ -57537,12 +57534,14 @@ function computeRiskReward(payload) {
57537
57534
  app_config,
57538
57535
  target_loss,
57539
57536
  distribution,
57537
+ high_range,
57540
57538
  max_size
57541
57539
  });
57542
57540
  return result;
57543
57541
  }
57544
57542
  function getRiskReward(payload) {
57545
57543
  const {
57544
+ high_range,
57546
57545
  max_size,
57547
57546
  entry,
57548
57547
  stop,
@@ -57566,6 +57565,7 @@ function getRiskReward(payload) {
57566
57565
  entry,
57567
57566
  stop,
57568
57567
  risk_per_trade: risk,
57568
+ high_range,
57569
57569
  target_loss,
57570
57570
  distribution,
57571
57571
  max_size
@@ -58560,7 +58560,420 @@ class Strategy {
58560
58560
  }
58561
58561
  }
58562
58562
  // src/helpers/compound.ts
58563
- var name2 = "";
58563
+ function buildTrades(payload) {
58564
+ const { appConfig, settings, kind } = payload;
58565
+ const kelly_config = settings.kelly;
58566
+ const current_app_config = { ...appConfig[kind] };
58567
+ const entryNum = parseFloat(settings.entry);
58568
+ const stopNum = parseFloat(settings.stop);
58569
+ current_app_config.entry = entryNum;
58570
+ current_app_config.stop = stopNum;
58571
+ current_app_config.risk_per_trade = parseFloat(settings.risk);
58572
+ current_app_config.risk_reward = parseFloat(settings.risk_reward);
58573
+ current_app_config.kind = kind;
58574
+ current_app_config.kelly = kelly_config;
58575
+ const options = {
58576
+ take_profit: null,
58577
+ entry: current_app_config.entry,
58578
+ stop: current_app_config.stop,
58579
+ raw_instance: null,
58580
+ risk: current_app_config.risk_per_trade,
58581
+ no_of_trades: undefined,
58582
+ risk_reward: current_app_config.risk_reward,
58583
+ kind: current_app_config.kind,
58584
+ increase: true,
58585
+ gap: current_app_config.gap,
58586
+ rr: current_app_config.rr,
58587
+ price_places: current_app_config.price_places,
58588
+ decimal_places: current_app_config.decimal_places,
58589
+ use_kelly: kelly_config?.use_kelly,
58590
+ kelly_confidence_factor: kelly_config?.kelly_confidence_factor,
58591
+ kelly_minimum_risk: kelly_config?.kelly_minimum_risk,
58592
+ kelly_prediction_model: kelly_config?.kelly_prediction_model,
58593
+ kelly_func: kelly_config?.kelly_func,
58594
+ distribution: settings.distribution
58595
+ };
58596
+ if (kind === "long" && entryNum <= stopNum) {
58597
+ return [];
58598
+ }
58599
+ if (kind === "short" && entryNum >= stopNum) {
58600
+ return [];
58601
+ }
58602
+ try {
58603
+ const generatedTrades = sortedBuildConfig(current_app_config, options);
58604
+ return generatedTrades ?? [];
58605
+ } catch (error) {
58606
+ console.error("Error generating orders:", error);
58607
+ return [];
58608
+ }
58609
+ }
58610
+ function generateSummary({
58611
+ trades,
58612
+ fee_percent = 0.05,
58613
+ anchor
58614
+ }) {
58615
+ const avg_entry = trades[0].avg_entry;
58616
+ const avg_size = trades[0].avg_size;
58617
+ const expected_fee = avg_entry * avg_size * fee_percent / 100;
58618
+ return {
58619
+ first_entry: trades.at(-1).entry,
58620
+ last_entry: trades[0].entry,
58621
+ quantity: avg_size,
58622
+ entry: avg_entry,
58623
+ loss: trades[0].neg_pnl,
58624
+ number_of_trades: trades.length,
58625
+ fee: to_f(expected_fee, "%.2f"),
58626
+ anchor_pnl: anchor?.target_pnl
58627
+ };
58628
+ }
58629
+ function helperFuncToBuildTrades({
58630
+ custom_b_config,
58631
+ symbol_config,
58632
+ app_config_kind,
58633
+ appConfig,
58634
+ force_exact_risk = true
58635
+ }) {
58636
+ const risk = custom_b_config.risk * (custom_b_config.risk_factor || 1);
58637
+ let result = getRiskReward({
58638
+ entry: custom_b_config.entry,
58639
+ stop: custom_b_config.stop,
58640
+ risk,
58641
+ global_config: symbol_config,
58642
+ force_exact_risk,
58643
+ target_loss: custom_b_config.risk * (custom_b_config.risk_factor || 1),
58644
+ distribution: custom_b_config.distribution
58645
+ });
58646
+ if (!force_exact_risk) {
58647
+ result = {
58648
+ risk_reward: result,
58649
+ risk
58650
+ };
58651
+ }
58652
+ const trades = result.risk_reward ? buildTrades({
58653
+ appConfig: { [app_config_kind]: appConfig },
58654
+ kind: app_config_kind,
58655
+ settings: {
58656
+ entry: custom_b_config.entry,
58657
+ stop: custom_b_config.stop,
58658
+ risk: result.risk || custom_b_config.risk,
58659
+ risk_reward: result.risk_reward,
58660
+ distribution: custom_b_config.distribution
58661
+ }
58662
+ }) : [];
58663
+ const summary = trades.length > 0 ? generateSummary({ trades }) : {};
58664
+ return { trades, result, summary };
58665
+ }
58666
+ function constructAppConfig2({
58667
+ config: config2,
58668
+ global_config
58669
+ }) {
58670
+ const options = {
58671
+ entry: config2?.entry,
58672
+ stop: config2?.stop,
58673
+ risk_reward: config2?.risk_reward,
58674
+ risk: config2?.risk,
58675
+ symbol: config2.symbol
58676
+ };
58677
+ const { entries: _entries, ...appConfig } = buildAppConfig(global_config, options);
58678
+ return appConfig;
58679
+ }
58680
+ function buildWithOptimumReward({
58681
+ config: config2,
58682
+ settings,
58683
+ global_config,
58684
+ force_exact
58685
+ }) {
58686
+ const kind = config2.entry > config2.stop ? "long" : "short";
58687
+ let stop = settings.stop;
58688
+ let entry = settings.entry;
58689
+ const risk = settings.risk;
58690
+ const stop_ratio = settings.stop_ratio || 1;
58691
+ const distribution = settings.distribution || config2?.distribution;
58692
+ const custom_b_config = {
58693
+ entry,
58694
+ stop,
58695
+ risk,
58696
+ distribution
58697
+ };
58698
+ const appConfig = constructAppConfig2({
58699
+ config: config2,
58700
+ global_config
58701
+ });
58702
+ const { trades, summary, result } = helperFuncToBuildTrades({
58703
+ custom_b_config,
58704
+ app_config_kind: kind,
58705
+ appConfig,
58706
+ symbol_config: global_config,
58707
+ force_exact_risk: force_exact
58708
+ });
58709
+ const adjusted_size = summary.quantity;
58710
+ const symbol_config = global_config;
58711
+ const entryDetails = {
58712
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
58713
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
58714
+ risk: to_f(result.risk, "%.2f"),
58715
+ risk_reward: result.risk_reward,
58716
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
58717
+ avg_size: to_f(adjusted_size, symbol_config.decimal_places),
58718
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
58719
+ pnl: to_f(custom_b_config.risk, "%.2f"),
58720
+ fee: to_f(summary.fee, "%.2f"),
58721
+ loss: to_f(summary.loss, "%.2f"),
58722
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
58723
+ margin: to_f(summary.entry * adjusted_size / symbol_config.leverage, "%.2f")
58724
+ };
58725
+ return {
58726
+ trades,
58727
+ summary: entryDetails,
58728
+ config: {
58729
+ ...custom_b_config,
58730
+ ...result,
58731
+ stop_ratio
58732
+ },
58733
+ stop_order: {
58734
+ quantity: entryDetails.avg_size * stop_ratio,
58735
+ price: entryDetails.stop
58736
+ },
58737
+ kind
58738
+ };
58739
+ }
58740
+ function generateOppositeOptimum({
58741
+ config: config2,
58742
+ global_config,
58743
+ settings,
58744
+ ratio = 1,
58745
+ distribution,
58746
+ risk_factor = 1
58747
+ }) {
58748
+ const configKind = config2.entry > config2.stop ? "long" : "short";
58749
+ if (configKind === "long" && config2.entry > config2.stop) {
58750
+ if (settings.stop <= settings.entry) {
58751
+ throw new Error("Invalid input: For long config positions, opposite settings must have stop > entry");
58752
+ }
58753
+ } else if (configKind === "short" && config2.entry < config2.stop) {
58754
+ if (settings.stop >= settings.entry) {
58755
+ throw new Error("Invalid input: For short config positions, opposite settings must have stop < entry");
58756
+ }
58757
+ }
58758
+ const kind = config2.entry > config2.stop ? "long" : "short";
58759
+ const app_config_kind = kind === "long" ? "short" : "long";
58760
+ let risk = settings.risk;
58761
+ const custom_b_config = {
58762
+ entry: settings.entry,
58763
+ stop: settings.stop,
58764
+ risk: risk * ratio,
58765
+ distribution: distribution || "inverse-exponential",
58766
+ risk_factor
58767
+ };
58768
+ const appConfig = constructAppConfig2({
58769
+ config: {
58770
+ ...config2,
58771
+ ...custom_b_config
58772
+ },
58773
+ global_config
58774
+ });
58775
+ const { result, trades, summary } = helperFuncToBuildTrades({
58776
+ custom_b_config,
58777
+ symbol_config: global_config,
58778
+ app_config_kind,
58779
+ appConfig
58780
+ });
58781
+ if (Object.keys(summary).length === 0) {
58782
+ return {
58783
+ trades,
58784
+ summary,
58785
+ config: custom_b_config,
58786
+ kind: app_config_kind
58787
+ };
58788
+ }
58789
+ const symbol_config = global_config;
58790
+ const entryDetails = {
58791
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
58792
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
58793
+ risk: to_f(result.risk, "%.2f"),
58794
+ risk_reward: result.risk_reward,
58795
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
58796
+ avg_size: to_f(summary.quantity, symbol_config.decimal_places),
58797
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
58798
+ pnl: to_f(custom_b_config.risk, "%.2f"),
58799
+ fee: to_f(summary.fee, "%.2f"),
58800
+ loss: to_f(summary.loss, "%.2f"),
58801
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
58802
+ defaultEntry: settings.entry ? to_f(settings.entry, symbol_config.price_places) : null
58803
+ };
58804
+ return {
58805
+ trades,
58806
+ summary: entryDetails,
58807
+ config: {
58808
+ ...custom_b_config,
58809
+ ...result
58810
+ },
58811
+ kind: app_config_kind
58812
+ };
58813
+ }
58814
+ function defaultTradeFromCurrentState({
58815
+ config: config2,
58816
+ global_config
58817
+ }) {
58818
+ const kind = config2.entry > config2.stop ? "long" : "short";
58819
+ const settings = {
58820
+ entry: config2?.entry,
58821
+ stop: config2?.stop,
58822
+ risk: config2?.risk,
58823
+ distribution: config2?.distribution,
58824
+ risk_reward: config2?.risk_reward
58825
+ };
58826
+ const appConfig = constructAppConfig2({
58827
+ config: config2,
58828
+ global_config
58829
+ });
58830
+ const trades = buildTrades({
58831
+ appConfig: { [kind]: appConfig },
58832
+ kind,
58833
+ settings
58834
+ });
58835
+ return {
58836
+ trades,
58837
+ summary: generateSummary({
58838
+ trades,
58839
+ fee_percent: global_config.fee_percent
58840
+ })
58841
+ };
58842
+ }
58843
+ function increaseTradeHelper({
58844
+ increase_qty,
58845
+ stop,
58846
+ config: config2,
58847
+ global_config,
58848
+ style,
58849
+ entry,
58850
+ position: position2,
58851
+ stop_ratio = 1,
58852
+ distribution: default_distribution
58853
+ }) {
58854
+ const symbol_config = global_config;
58855
+ const kind = config2.entry > config2.stop ? "long" : "short";
58856
+ const distribution = default_distribution || config2.distribution || "inverse-exponential";
58857
+ const appConfig = constructAppConfig2({
58858
+ config: config2,
58859
+ global_config
58860
+ });
58861
+ const currentState = defaultTradeFromCurrentState({
58862
+ config: config2,
58863
+ global_config
58864
+ });
58865
+ const { optimal_risk, neg_pnl } = getOptimumStopAndRisk(appConfig, {
58866
+ max_size: increase_qty,
58867
+ target_stop: stop,
58868
+ distribution
58869
+ });
58870
+ if (neg_pnl === 0) {
58871
+ return {
58872
+ trades: [],
58873
+ summary: {},
58874
+ config: {},
58875
+ kind,
58876
+ current: currentState
58877
+ };
58878
+ }
58879
+ const custom_b_config = {
58880
+ entry,
58881
+ stop,
58882
+ risk: style === "minimum" ? Math.abs(neg_pnl) : optimal_risk,
58883
+ distribution
58884
+ };
58885
+ const { result, trades, summary } = helperFuncToBuildTrades({
58886
+ custom_b_config,
58887
+ symbol_config,
58888
+ appConfig,
58889
+ app_config_kind: kind
58890
+ });
58891
+ if (Object.keys(summary).length === 0) {
58892
+ return {
58893
+ trades,
58894
+ summary,
58895
+ config: {
58896
+ ...custom_b_config,
58897
+ ...result
58898
+ },
58899
+ kind,
58900
+ current: currentState
58901
+ };
58902
+ }
58903
+ const new_avg_values = determine_average_entry_and_size([
58904
+ {
58905
+ price: position2.entry,
58906
+ quantity: position2.quantity
58907
+ },
58908
+ {
58909
+ price: summary?.entry,
58910
+ quantity: summary?.quantity
58911
+ }
58912
+ ], symbol_config.decimal_places, symbol_config.price_places);
58913
+ summary.entry = new_avg_values.entry;
58914
+ summary.quantity = new_avg_values.quantity;
58915
+ const loss = Math.abs(summary.entry - custom_b_config.stop) * summary.quantity;
58916
+ const entryDetails = {
58917
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
58918
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
58919
+ risk: to_f(result.risk, symbol_config.price_places),
58920
+ risk_reward: result.risk_reward,
58921
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
58922
+ avg_size: to_f(summary.quantity, symbol_config.decimal_places),
58923
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
58924
+ pnl: to_f(custom_b_config.risk, "%.2f"),
58925
+ fee: to_f(summary.fee, "%.2f"),
58926
+ loss: to_f(loss, "%.2f"),
58927
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
58928
+ margin: to_f(summary.entry * summary.quantity / global_config.leverage, "%.2f")
58929
+ };
58930
+ return {
58931
+ trades,
58932
+ summary: entryDetails,
58933
+ stop_order: {
58934
+ quantity: entryDetails.avg_size * stop_ratio,
58935
+ price: entryDetails.stop
58936
+ },
58937
+ config: {
58938
+ ...custom_b_config,
58939
+ ...result
58940
+ },
58941
+ kind,
58942
+ current: currentState
58943
+ };
58944
+ }
58945
+ function generatePositionIncreaseTrade({
58946
+ account,
58947
+ zoneAccount,
58948
+ ratio = 0.1,
58949
+ config: config2,
58950
+ global_config,
58951
+ style = "minimum",
58952
+ distribution = "inverse-exponential"
58953
+ }) {
58954
+ const kind = config2.entry > config2.stop ? "long" : "short";
58955
+ const target_max_quantity = kind === "long" ? account.short.quantity : account.long.quantity;
58956
+ const increase_qty = target_max_quantity * ratio;
58957
+ const entry = zoneAccount.entry;
58958
+ const stop = zoneAccount.stop;
58959
+ return increaseTradeHelper({
58960
+ config: config2,
58961
+ position: account[kind],
58962
+ global_config,
58963
+ entry,
58964
+ stop,
58965
+ style,
58966
+ increase_qty,
58967
+ distribution
58968
+ });
58969
+ }
58970
+ var compoundAPI = {
58971
+ buildWithOptimumReward,
58972
+ constructAppConfig: constructAppConfig2,
58973
+ generateOppositeOptimum,
58974
+ increaseTradeHelper,
58975
+ generatePositionIncreaseTrade
58976
+ };
58564
58977
  // src/types/index.ts
58565
58978
  class BaseExchange {
58566
58979
  client;
@@ -64761,7 +65174,6 @@ async function initialize(payload) {
64761
65174
  }
64762
65175
  export {
64763
65176
  sortedBuildConfig,
64764
- name2 as name,
64765
65177
  initialize,
64766
65178
  initApp,
64767
65179
  get_app_config_and_max_size,
@@ -64787,6 +65199,7 @@ export {
64787
65199
  constructAppConfig,
64788
65200
  computeRiskReward,
64789
65201
  computeProfitDetail,
65202
+ compoundAPI,
64790
65203
  calculateFactorFromTakeProfit,
64791
65204
  calculateFactorFromSellQuantity,
64792
65205
  buildConfig,