@gbozee/ultimate 0.0.2-204 → 0.0.2-207

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
@@ -55873,6 +55873,7 @@ class Signal {
55873
55873
  budget;
55874
55874
  percent_change = 0.02;
55875
55875
  price_places = "%.5f";
55876
+ distribution_params = {};
55876
55877
  decimal_places = "%.0f";
55877
55878
  zone_risk = 1;
55878
55879
  fee = 0.08 / 100;
@@ -55928,11 +55929,13 @@ class Signal {
55928
55929
  kelly_minimum_risk = 0.2,
55929
55930
  kelly_func = "theoretical",
55930
55931
  full_distribution,
55931
- max_quantity = 0.03
55932
+ max_quantity = 0.03,
55933
+ distribution_params = {}
55932
55934
  }) {
55933
55935
  if (full_distribution) {
55934
55936
  this.distribution = full_distribution;
55935
55937
  }
55938
+ this.distribution_params = distribution_params;
55936
55939
  this.symbol = symbol;
55937
55940
  this.minimum_size = minimum_size;
55938
55941
  this.first_order_size = first_order_size;
@@ -55970,7 +55973,8 @@ class Signal {
55970
55973
  risk,
55971
55974
  no_of_trades = 1,
55972
55975
  take_profit,
55973
- distribution
55976
+ distribution,
55977
+ distribution_params = {}
55974
55978
  }) {
55975
55979
  let _stop_loss = stop_loss;
55976
55980
  if (!_stop_loss && stop_percent) {
@@ -55994,7 +55998,8 @@ class Signal {
55994
55998
  full_distribution: distribution ? {
55995
55999
  ...this.distribution,
55996
56000
  [kind]: distribution
55997
- } : undefined
56001
+ } : undefined,
56002
+ distribution_params
55998
56003
  };
55999
56004
  const instance = new Signal(derivedConfig);
56000
56005
  if (kind === "short") {}
@@ -56222,7 +56227,8 @@ class Signal {
56222
56227
  kind: _kind,
56223
56228
  distribution,
56224
56229
  risk_reward: this.risk_reward,
56225
- price_places: this.price_places
56230
+ price_places: this.price_places,
56231
+ distribution_params: this.distribution_params
56226
56232
  });
56227
56233
  return entries.sort((a, b) => a - b);
56228
56234
  }
@@ -56892,7 +56898,8 @@ function buildConfig(app_config, {
56892
56898
  kelly_prediction_model = "exponential",
56893
56899
  kelly_func = "theoretical",
56894
56900
  min_avg_size = 0,
56895
- distribution
56901
+ distribution,
56902
+ distribution_params
56896
56903
  }) {
56897
56904
  let fee = app_config.fee / 100;
56898
56905
  let working_risk = risk || app_config.risk_per_trade;
@@ -56923,7 +56930,8 @@ function buildConfig(app_config, {
56923
56930
  kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model,
56924
56931
  kelly_func: kelly_func || app_config.kelly?.kelly_func,
56925
56932
  symbol: app_config.symbol,
56926
- max_quantity: app_config.max_quantity
56933
+ max_quantity: app_config.max_quantity,
56934
+ distribution_params: distribution_params || app_config.distribution_params
56927
56935
  };
56928
56936
  const instance = new Signal(config2);
56929
56937
  if (raw_instance) {
@@ -56940,7 +56948,8 @@ function buildConfig(app_config, {
56940
56948
  risk: working_risk,
56941
56949
  kind: kind || app_config.kind,
56942
56950
  no_of_trades: trade_no,
56943
- distribution
56951
+ distribution,
56952
+ distribution_params
56944
56953
  }) || [] : [];
56945
56954
  const new_trades = computeTotalAverageForEachTrade(result, config2);
56946
56955
  let filtered = new_trades.filter((o) => o.avg_size > min_avg_size);
@@ -57010,7 +57019,8 @@ function get_app_config_and_max_size(config2, payload) {
57010
57019
  kelly_minimum_risk: payload.kelly_minimum_risk,
57011
57020
  kelly_prediction_model: payload.kelly_prediction_model,
57012
57021
  kelly_func: payload.kelly_func,
57013
- distribution: payload.distribution
57022
+ distribution: payload.distribution,
57023
+ distribution_params: payload.distribution_params
57014
57024
  });
57015
57025
  const max_size = initialResult[0]?.avg_size;
57016
57026
  const last_value = initialResult[0];
@@ -57049,7 +57059,8 @@ function buildAppConfig(config2, payload) {
57049
57059
  kelly_minimum_risk: payload.kelly_minimum_risk,
57050
57060
  kelly_prediction_model: payload.kelly_prediction_model,
57051
57061
  kelly_func: payload.kelly_func,
57052
- distribution: payload.distribution
57062
+ distribution: payload.distribution,
57063
+ distribution_params: payload.distribution_params
57053
57064
  });
57054
57065
  app_config.max_size = max_size;
57055
57066
  app_config.entry = payload.entry || app_config.entry;
@@ -57063,10 +57074,12 @@ function buildAppConfig(config2, payload) {
57063
57074
  kelly_prediction_model: payload.kelly_prediction_model,
57064
57075
  kelly_func: payload.kelly_func
57065
57076
  };
57077
+ app_config.distribution = payload.distribution;
57078
+ app_config.distribution_params = payload.distribution_params;
57066
57079
  return app_config;
57067
57080
  }
