@gbozee/ultimate 0.0.2-200 → 0.0.2-201

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.cjs CHANGED
@@ -38677,20 +38677,20 @@ var require_axios2 = __commonJS((exports2, module2) => {
38677
38677
  var reduceDescriptors = (obj, reducer) => {
38678
38678
  const descriptors2 = Object.getOwnPropertyDescriptors(obj);
38679
38679
  const reducedDescriptors = {};
38680
- forEach2(descriptors2, (descriptor, name3) => {
38680
+ forEach2(descriptors2, (descriptor, name2) => {
38681
38681
  let ret;
38682
- if ((ret = reducer(descriptor, name3, obj)) !== false) {
38683
- reducedDescriptors[name3] = ret || descriptor;
38682
+ if ((ret = reducer(descriptor, name2, obj)) !== false) {
38683
+ reducedDescriptors[name2] = ret || descriptor;
38684
38684
  }
38685
38685
  });
38686
38686
  Object.defineProperties(obj, reducedDescriptors);
38687
38687
  };
38688
38688
  var freezeMethods = (obj) => {
38689
- reduceDescriptors(obj, (descriptor, name3) => {
38690
- if (isFunction(obj) && ["arguments", "caller", "callee"].indexOf(name3) !== -1) {
38689
+ reduceDescriptors(obj, (descriptor, name2) => {
38690
+ if (isFunction(obj) && ["arguments", "caller", "callee"].indexOf(name2) !== -1) {
38691
38691
  return false;
38692
38692
  }
38693
- const value2 = obj[name3];
38693
+ const value2 = obj[name2];
38694
38694
  if (!isFunction(value2))
38695
38695
  return;
38696
38696
  descriptor.enumerable = false;
@@ -38700,7 +38700,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
38700
38700
  }
38701
38701
  if (!descriptor.set) {
38702
38702
  descriptor.set = () => {
38703
- throw Error("Can not rewrite read-only method '" + name3 + "'");
38703
+ throw Error("Can not rewrite read-only method '" + name2 + "'");
38704
38704
  };
38705
38705
  }
38706
38706
  });
@@ -39008,8 +39008,8 @@ var require_axios2 = __commonJS((exports2, module2) => {
39008
39008
  params && toFormData(params, this, options);
39009
39009
  }
39010
39010
  var prototype = AxiosURLSearchParams.prototype;
39011
- prototype.append = function append(name3, value2) {
39012
- this._pairs.push([name3, value2]);
39011
+ prototype.append = function append(name2, value2) {
39012
+ this._pairs.push([name2, value2]);
39013
39013
  };
39014
39014
  prototype.toString = function toString(encoder2) {
39015
39015
  const _encode = encoder2 ? function(value2) {
@@ -39145,8 +39145,8 @@ var require_axios2 = __commonJS((exports2, module2) => {
39145
39145
  }
39146
39146
  }, options));
39147
39147
  }
39148
- function parsePropPath(name3) {
39149
- return utils$1.matchAll(/\w+|\[(\w*)]/g, name3).map((match) => {
39148
+ function parsePropPath(name2) {
39149
+ return utils$1.matchAll(/\w+|\[(\w*)]/g, name2).map((match) => {
39150
39150
  return match[0] === "[]" ? "" : match[1] || match[0];
39151
39151
  });
39152
39152
  }
@@ -39164,33 +39164,33 @@ var require_axios2 = __commonJS((exports2, module2) => {
39164
39164
  }
39165
39165
  function formDataToJSON(formData) {
39166
39166
  function buildPath(path, value2, target, index) {
39167
- let name3 = path[index++];
39168
- if (name3 === "__proto__")
39167
+ let name2 = path[index++];
39168
+ if (name2 === "__proto__")
39169
39169
  return true;
39170
- const isNumericKey = Number.isFinite(+name3);
39170
+ const isNumericKey = Number.isFinite(+name2);
39171
39171
  const isLast = index >= path.length;
39172
- name3 = !name3 && utils$1.isArray(target) ? target.length : name3;
39172
+ name2 = !name2 && utils$1.isArray(target) ? target.length : name2;
39173
39173
  if (isLast) {
39174
- if (utils$1.hasOwnProp(target, name3)) {
39175
- target[name3] = [target[name3], value2];
39174
+ if (utils$1.hasOwnProp(target, name2)) {
39175
+ target[name2] = [target[name2], value2];
39176
39176
  } else {
39177
- target[name3] = value2;
39177
+ target[name2] = value2;
39178
39178
  }
39179
39179
  return !isNumericKey;
39180
39180
  }
39181
- if (!target[name3] || !utils$1.isObject(target[name3])) {
39182
- target[name3] = [];
39181
+ if (!target[name2] || !utils$1.isObject(target[name2])) {
39182
+ target[name2] = [];
39183
39183
  }
39184
- const result = buildPath(path, value2, target[name3], index);
39185
- if (result && utils$1.isArray(target[name3])) {
39186
- target[name3] = arrayToObject(target[name3]);
39184
+ const result = buildPath(path, value2, target[name2], index);
39185
+ if (result && utils$1.isArray(target[name2])) {
39186
+ target[name2] = arrayToObject(target[name2]);
39187
39187
  }
39188
39188
  return !isNumericKey;
39189
39189
  }
39190
39190
  if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
39191
39191
  const obj = {};
39192
- utils$1.forEachEntry(formData, (name3, value2) => {
39193
- buildPath(parsePropPath(name3), value2, obj, 0);
39192
+ utils$1.forEachEntry(formData, (name2, value2) => {
39193
+ buildPath(parsePropPath(name2), value2, obj, 0);
39194
39194
  });
39195
39195
  return obj;
39196
39196
  }
@@ -39769,10 +39769,10 @@ var require_axios2 = __commonJS((exports2, module2) => {
39769
39769
  var CRLF_BYTES_COUNT = 2;
39770
39770
 
39771
39771
  class FormDataPart {
39772
- constructor(name3, value2) {
39772
+ constructor(name2, value2) {
39773
39773
  const { escapeName } = this.constructor;
39774
39774
  const isStringValue = utils$1.isString(value2);
39775
- let headers = `Content-Disposition: form-data; name="${escapeName(name3)}"${!isStringValue && value2.name ? `; filename="${escapeName(value2.name)}"` : ""}${CRLF}`;
39775
+ let headers = `Content-Disposition: form-data; name="${escapeName(name2)}"${!isStringValue && value2.name ? `; filename="${escapeName(value2.name)}"` : ""}${CRLF}`;
39776
39776
  if (isStringValue) {
39777
39777
  value2 = textEncoder.encode(String(value2).replace(/\r?\n|\r\n?/g, CRLF));
39778
39778
  } else {
@@ -39781,7 +39781,7 @@ var require_axios2 = __commonJS((exports2, module2) => {
39781
39781
  this.headers = textEncoder.encode(headers + CRLF);
39782
39782
  this.contentLength = isStringValue ? value2.byteLength : value2.size;
39783
39783
  this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
39784
- this.name = name3;
39784
+ this.name = name2;
39785
39785
  this.value = value2;
39786
39786
  }
39787
39787
  async* encode() {
@@ -39794,8 +39794,8 @@ var require_axios2 = __commonJS((exports2, module2) => {
39794
39794
  }
39795
39795
  yield CRLF_BYTES;
39796
39796
  }
39797
- static escapeName(name3) {
39798
- return String(name3).replace(/[\r\n"]/g, (match) => ({
39797
+ static escapeName(name2) {
39798
+ return String(name2).replace(/[\r\n"]/g, (match) => ({
39799
39799
  "\r": "%0D",
39800
39800
  "\n": "%0A",
39801
39801
  '"': "%22"
@@ -39817,8 +39817,8 @@ var require_axios2 = __commonJS((exports2, module2) => {
39817
39817
  const boundaryBytes = textEncoder.encode("--" + boundary + CRLF);
39818
39818
  const footerBytes = textEncoder.encode("--" + boundary + "--" + CRLF + CRLF);
39819
39819
  let contentLength = footerBytes.byteLength;
39820
- const parts = Array.from(form.entries()).map(([name3, value2]) => {
39821
- const part = new FormDataPart(name3, value2);
39820
+ const parts = Array.from(form.entries()).map(([name2, value2]) => {
39821
+ const part = new FormDataPart(name2, value2);
39822
39822
  contentLength += part.size;
39823
39823
  return part;
39824
39824
  });
@@ -40426,20 +40426,20 @@ var require_axios2 = __commonJS((exports2, module2) => {
40426
40426
  return origin2.protocol === url2.protocol && origin2.host === url2.host && (isMSIE || origin2.port === url2.port);
40427
40427
  })(new URL(platform.origin), platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)) : () => true;
40428
40428
  var cookies = platform.hasStandardBrowserEnv ? {
40429
- write(name3, value2, expires, path, domain, secure) {
40430
- const cookie = [name3 + "=" + encodeURIComponent(value2)];
40429
+ write(name2, value2, expires, path, domain, secure) {
40430
+ const cookie = [name2 + "=" + encodeURIComponent(value2)];
40431
40431
  utils$1.isNumber(expires) && cookie.push("expires=" + new Date(expires).toGMTString());
40432
40432
  utils$1.isString(path) && cookie.push("path=" + path);
40433
40433
  utils$1.isString(domain) && cookie.push("domain=" + domain);
40434
40434
  secure === true && cookie.push("secure");
40435
40435
  document.cookie = cookie.join("; ");
40436
40436
  },
40437
- read(name3) {
40438
- const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name3 + ")=([^;]*)"));
40437
+ read(name2) {
40438
+ const match = document.cookie.match(new RegExp("(^|;\\s*)(" + name2 + ")=([^;]*)"));
40439
40439
  return match ? decodeURIComponent(match[3]) : null;
40440
40440
  },
40441
- remove(name3) {
40442
- this.write(name3, "", Date.now() - 86400000);
40441
+ remove(name2) {
40442
+ this.write(name2, "", Date.now() - 86400000);
40443
40443
  }
40444
40444
  } : {
40445
40445
  write() {},
@@ -44876,7 +44876,6 @@ var require_lib3 = __commonJS((exports2) => {
44876
44876
  var exports_src = {};
44877
44877
  __export(exports_src, {
44878
44878
  sortedBuildConfig: () => sortedBuildConfig,
44879
- name: () => name2,
44880
44879
  initialize: () => initialize,
44881
44880
  initApp: () => initApp,
44882
44881
  get_app_config_and_max_size: () => get_app_config_and_max_size,
@@ -44902,6 +44901,7 @@ __export(exports_src, {
44902
44901
  constructAppConfig: () => constructAppConfig,
44903
44902
  computeRiskReward: () => computeRiskReward,
44904
44903
  computeProfitDetail: () => computeProfitDetail,
44904
+ compoundAPI: () => compoundAPI,
44905
44905
  calculateFactorFromTakeProfit: () => calculateFactorFromTakeProfit,
44906
44906
  calculateFactorFromSellQuantity: () => calculateFactorFromSellQuantity,
44907
44907
  buildConfig: () => buildConfig,
@@ -56150,7 +56150,6 @@ class Signal {
56150
56150
  let potentials = new_result.filter((x) => condition(x["entry"], i2["risk_sell"])).map((x) => x["entry"]);
56151
56151
  if (potentials.length && max_index) {
56152
56152
  if (kind === "long") {
56153
- console.log("slice: ", potentials.slice(0, max_index));
56154
56153
  i2["risk_sell"] = Math.max(...potentials.slice(0, max_index));
56155
56154
  } else {
56156
56155
  i2["risk_sell"] = Math.min(...potentials.slice(0, max_index));
@@ -56214,7 +56213,6 @@ class Signal {
56214
56213
  }) {
56215
56214
  const margin_zones = [this.support, this.resistance];
56216
56215
  const distribution = this.distribution ? this.distribution[kind] : "geometric";
56217
- console.log("margin_zones", { margin_zones, distribution });
56218
56216
  let _kind = distribution === "inverse-exponential" ? kind === "long" ? "short" : "long" : kind;
56219
56217
  const entries = distributions_default({
56220
56218
  margin_range: margin_zones,
@@ -56433,7 +56431,6 @@ class Signal {
56433
56431
  }
56434
56432
  });
56435
56433
  risk_to_use = theoretical_kelly * risk_per_trade / this.kelly_minimum_risk;
56436
- console.log({ risk_per_trade, theoretical_kelly });
56437
56434
  }
56438
56435
  const y = this.build_trade_dict({
56439
56436
  entry: x,
@@ -56933,7 +56930,6 @@ function buildConfig(app_config, {
56933
56930
  }
56934
56931
  const condition = (kind === "long" ? entry > app_config.support : entry >= app_config.support) && stop >= app_config.support * 0.999;
56935
56932
  if (kind === "short") {}
56936
- console.log({ entry, stop, condition, working_risk, config: config2 });
56937
56933
  const result = entry === stop ? [] : condition ? instance.build_entry({
56938
56934
  current_price: entry,
56939
56935
  stop_loss: stop,
@@ -58623,7 +58619,418 @@ class Strategy {
58623
58619
  }
58624
58620
  }
58625
58621
  // src/helpers/compound.ts
58626
- var name2 = "";
58622
+ function buildTrades(payload) {
58623
+ const { appConfig, settings, kind } = payload;
58624
+ const kelly_config = settings.kelly;
58625
+ const current_app_config = { ...appConfig[kind] };
58626
+ const entryNum = parseFloat(settings.entry);
58627
+ const stopNum = parseFloat(settings.stop);
58628
+ current_app_config.entry = entryNum;
58629
+ current_app_config.stop = stopNum;
58630
+ current_app_config.risk_per_trade = parseFloat(settings.risk);
58631
+ current_app_config.risk_reward = parseFloat(settings.risk_reward);
58632
+ current_app_config.kind = kind;
58633
+ current_app_config.kelly = kelly_config;
58634
+ const options = {
58635
+ take_profit: null,
58636
+ entry: current_app_config.entry,
58637
+ stop: current_app_config.stop,
58638
+ raw_instance: null,
58639
+ risk: current_app_config.risk_per_trade,
58640
+ no_of_trades: undefined,
58641
+ risk_reward: current_app_config.risk_reward,
58642
+ kind: current_app_config.kind,
58643
+ increase: true,
58644
+ gap: current_app_config.gap,
58645
+ rr: current_app_config.rr,
58646
+ price_places: current_app_config.price_places,
58647
+ decimal_places: current_app_config.decimal_places,
58648
+ use_kelly: kelly_config?.use_kelly,
58649
+ kelly_confidence_factor: kelly_config?.kelly_confidence_factor,
58650
+ kelly_minimum_risk: kelly_config?.kelly_minimum_risk,
58651
+ kelly_prediction_model: kelly_config?.kelly_prediction_model,
58652
+ kelly_func: kelly_config?.kelly_func,
58653
+ distribution: settings.distribution
58654
+ };
58655
+ if (kind === "long" && entryNum <= stopNum) {
58656
+ return [];
58657
+ }
58658
+ if (kind === "short" && entryNum >= stopNum) {
58659
+ return [];
58660
+ }
58661
+ try {
58662
+ const generatedTrades = sortedBuildConfig(current_app_config, options);
58663
+ return generatedTrades ?? [];
58664
+ } catch (error) {
58665
+ console.error("Error generating orders:", error);
58666
+ return [];
58667
+ }
58668
+ }
58669
+ function generateSummary({
58670
+ trades,
58671
+ fee_percent = 0.05,
58672
+ anchor
58673
+ }) {
58674
+ const avg_entry = trades[0].avg_entry;
58675
+ const avg_size = trades[0].avg_size;
58676
+ const expected_fee = avg_entry * avg_size * fee_percent / 100;
58677
+ return {
58678
+ first_entry: trades.at(-1).entry,
58679
+ last_entry: trades[0].entry,
58680
+ quantity: avg_size,
58681
+ entry: avg_entry,
58682
+ loss: trades[0].neg_pnl,
58683
+ number_of_trades: trades.length,
58684
+ fee: to_f(expected_fee, "%.2f"),
58685
+ anchor_pnl: anchor?.target_pnl
58686
+ };
58687
+ }
58688
+ function helperFuncToBuildTrades({
58689
+ custom_b_config,
58690
+ symbol_config,
58691
+ app_config_kind,
58692
+ appConfig,
58693
+ force_exact_risk = true
58694
+ }) {
58695
+ const risk = custom_b_config.risk * (custom_b_config.risk_factor || 1);
58696
+ let result = getRiskReward({
58697
+ entry: custom_b_config.entry,
58698
+ stop: custom_b_config.stop,
58699
+ risk,
58700
+ global_config: symbol_config,
58701
+ force_exact_risk,
58702
+ target_loss: custom_b_config.risk * (custom_b_config.risk_factor || 1),
58703
+ distribution: custom_b_config.distribution
58704
+ });
58705
+ if (!force_exact_risk) {
58706
+ result = {
58707
+ risk_reward: result,
58708
+ risk
58709
+ };
58710
+ }
58711
+ const trades = result.risk_reward ? buildTrades({
58712
+ appConfig: { [app_config_kind]: appConfig },
58713
+ kind: app_config_kind,
58714
+ settings: {
58715
+ entry: custom_b_config.entry,
58716
+ stop: custom_b_config.stop,
58717
+ risk: result.risk || custom_b_config.risk,
58718
+ risk_reward: result.risk_reward,
58719
+ distribution: custom_b_config.distribution
58720
+ }
58721
+ }) : [];
58722
+ const summary = trades.length > 0 ? generateSummary({ trades }) : {};
58723
+ return { trades, result, summary };
58724
+ }
58725
+ function constructAppConfig2({
58726
+ config: config2,
58727
+ global_config
58728
+ }) {
58729
+ const options = {
58730
+ entry: config2?.entry,
58731
+ stop: config2?.stop,
58732
+ risk_reward: config2?.risk_reward,
58733
+ risk: config2?.risk,
58734
+ symbol: config2.symbol
58735
+ };
58736
+ const { entries: _entries, ...appConfig } = buildAppConfig(global_config, options);
58737
+ return appConfig;
58738
+ }
58739
+ function buildWithOptimumReward({
58740
+ config: config2,
58741
+ settings,
58742
+ global_config
58743
+ }) {
58744
+ const kind = config2.entry > config2.stop ? "long" : "short";
58745
+ let stop = settings.stop;
58746
+ let entry = settings.entry;
58747
+ const risk = settings.risk;
58748
+ const stop_ratio = settings.stop_ratio || 1;
58749
+ const distribution = settings.distribution || config2?.distribution;
58750
+ const custom_b_config = {
58751
+ entry,
58752
+ stop,
58753
+ risk,
58754
+ distribution
58755
+ };
58756
+ const appConfig = constructAppConfig2({
58757
+ config: config2,
58758
+ global_config
58759
+ });
58760
+ const { trades, summary, result } = helperFuncToBuildTrades({
58761
+ custom_b_config,
58762
+ app_config_kind: kind,
58763
+ appConfig,
58764
+ symbol_config: global_config
58765
+ });
58766
+ const adjusted_size = summary.quantity;
58767
+ const symbol_config = global_config;
58768
+ const entryDetails = {
58769
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
58770
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
58771
+ risk: to_f(result.risk, "%.2f"),
58772
+ risk_reward: result.risk_reward,
58773
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
58774
+ avg_size: to_f(adjusted_size, symbol_config.decimal_places),
58775
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
58776
+ pnl: to_f(custom_b_config.risk, "%.2f"),
58777
+ fee: to_f(summary.fee, "%.2f"),
58778
+ loss: to_f(summary.loss, "%.2f"),
58779
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
58780
+ margin: to_f(summary.entry * adjusted_size / symbol_config.leverage, "%.2f")
58781
+ };
58782
+ return {
58783
+ trades,
58784
+ summary: entryDetails,
58785
+ config: {
58786
+ ...custom_b_config,
58787
+ ...result,
58788
+ stop_ratio
58789
+ },
58790
+ stop_order: {
58791
+ quantity: entryDetails.avg_size * stop_ratio,
58792
+ price: entryDetails.stop
58793
+ },
58794
+ kind
58795
+ };
58796
+ }
58797
+ function generateOppositeOptimum({
58798
+ config: config2,
58799
+ global_config,
58800
+ settings,
58801
+ ratio = 1,
58802
+ distribution,
58803
+ risk_factor = 1
58804
+ }) {
58805
+ const configKind = config2.entry > config2.stop ? "long" : "short";
58806
+ if (configKind === "long" && config2.entry > config2.stop) {
58807
+ if (settings.stop <= settings.entry) {
58808
+ throw new Error("Invalid input: For long config positions, opposite settings must have stop > entry");
58809
+ }
58810
+ } else if (configKind === "short" && config2.entry < config2.stop) {
58811
+ if (settings.stop >= settings.entry) {
58812
+ throw new Error("Invalid input: For short config positions, opposite settings must have stop < entry");
58813
+ }
58814
+ }
58815
+ const kind = config2.entry > config2.stop ? "long" : "short";
58816
+ const app_config_kind = kind === "long" ? "short" : "long";
58817
+ let risk = settings.risk;
58818
+ const custom_b_config = {
58819
+ entry: settings.entry,
58820
+ stop: settings.stop,
58821
+ risk: risk * ratio,
58822
+ distribution: distribution || "inverse-exponential",
58823
+ risk_factor
58824
+ };
58825
+ const appConfig = constructAppConfig2({
58826
+ config: {
58827
+ ...config2,
58828
+ ...custom_b_config
58829
+ },
58830
+ global_config
58831
+ });
58832
+ const { result, trades, summary } = helperFuncToBuildTrades({
58833
+ custom_b_config,
58834
+ symbol_config: global_config,
58835
+ app_config_kind,
58836
+ appConfig
58837
+ });
58838
+ if (Object.keys(summary).length === 0) {
58839
+ return {
58840
+ trades,
58841
+ summary,
58842
+ config: custom_b_config,
58843
+ kind: app_config_kind
58844
+ };
58845
+ }
58846
+ const symbol_config = global_config;
58847
+ const entryDetails = {
58848
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
58849
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
58850
+ risk: to_f(result.risk, "%.2f"),
58851
+ risk_reward: result.risk_reward,
58852
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
58853
+ avg_size: to_f(summary.quantity, symbol_config.decimal_places),
58854
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
58855
+ pnl: to_f(custom_b_config.risk, "%.2f"),
58856
+ fee: to_f(summary.fee, "%.2f"),
58857
+ loss: to_f(summary.loss, "%.2f"),
58858
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
58859
+ defaultEntry: settings.entry ? to_f(settings.entry, symbol_config.price_places) : null
58860
+ };
58861
+ return {
58862
+ trades,
58863
+ summary: entryDetails,
58864
+ config: {
58865
+ ...custom_b_config,
58866
+ ...result
58867
+ },
58868
+ kind: app_config_kind
58869
+ };
58870
+ }
58871
+ function defaultTradeFromCurrentState({
58872
+ config: config2,
58873
+ global_config
58874
+ }) {
58875
+ const kind = config2.entry > config2.stop ? "long" : "short";
58876
+ const settings = {
58877
+ entry: config2?.entry,
58878
+ stop: config2?.stop,
58879
+ risk: config2?.risk,
58880
+ distribution: config2?.distribution,
58881
+ risk_reward: config2?.risk_reward
58882
+ };
58883
+ const appConfig = constructAppConfig2({
58884
+ config: config2,
58885
+ global_config
58886
+ });
58887
+ const trades = buildTrades({
58888
+ appConfig: { [kind]: appConfig },
58889
+ kind,
58890
+ settings
58891
+ });
58892
+ return {
58893
+ trades,
58894
+ summary: generateSummary({
58895
+ trades,
58896
+ fee_percent: global_config.fee_percent
58897
+ })
58898
+ };
58899
+ }
58900
+ function increaseTradeHelper({
58901
+ increase_qty,
58902
+ stop,
58903
+ config: config2,
58904
+ global_config,
58905
+ style,
58906
+ entry,
58907
+ position: position2,
58908
+ stop_ratio = 1,
58909
+ distribution: default_distribution
58910
+ }) {
58911
+ const symbol_config = global_config;
58912
+ const kind = config2.entry > config2.stop ? "long" : "short";
58913
+ const distribution = default_distribution || config2.distribution || "inverse-exponential";
58914
+ const appConfig = constructAppConfig2({
58915
+ config: config2,
58916
+ global_config
58917
+ });
58918
+ const currentState = defaultTradeFromCurrentState({
58919
+ config: config2,
58920
+ global_config
58921
+ });
58922
+ const { optimal_risk, neg_pnl } = getOptimumStopAndRisk(appConfig, {
58923
+ max_size: increase_qty,
58924
+ target_stop: stop,
58925
+ distribution
58926
+ });
58927
+ if (neg_pnl === 0) {
58928
+ return {
58929
+ trades: [],
58930
+ summary: {},
58931
+ config: {},
58932
+ kind,
58933
+ current: currentState
58934
+ };
58935
+ }
58936
+ const custom_b_config = {
58937
+ entry,
58938
+ stop,
58939
+ risk: style === "minimum" ? Math.abs(neg_pnl) : optimal_risk,
58940
+ distribution
58941
+ };
58942
+ const { result, trades, summary } = helperFuncToBuildTrades({
58943
+ custom_b_config,
58944
+ symbol_config,
58945
+ appConfig,
58946
+ app_config_kind: kind
58947
+ });
58948
+ if (Object.keys(summary).length === 0) {
58949
+ return {
58950
+ trades,
58951
+ summary,
58952
+ config: {
58953
+ ...custom_b_config,
58954
+ ...result
58955
+ },
58956
+ kind,
58957
+ current: currentState
58958
+ };
58959
+ }
58960
+ const new_avg_values = determine_average_entry_and_size([
58961
+ {
58962
+ price: position2.entry,
58963
+ quantity: position2.quantity
58964
+ },
58965
+ {
58966
+ price: summary?.entry,
58967
+ quantity: summary?.quantity
58968
+ }
58969
+ ], symbol_config.decimal_places, symbol_config.price_places);
58970
+ summary.entry = new_avg_values.entry;
58971
+ summary.quantity = new_avg_values.quantity;
58972
+ const loss = Math.abs(summary.entry - custom_b_config.stop) * summary.quantity;
58973
+ const entryDetails = {
58974
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
58975
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
58976
+ risk: to_f(result.risk, symbol_config.price_places),
58977
+ risk_reward: result.risk_reward,
58978
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
58979
+ avg_size: to_f(summary.quantity, symbol_config.decimal_places),
58980
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
58981
+ pnl: to_f(custom_b_config.risk, "%.2f"),
58982
+ fee: to_f(summary.fee, "%.2f"),
58983
+ loss: to_f(loss, "%.2f"),
58984
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
58985
+ margin: to_f(summary.entry * summary.quantity / global_config.leverage, "%.2f")
58986
+ };
58987
+ return {
58988
+ trades,
58989
+ summary: entryDetails,
58990
+ stop_order: {
58991
+ quantity: entryDetails.avg_size * stop_ratio,
58992
+ price: entryDetails.stop
58993
+ },
58994
+ config: {
58995
+ ...custom_b_config,
58996
+ ...result
58997
+ },
58998
+ kind,
58999
+ current: currentState
59000
+ };
59001
+ }
59002
+ function generatePositionIncreaseTrade({
59003
+ account,
59004
+ zoneAccount,
59005
+ ratio = 0.1,
59006
+ config: config2,
59007
+ global_config,
59008
+ style = "minimum",
59009
+ distribution = "inverse-exponential"
59010
+ }) {
59011
+ const kind = config2.entry > config2.stop ? "long" : "short";
59012
+ const target_max_quantity = kind === "long" ? account.short.quantity : account.long.quantity;
59013
+ const increase_qty = target_max_quantity * ratio;
59014
+ const entry = zoneAccount.entry;
59015
+ const stop = zoneAccount.stop;
59016
+ return increaseTradeHelper({
59017
+ config: config2,
59018
+ position: account[kind],
59019
+ global_config,
59020
+ entry,
59021
+ stop,
59022
+ style,
59023
+ increase_qty,
59024
+ distribution
59025
+ });
59026
+ }
59027
+ var compoundAPI = {
59028
+ buildWithOptimumReward,
59029
+ constructAppConfig: constructAppConfig2,
59030
+ generateOppositeOptimum,
59031
+ increaseTradeHelper,
59032
+ generatePositionIncreaseTrade
59033
+ };
58627
59034
  // src/types/index.ts
58628
59035
  class BaseExchange {
58629
59036
  client;