@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.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,
@@ -58560,7 +58556,418 @@ class Strategy {
58560
58556
  }
58561
58557
  }
58562
58558
  // src/helpers/compound.ts
58563
- var name2 = "";
58559
+ function buildTrades(payload) {
58560
+ const { appConfig, settings, kind } = payload;
58561
+ const kelly_config = settings.kelly;
58562
+ const current_app_config = { ...appConfig[kind] };
58563
+ const entryNum = parseFloat(settings.entry);
58564
+ const stopNum = parseFloat(settings.stop);
58565
+ current_app_config.entry = entryNum;
58566
+ current_app_config.stop = stopNum;
58567
+ current_app_config.risk_per_trade = parseFloat(settings.risk);
58568
+ current_app_config.risk_reward = parseFloat(settings.risk_reward);
58569
+ current_app_config.kind = kind;
58570
+ current_app_config.kelly = kelly_config;
58571
+ const options = {
58572
+ take_profit: null,
58573
+ entry: current_app_config.entry,
58574
+ stop: current_app_config.stop,
58575
+ raw_instance: null,
58576
+ risk: current_app_config.risk_per_trade,
58577
+ no_of_trades: undefined,
58578
+ risk_reward: current_app_config.risk_reward,
58579
+ kind: current_app_config.kind,
58580
+ increase: true,
58581
+ gap: current_app_config.gap,
58582
+ rr: current_app_config.rr,
58583
+ price_places: current_app_config.price_places,
58584
+ decimal_places: current_app_config.decimal_places,
58585
+ use_kelly: kelly_config?.use_kelly,
58586
+ kelly_confidence_factor: kelly_config?.kelly_confidence_factor,
58587
+ kelly_minimum_risk: kelly_config?.kelly_minimum_risk,
58588
+ kelly_prediction_model: kelly_config?.kelly_prediction_model,
58589
+ kelly_func: kelly_config?.kelly_func,
58590
+ distribution: settings.distribution
58591
+ };
58592
+ if (kind === "long" && entryNum <= stopNum) {
58593
+ return [];
58594
+ }
58595
+ if (kind === "short" && entryNum >= stopNum) {
58596
+ return [];
58597
+ }
58598
+ try {
58599
+ const generatedTrades = sortedBuildConfig(current_app_config, options);
58600
+ return generatedTrades ?? [];
58601
+ } catch (error) {
58602
+ console.error("Error generating orders:", error);
58603
+ return [];
58604
+ }
58605
+ }
58606
+ function generateSummary({
58607
+ trades,
58608
+ fee_percent = 0.05,
58609
+ anchor
58610
+ }) {
58611
+ const avg_entry = trades[0].avg_entry;
58612
+ const avg_size = trades[0].avg_size;
58613
+ const expected_fee = avg_entry * avg_size * fee_percent / 100;
58614
+ return {
58615
+ first_entry: trades.at(-1).entry,
58616
+ last_entry: trades[0].entry,
58617
+ quantity: avg_size,
58618
+ entry: avg_entry,
58619
+ loss: trades[0].neg_pnl,
58620
+ number_of_trades: trades.length,
58621
+ fee: to_f(expected_fee, "%.2f"),
58622
+ anchor_pnl: anchor?.target_pnl
58623
+ };
58624
+ }
58625
+ function helperFuncToBuildTrades({
58626
+ custom_b_config,
58627
+ symbol_config,
58628
+ app_config_kind,
58629
+ appConfig,
58630
+ force_exact_risk = true
58631
+ }) {
58632
+ const risk = custom_b_config.risk * (custom_b_config.risk_factor || 1);
58633
+ let result = getRiskReward({
58634
+ entry: custom_b_config.entry,
58635
+ stop: custom_b_config.stop,
58636
+ risk,
58637
+ global_config: symbol_config,
58638
+ force_exact_risk,
58639
+ target_loss: custom_b_config.risk * (custom_b_config.risk_factor || 1),
58640
+ distribution: custom_b_config.distribution
58641
+ });
58642
+ if (!force_exact_risk) {
58643
+ result = {
58644
+ risk_reward: result,
58645
+ risk
58646
+ };
58647
+ }
58648
+ const trades = result.risk_reward ? buildTrades({
58649
+ appConfig: { [app_config_kind]: appConfig },
58650
+ kind: app_config_kind,
58651
+ settings: {
58652
+ entry: custom_b_config.entry,
58653
+ stop: custom_b_config.stop,
58654
+ risk: result.risk || custom_b_config.risk,
58655
+ risk_reward: result.risk_reward,
58656
+ distribution: custom_b_config.distribution
58657
+ }
58658
+ }) : [];
58659
+ const summary = trades.length > 0 ? generateSummary({ trades }) : {};
58660
+ return { trades, result, summary };
58661
+ }
58662
+ function constructAppConfig2({
58663
+ config: config2,
58664
+ global_config
58665
+ }) {
58666
+ const options = {
58667
+ entry: config2?.entry,
58668
+ stop: config2?.stop,
58669
+ risk_reward: config2?.risk_reward,
58670
+ risk: config2?.risk,
58671
+ symbol: config2.symbol
58672
+ };
58673
+ const { entries: _entries, ...appConfig } = buildAppConfig(global_config, options);
58674
+ return appConfig;
58675
+ }
58676
+ function buildWithOptimumReward({
58677
+ config: config2,
58678
+ settings,
58679
+ global_config
58680
+ }) {
58681
+ const kind = config2.entry > config2.stop ? "long" : "short";
58682
+ let stop = settings.stop;
58683
+ let entry = settings.entry;
58684
+ const risk = settings.risk;
58685
+ const stop_ratio = settings.stop_ratio || 1;
58686
+ const distribution = settings.distribution || config2?.distribution;
58687
+ const custom_b_config = {
58688
+ entry,
58689
+ stop,
58690
+ risk,
58691
+ distribution
58692
+ };
58693
+ const appConfig = constructAppConfig2({
58694
+ config: config2,
58695
+ global_config
58696
+ });
58697
+ const { trades, summary, result } = helperFuncToBuildTrades({
58698
+ custom_b_config,
58699
+ app_config_kind: kind,
58700
+ appConfig,
58701
+ symbol_config: global_config
58702
+ });
58703
+ const adjusted_size = summary.quantity;
58704
+ const symbol_config = global_config;
58705
+ const entryDetails = {
58706
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
58707
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
58708
+ risk: to_f(result.risk, "%.2f"),
58709
+ risk_reward: result.risk_reward,
58710
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
58711
+ avg_size: to_f(adjusted_size, symbol_config.decimal_places),
58712
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
58713
+ pnl: to_f(custom_b_config.risk, "%.2f"),
58714
+ fee: to_f(summary.fee, "%.2f"),
58715
+ loss: to_f(summary.loss, "%.2f"),
58716
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
58717
+ margin: to_f(summary.entry * adjusted_size / symbol_config.leverage, "%.2f")
58718
+ };
58719
+ return {
58720
+ trades,
58721
+ summary: entryDetails,
58722
+ config: {
58723
+ ...custom_b_config,
58724
+ ...result,
58725
+ stop_ratio
58726
+ },
58727
+ stop_order: {
58728
+ quantity: entryDetails.avg_size * stop_ratio,
58729
+ price: entryDetails.stop
58730
+ },
58731
+ kind
58732
+ };
58733
+ }
58734
+ function generateOppositeOptimum({
58735
+ config: config2,
58736
+ global_config,
58737
+ settings,
58738
+ ratio = 1,
58739
+ distribution,
58740
+ risk_factor = 1
58741
+ }) {
58742
+ const configKind = config2.entry > config2.stop ? "long" : "short";
58743
+ if (configKind === "long" && config2.entry > config2.stop) {
58744
+ if (settings.stop <= settings.entry) {
58745
+ throw new Error("Invalid input: For long config positions, opposite settings must have stop > entry");
58746
+ }
58747
+ } else if (configKind === "short" && config2.entry < config2.stop) {
58748
+ if (settings.stop >= settings.entry) {
58749
+ throw new Error("Invalid input: For short config positions, opposite settings must have stop < entry");
58750
+ }
58751
+ }
58752
+ const kind = config2.entry > config2.stop ? "long" : "short";
58753
+ const app_config_kind = kind === "long" ? "short" : "long";
58754
+ let risk = settings.risk;
58755
+ const custom_b_config = {
58756
+ entry: settings.entry,
58757
+ stop: settings.stop,
58758
+ risk: risk * ratio,
58759
+ distribution: distribution || "inverse-exponential",
58760
+ risk_factor
58761
+ };
58762
+ const appConfig = constructAppConfig2({
58763
+ config: {
58764
+ ...config2,
58765
+ ...custom_b_config
58766
+ },
58767
+ global_config
58768
+ });
58769
+ const { result, trades, summary } = helperFuncToBuildTrades({
58770
+ custom_b_config,
58771
+ symbol_config: global_config,
58772
+ app_config_kind,
58773
+ appConfig
58774
+ });
58775
+ if (Object.keys(summary).length === 0) {
58776
+ return {
58777
+ trades,
58778
+ summary,
58779
+ config: custom_b_config,
58780
+ kind: app_config_kind
58781
+ };
58782
+ }
58783
+ const symbol_config = global_config;
58784
+ const entryDetails = {
58785
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
58786
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
58787
+ risk: to_f(result.risk, "%.2f"),
58788
+ risk_reward: result.risk_reward,
58789
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
58790
+ avg_size: to_f(summary.quantity, symbol_config.decimal_places),
58791
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
58792
+ pnl: to_f(custom_b_config.risk, "%.2f"),
58793
+ fee: to_f(summary.fee, "%.2f"),
58794
+ loss: to_f(summary.loss, "%.2f"),
58795
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
58796
+ defaultEntry: settings.entry ? to_f(settings.entry, symbol_config.price_places) : null
58797
+ };
58798
+ return {
58799
+ trades,
58800
+ summary: entryDetails,
58801
+ config: {
58802
+ ...custom_b_config,
58803
+ ...result
58804
+ },
58805
+ kind: app_config_kind
58806
+ };
58807
+ }
58808
+ function defaultTradeFromCurrentState({
58809
+ config: config2,
58810
+ global_config
58811
+ }) {
58812
+ const kind = config2.entry > config2.stop ? "long" : "short";
58813
+ const settings = {
58814
+ entry: config2?.entry,
58815
+ stop: config2?.stop,
58816
+ risk: config2?.risk,
58817
+ distribution: config2?.distribution,
58818
+ risk_reward: config2?.risk_reward
58819
+ };
58820
+ const appConfig = constructAppConfig2({
58821
+ config: config2,
58822
+ global_config
58823
+ });
58824
+ const trades = buildTrades({
58825
+ appConfig: { [kind]: appConfig },
58826
+ kind,
58827
+ settings
58828
+ });
58829
+ return {
58830
+ trades,
58831
+ summary: generateSummary({
58832
+ trades,
58833
+ fee_percent: global_config.fee_percent
58834
+ })
58835
+ };
58836
+ }
58837
+ function increaseTradeHelper({
58838
+ increase_qty,
58839
+ stop,
58840
+ config: config2,
58841
+ global_config,
58842
+ style,
58843
+ entry,
58844
+ position: position2,
58845
+ stop_ratio = 1,
58846
+ distribution: default_distribution
58847
+ }) {
58848
+ const symbol_config = global_config;
58849
+ const kind = config2.entry > config2.stop ? "long" : "short";
58850
+ const distribution = default_distribution || config2.distribution || "inverse-exponential";
58851
+ const appConfig = constructAppConfig2({
58852
+ config: config2,
58853
+ global_config
58854
+ });
58855
+ const currentState = defaultTradeFromCurrentState({
58856
+ config: config2,
58857
+ global_config
58858
+ });
58859
+ const { optimal_risk, neg_pnl } = getOptimumStopAndRisk(appConfig, {
58860
+ max_size: increase_qty,
58861
+ target_stop: stop,
58862
+ distribution
58863
+ });
58864
+ if (neg_pnl === 0) {
58865
+ return {
58866
+ trades: [],
58867
+ summary: {},
58868
+ config: {},
58869
+ kind,
58870
+ current: currentState
58871
+ };
58872
+ }
58873
+ const custom_b_config = {
58874
+ entry,
58875
+ stop,
58876
+ risk: style === "minimum" ? Math.abs(neg_pnl) : optimal_risk,
58877
+ distribution
58878
+ };
58879
+ const { result, trades, summary } = helperFuncToBuildTrades({
58880
+ custom_b_config,
58881
+ symbol_config,
58882
+ appConfig,
58883
+ app_config_kind: kind
58884
+ });
58885
+ if (Object.keys(summary).length === 0) {
58886
+ return {
58887
+ trades,
58888
+ summary,
58889
+ config: {
58890
+ ...custom_b_config,
58891
+ ...result
58892
+ },
58893
+ kind,
58894
+ current: currentState
58895
+ };
58896
+ }
58897
+ const new_avg_values = determine_average_entry_and_size([
58898
+ {
58899
+ price: position2.entry,
58900
+ quantity: position2.quantity
58901
+ },
58902
+ {
58903
+ price: summary?.entry,
58904
+ quantity: summary?.quantity
58905
+ }
58906
+ ], symbol_config.decimal_places, symbol_config.price_places);
58907
+ summary.entry = new_avg_values.entry;
58908
+ summary.quantity = new_avg_values.quantity;
58909
+ const loss = Math.abs(summary.entry - custom_b_config.stop) * summary.quantity;
58910
+ const entryDetails = {
58911
+ entry: to_f(custom_b_config.entry, symbol_config.price_places),
58912
+ stop: to_f(custom_b_config.stop, symbol_config.price_places),
58913
+ risk: to_f(result.risk, symbol_config.price_places),
58914
+ risk_reward: result.risk_reward,
58915
+ avg_entry: to_f(summary.entry, symbol_config.price_places),
58916
+ avg_size: to_f(summary.quantity, symbol_config.decimal_places),
58917
+ first_entry: to_f(summary.first_entry, symbol_config.price_places),
58918
+ pnl: to_f(custom_b_config.risk, "%.2f"),
58919
+ fee: to_f(summary.fee, "%.2f"),
58920
+ loss: to_f(loss, "%.2f"),
58921
+ last_entry: to_f(summary.last_entry, symbol_config.price_places),
58922
+ margin: to_f(summary.entry * summary.quantity / global_config.leverage, "%.2f")
58923
+ };
58924
+ return {
58925
+ trades,
58926
+ summary: entryDetails,
58927
+ stop_order: {
58928
+ quantity: entryDetails.avg_size * stop_ratio,
58929
+ price: entryDetails.stop
58930
+ },
58931
+ config: {
58932
+ ...custom_b_config,
58933
+ ...result
58934
+ },
58935
+ kind,
58936
+ current: currentState
58937
+ };
58938
+ }
58939
+ function generatePositionIncreaseTrade({
58940
+ account,
58941
+ zoneAccount,
58942
+ ratio = 0.1,
58943
+ config: config2,
58944
+ global_config,
58945
+ style = "minimum",
58946
+ distribution = "inverse-exponential"
58947
+ }) {
58948
+ const kind = config2.entry > config2.stop ? "long" : "short";
58949
+ const target_max_quantity = kind === "long" ? account.short.quantity : account.long.quantity;
58950
+ const increase_qty = target_max_quantity * ratio;
58951
+ const entry = zoneAccount.entry;
58952
+ const stop = zoneAccount.stop;
58953
+ return increaseTradeHelper({
58954
+ config: config2,
58955
+ position: account[kind],
58956
+ global_config,
58957
+ entry,
58958
+ stop,
58959
+ style,
58960
+ increase_qty,
58961
+ distribution
58962
+ });
58963
+ }
58964
+ var compoundAPI = {
58965
+ buildWithOptimumReward,
58966
+ constructAppConfig: constructAppConfig2,
58967
+ generateOppositeOptimum,
58968
+ increaseTradeHelper,
58969
+ generatePositionIncreaseTrade
58970
+ };
58564
58971
  // src/types/index.ts
58565
58972
  class BaseExchange {
58566
58973
  client;
@@ -64761,7 +65168,6 @@ async function initialize(payload) {
64761
65168
  }
64762
65169
  export {
64763
65170
  sortedBuildConfig,
64764
- name2 as name,
64765
65171
  initialize,
64766
65172
  initApp,
64767
65173
  get_app_config_and_max_size,
@@ -64787,6 +65193,7 @@ export {
64787
65193
  constructAppConfig,
64788
65194
  computeRiskReward,
64789
65195
  computeProfitDetail,
65196
+ compoundAPI,
64790
65197
  calculateFactorFromTakeProfit,
64791
65198
  calculateFactorFromSellQuantity,
64792
65199
  buildConfig,