57068
57081
  function getOptimumStopAndRisk(app_config, params) {
57069
- const { max_size, target_stop, distribution } = params;
57082
+ const { max_size, target_stop, distribution, distribution_params: _distribution_params } = params;
57070
57083
  const isLong = app_config.kind === "long";
57071
57084
  const stopRange = Math.abs(app_config.entry - target_stop) * 0.5;
57072
57085
  let low_stop = isLong ? target_stop - stopRange : Math.max(target_stop - stopRange, app_config.entry);
@@ -57090,7 +57103,8 @@ function getOptimumStopAndRisk(app_config, params) {
57090
57103
  gap: app_config.gap,
57091
57104
  price_places: app_config.price_places,
57092
57105
  decimal_places: app_config.decimal_places,
57093
- distribution
57106
+ distribution,
57107
+ distribution_params: _distribution_params
57094
57108
  });
57095
57109
  if (result.length === 0) {
57096
57110
  if (isLong) {
@@ -57145,7 +57159,8 @@ function getOptimumStopAndRisk(app_config, params) {
57145
57159
  gap: app_config.gap,
57146
57160
  price_places: app_config.price_places,
57147
57161
  decimal_places: app_config.decimal_places,
57148
- distribution
57162
+ distribution,
57163
+ distribution_params: _distribution_params
57149
57164
  });
57150
57165
  if (result.length === 0) {
57151
57166
  high_risk = mid_risk;
@@ -57191,7 +57206,8 @@ function getOptimumStopAndRisk(app_config, params) {
57191
57206
  gap: app_config.gap,
57192
57207
  price_places: app_config.price_places,
57193
57208
  decimal_places: app_config.decimal_places,
57194
- distribution
57209
+ distribution,
57210
+ distribution_params: _distribution_params
57195
57211
  });
57196
57212
  if (result.length === 0)
57197
57213
  continue;
@@ -57412,7 +57428,8 @@ function determineOptimumReward(payload) {
57412
57428
  kind: app_config.kind,
57413
57429
  gap: app_config.gap,
57414
57430
  decimal_places: app_config.decimal_places,
57415
- distribution
57431
+ distribution,
57432
+ distribution_params: payload.distribution_params
57416
57433
  });
57417
57434
  let total = 0;
57418
57435
  let max = -Infinity;
@@ -57601,6 +57618,7 @@ function computeRiskReward(payload) {
57601
57618
  app_config,
57602
57619
  target_loss,
57603
57620
  distribution,
57621
+ distribution_params: payload.distribution_params,
57604
57622
  high_range,
57605
57623
  max_size
57606
57624
  });
@@ -57625,7 +57643,8 @@ function getRiskReward(payload) {
57625
57643
  risk_reward: 30,
57626
57644
  risk,
57627
57645
  symbol: global_config.symbol,
57628
- distribution
57646
+ distribution,
57647
+ distribution_params: payload.distribution_params
57629
57648
  });
57630
57649
  const risk_reward = computeRiskReward({
57631
57650
  app_config,
@@ -57635,6 +57654,7 @@ function getRiskReward(payload) {
57635
57654
  high_range,
57636
57655
  target_loss,
57637
57656
  distribution,
57657
+ distribution_params: payload.distribution_params,
57638
57658
  max_size
57639
57659
  });
57640
57660
  if (force_exact_risk) {
@@ -57644,7 +57664,8 @@ function getRiskReward(payload) {
57644
57664
  risk_reward,
57645
57665
  risk,
57646
57666
  symbol: global_config.symbol,
57647
- distribution
57667
+ distribution,
57668
+ distribution_params: payload.distribution_params
57648
57669
  }, {
57649
57670
  highest_risk: risk * risk_factor
57650
57671
  }).optimal_risk;
@@ -58065,7 +58086,8 @@ function generateOppositeTradeConfig(payload) {
58065
58086
  }
58066
58087
  }
58067
58088
  },
58068
- global_config
58089
+ global_config,
58090
+ distribution_config: {}
58069
58091
  });
58070
58092
  const risk_reward = computeRiskReward({
58071
58093
  app_config,
@@ -58082,7 +58104,7 @@ function generateOppositeTradeConfig(payload) {
58082
58104
  };
58083
58105
  }
58084
58106
  function constructAppConfig(payload) {
58085
- const { account, global_config, kelly_config } = payload;
58107
+ const { account, global_config, kelly_config, distribution_config } = payload;
58086
58108
  const config2 = account.expand?.b_config;
58087
58109
  if (!config2) {
58088
58110
  return null;
@@ -58097,7 +58119,9 @@ function constructAppConfig(payload) {
58097
58119
  use_kelly: kelly_config?.use_kelly ?? kelly?.use_kelly,
58098
58120
  kelly_confidence_factor: kelly_config?.kelly_confidence_factor ?? kelly?.kelly_confidence_factor,
58099
58121
  kelly_minimum_risk: kelly_config?.kelly_minimum_risk ?? kelly?.kelly_minimum_risk,
58100
- kelly_prediction_model: kelly_config?.kelly_prediction_model ?? kelly?.kelly_prediction_model
58122
+ kelly_prediction_model: kelly_config?.kelly_prediction_model ?? kelly?.kelly_prediction_model,
58123
+ distribution: distribution_config?.distribution ?? config2?.distribution,
58124
+ distribution_params: distribution_config?.distribution_params ?? config2?.distribution_params
58101
58125
  };
58102
58126
  const { entries: _entries, ...appConfig } = buildAppConfig(global_config, options);
58103
58127
  return appConfig;
@@ -58107,7 +58131,8 @@ function generateDangerousConfig(payload) {
58107
58131
  const app_config = constructAppConfig({
58108
58132
  account,
58109
58133
  global_config,
58110
- kelly_config: {}
58134
+ kelly_config: {},
58135
+ distribution_config: {}
58111
58136
  });
58112
58137
  const { optimal_risk, optimal_stop } = getOptimumStopAndRisk(app_config, {
58113
58138
  max_size: config2.quantity,
@@ -58630,6 +58655,7 @@ class Strategy {
58630
58655
  function buildTrades(payload) {
58631
58656
  const { appConfig, settings, kind } = payload;
58632
58657
  const kelly_config = settings.kelly;
58658
+ const distribution_params = settings.distribution_params;
58633
58659
  const current_app_config = { ...appConfig[kind] };
58634
58660
  const entryNum = parseFloat(settings.entry);
58635
58661
  const stopNum = parseFloat(settings.stop);
@@ -58639,6 +58665,7 @@ function buildTrades(payload) {
58639
58665
  current_app_config.risk_reward = parseFloat(settings.risk_reward);
58640
58666
  current_app_config.kind = kind;
58641
58667
  current_app_config.kelly = kelly_config;
58668
+ current_app_config.distribution_params = distribution_params;
58642
58669
  const options = {
58643
58670
  take_profit: null,
58644
58671
  entry: current_app_config.entry,
@@ -58756,11 +58783,13 @@ function buildWithOptimumReward({
58756
58783
  const risk = settings.risk;
58757
58784
  const stop_ratio = settings.stop_ratio || 1;
58758
58785
  const distribution = settings.distribution || config2?.distribution;
58786
+ const distribution_params = settings.distribution_params || config2?.distribution_params;
58759
58787
  const custom_b_config = {
58760
58788
  entry,
58761
58789
  stop,
58762
58790
  risk,
58763
- distribution
58791
+ distribution,
58792
+ distribution_params
58764
58793
  };
58765
58794
  const appConfig = constructAppConfig2({
58766
58795
  config: config2,
@@ -58810,6 +58839,7 @@ function generateOppositeOptimum({
58810
58839
  settings,
58811
58840
  ratio = 1,
58812
58841
  distribution,
58842
+ distribution_params,
58813
58843
  risk_factor = 1
58814
58844
  }) {
58815
58845
  const configKind = config2.entry > config2.stop ? "long" : "short";
@@ -58830,6 +58860,7 @@ function generateOppositeOptimum({
58830
58860
  stop: settings.stop,
58831
58861
  risk: risk * ratio,
58832
58862
  distribution: distribution || "inverse-exponential",
58863
+ distribution_params: distribution_params || config2?.distribution_params,
58833
58864
  risk_factor
58834
58865
  };
58835
58866
  const appConfig = constructAppConfig2({
@@ -58916,11 +58947,13 @@ function increaseTradeHelper({
58916
58947
  entry,
58917
58948
  position: position2,
58918
58949
  stop_ratio = 1,
58919
- distribution: default_distribution
58950
+ distribution: default_distribution,
58951
+ distribution_params: default_distribution_params
58920
58952
  }) {
58921
58953
  const symbol_config = global_config;
58922
58954
  const kind = config2.entry > config2.stop ? "long" : "short";
58923
58955
  const distribution = default_distribution || config2.distribution || "inverse-exponential";
58956
+ const distribution_params = default_distribution_params || config2.distribution_params;
58924
58957
  const appConfig = constructAppConfig2({
58925
58958
  config: config2,
58926
58959
  global_config
@@ -58947,7 +58980,8 @@ function increaseTradeHelper({
58947
58980
  entry,
58948
58981
  stop,
58949
58982
  risk: style === "minimum" ? Math.abs(neg_pnl) : optimal_risk,
58950
- distribution
58983
+ distribution,
58984
+ distribution_params
58951
58985
  };
58952
58986
  const { result, trades, summary } = helperFuncToBuildTrades({
58953
58987
  custom_b_config,
@@ -59016,7 +59050,8 @@ function generatePositionIncreaseTrade({
59016
59050
  config: config2,
59017
59051
  global_config,
59018
59052
  style = "minimum",
59019
- distribution = "inverse-exponential"
59053
+ distribution = "inverse-exponential",
59054
+ distribution_params
59020
59055
  }) {
59021
59056
  const kind = config2.entry > config2.stop ? "long" : "short";
59022
59057
  const target_max_quantity = kind === "long" ? account.short.quantity : account.long.quantity;
@@ -59031,10 +59066,46 @@ function generatePositionIncreaseTrade({
59031
59066
  stop,
59032
59067
  style,
59033
59068
  increase_qty,
59034
- distribution
59069
+ distribution,
59070
+ distribution_params
59035
59071
  });
59036
59072
  }
59073
+ function determineHedgeTradeToPlace({
59074
+ position: position2,
59075
+ config: config2,
59076
+ global_config,
59077
+ profit_risk = 200,
59078
+ allowable_loss = 1000
59079
+ }) {
59080
+ const diff = profit_risk / position2.quantity;
59081
+ const kind = position2.kind === "long" ? "short" : "long";
59082
+ const tp_price = position2.kind === "long" ? diff + position2.entry : position2.entry - diff;
59083
+ const loss_diff = allowable_loss / position2.quantity;
59084
+ const loss_price = position2.kind === "long" ? position2.entry - loss_diff : position2.entry + loss_diff;
59085
+ const entry = kind === "short" ? loss_price : tp_price;
59086
+ const stop = kind === "short" ? tp_price : loss_price;
59087
+ const result = buildWithOptimumReward({
59088
+ config: {
59089
+ ...config2,
59090
+ entry,
59091
+ stop
59092
+ },
59093
+ global_config,
59094
+ force_exact: true,
59095
+ settings: {
59096
+ entry,
59097
+ stop,
59098
+ risk: profit_risk,
59099
+ distribution: config2.distribution
59100
+ }
59101
+ });
59102
+ return {
59103
+ opposite: result,
59104
+ take_profit: to_f(tp_price, global_config.price_places)
59105
+ };
59106
+ }
59037
59107
  var compoundAPI = {
59108
+ determineHedgeTradeToPlace,
59038
59109
  buildWithOptimumReward,
59039
59110
  constructAppConfig: constructAppConfig2,
59040
59111
  generateOppositeOptimum,
@@ -59047,8 +59118,10 @@ class BaseExchange {
59047
59118
  name;
59048
59119
  getCredentials;
59049
59120
  proxyAgent;
59121
+ remoteActionBaseUrl;
59050
59122
  constructor(client) {
59051
59123
  this.client = client;
59124
+ this.remoteActionBaseUrl = "https://app-dev.beeola.me";
59052
59125
  }
59053
59126
  async rawCreateLimitPurchaseOrders(payload) {
59054
59127
  const { symbol, orders, price_places, decimal_places } = payload;
@@ -59382,6 +59455,51 @@ class BaseExchange {
59382
59455
  setAccountDetails(payload) {
59383
59456
  this.getCredentials = payload.getCredentials;
59384
59457
  this.proxyAgent = payload.proxyAgent;
59458
+ if (payload.remoteActionBaseUrl) {
59459
+ this.remoteActionBaseUrl = payload.remoteActionBaseUrl;
59460
+ }
59461
+ }
59462
+ async getSymbolInformation(payload) {
59463
+ const { symbol, variant = "full" } = payload;
59464
+ if (!this.remoteActionBaseUrl) {
59465
+ throw new Error("Remote action base URL is not configured");
59466
+ }
59467
+ const url = `${this.remoteActionBaseUrl}/api/main_account/remote-actions`;
59468
+ const analysisType = variant === "short" ? "analyze_candlesticks_short" : "analyze_candlesticks";
59469
+ const requestPayload = {
59470
+ action: "base_model",
59471
+ symbol,
59472
+ name: "base_model",
59473
+ params: {
59474
+ args: [analysisType],
59475
+ kwargs: { symbol }
59476
+ }
59477
+ };
59478
+ try {
59479
+ const response = await fetch(url, {
59480
+ method: "POST",
59481
+ headers: {
59482
+ "Content-Type": "application/json"
59483
+ },
59484
+ body: JSON.stringify(requestPayload)
59485
+ });
59486
+ if (!response.ok) {
59487
+ throw new Error(`HTTP error! status: ${response.status}`);
59488
+ }
59489
+ const result = await response.json();
59490
+ const data = result.data;
59491
+ return {
59492
+ candlesticks: data.candlesticks || {},
59493
+ resistance: data.resistance || {},
59494
+ support: data.support || {},
59495
+ currentPrice: data.current_price || 0,
59496
+ minimumWeekly: data.minimum_weekly,
59497
+ lowest: data.lowest
59498
+ };
59499
+ } catch (error) {
59500
+ console.error("Error fetching symbol information:", error);
59501
+ throw error;
59502
+ }
59385
59503
  }
59386
59504
  }
59387
59505
 
@@ -62016,6 +62134,7 @@ class ExchangePosition {
62016
62134
  if (condition) {
62017
62135
  let entry = payload.tp ? position2.entry || config2.entry : config2.entry;
62018
62136
  const v = stop ? "place_stop_orders" : risky ? "dangerous_entry_orders" : "place_limit_orders";
62137
+ console.log("distribution_params", config2.distribution_params);
62019
62138
  return await this.placeSharedOrder(v, {
62020
62139
  entry,
62021
62140
  stop: config2.stop,
@@ -62026,6 +62145,7 @@ class ExchangePosition {
62026
62145
  use_current,
62027
62146
  stop_percent: config2.stop_percent || 100,
62028
62147
  distribution: config2.distribution,
62148
+ distribution_params: config2.distribution_params,
62029
62149
  hedge: payload.hedge,
62030
62150
  stop_ratio
62031
62151
  });
@@ -62045,7 +62165,9 @@ class ExchangePosition {
62045
62165
  kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
62046
62166
  kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
62047
62167
  kelly_prediction_model: config2.kelly?.kelly_prediction_model,
62048
- kelly_func: config2.kelly?.kelly_func
62168
+ kelly_func: config2.kelly?.kelly_func,
62169
+ distribution: payload.distribution || config2.distribution,
62170
+ distribution_params: payload.distribution_params || config2.distribution_params
62049
62171
  });
62050
62172
  const { entry_orders, stop_orders, trades } = await this.placeConfigOrders(app_config, {
62051
62173
  risk_reward: payload.risk_reward,
@@ -62062,7 +62184,8 @@ class ExchangePosition {
62062
62184
  kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
62063
62185
  kelly_prediction_model: config2.kelly?.kelly_prediction_model,
62064
62186
  kelly_func: config2.kelly?.kelly_func,
62065
- distribution: config2.distribution
62187
+ distribution: config2.distribution,
62188
+ distribution_params: payload.distribution_params || config2.distribution_params
62066
62189
  }, false);
62067
62190
  if (payload.raw) {
62068
62191
  let actual_orders_to_buy = await this.determineAmountToBuy({
@@ -62187,7 +62310,8 @@ class ExchangePosition {
62187
62310
  kelly_minimum_risk: solution.kelly_minimum_risk,
62188
62311
  kelly_prediction_model: solution.kelly_prediction_model,
62189
62312
  kelly_func: solution.kelly_func,
62190
- distribution: solution.distribution
62313
+ distribution: solution.distribution,
62314
+ distribution_params: solution.distribution_params
62191
62315
  };
62192
62316
  const trades = sortedBuildConfig(app_config, options);
62193
62317
  const entry_orders = {
@@ -62622,7 +62746,9 @@ class ExchangePosition {
62622
62746
  entry,
62623
62747
  stop,
62624
62748
  risk_reward,
62625
- risk
62749
+ risk,
62750
+ distribution: db_config.distribution,
62751
+ distribution_params: db_config.distribution_params
62626
62752
  });
62627
62753
  let config2 = generate_config_params(app_config, {
62628
62754
  entry,
@@ -62638,7 +62764,9 @@ class ExchangePosition {
62638
62764
  risk_reward: config2.risk_reward,
62639
62765
  risk: config2.risk,
62640
62766
  profit: 0,
62641
- update_db: false
62767
+ update_db: false,
62768
+ distribution: db_config.distribution,
62769
+ distribution_params: db_config.distribution_params
62642
62770
  });
62643
62771
  const { trades } = await this.placeConfigOrders(app_config2, {
62644
62772
  risk_reward: config2.risk_reward,
@@ -62736,7 +62864,9 @@ class ExchangePosition {
62736
62864
  entry: config2.entry,
62737
62865
  stop: config2.stop,
62738
62866
  risk_reward: config2.risk_reward,
62739
- risk: risk || config2.risk
62867
+ risk: risk || config2.risk,
62868
+ distribution: config2.distribution,
62869
+ distribution_params: config2.distribution_params
62740
62870
  });
62741
62871
  const { trades } = await this.placeConfigOrders(app_config, {
62742
62872
  risk_reward: config2.risk_reward,
@@ -62792,6 +62922,8 @@ class ExchangePosition {
62792
62922
  kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
62793
62923
  kelly_prediction_model: config2.kelly?.kelly_prediction_model,
62794
62924
  kelly_func: config2.kelly?.kelly_func,
62925
+ distribution: config2.distribution,
62926
+ distribution_params: config2.distribution_params,
62795
62927
  ...override
62796
62928
  });
62797
62929
  return app_config;
@@ -63366,7 +63498,7 @@ class ExchangeAccount {
63366
63498
  kind: "short"
63367
63499
  });
63368
63500
  const long_config = await long_position.getConfig();
63369
- const short_config = await short_position.getConfig();
63501
+ const short_config = short_position.getInstance().expand.b_config;
63370
63502
  const config2 = build_reduce_config({
63371
63503
  account: this.instance,
63372
63504
  symbol: payload.symbol,