@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.
@@ -62559,6 +62559,7 @@ class Signal {
62559
62559
  budget;
62560
62560
  percent_change = 0.02;
62561
62561
  price_places = "%.5f";
62562
+ distribution_params = {};
62562
62563
  decimal_places = "%.0f";
62563
62564
  zone_risk = 1;
62564
62565
  fee = 0.08 / 100;
@@ -62614,11 +62615,13 @@ class Signal {
62614
62615
  kelly_minimum_risk = 0.2,
62615
62616
  kelly_func = "theoretical",
62616
62617
  full_distribution,
62617
- max_quantity = 0.03
62618
+ max_quantity = 0.03,
62619
+ distribution_params = {}
62618
62620
  }) {
62619
62621
  if (full_distribution) {
62620
62622
  this.distribution = full_distribution;
62621
62623
  }
62624
+ this.distribution_params = distribution_params;
62622
62625
  this.symbol = symbol;
62623
62626
  this.minimum_size = minimum_size;
62624
62627
  this.first_order_size = first_order_size;
@@ -62656,7 +62659,8 @@ class Signal {
62656
62659
  risk,
62657
62660
  no_of_trades = 1,
62658
62661
  take_profit,
62659
- distribution
62662
+ distribution,
62663
+ distribution_params = {}
62660
62664
  }) {
62661
62665
  let _stop_loss = stop_loss;
62662
62666
  if (!_stop_loss && stop_percent) {
@@ -62680,7 +62684,8 @@ class Signal {
62680
62684
  full_distribution: distribution ? {
62681
62685
  ...this.distribution,
62682
62686
  [kind]: distribution
62683
- } : undefined
62687
+ } : undefined,
62688
+ distribution_params
62684
62689
  };
62685
62690
  const instance = new Signal(derivedConfig);
62686
62691
  if (kind === "short") {}
@@ -62908,7 +62913,8 @@ class Signal {
62908
62913
  kind: _kind,
62909
62914
  distribution,
62910
62915
  risk_reward: this.risk_reward,
62911
- price_places: this.price_places
62916
+ price_places: this.price_places,
62917
+ distribution_params: this.distribution_params
62912
62918
  });
62913
62919
  return entries.sort((a, b) => a - b);
62914
62920
  }
@@ -63578,7 +63584,8 @@ function buildConfig(app_config, {
63578
63584
  kelly_prediction_model = "exponential",
63579
63585
  kelly_func = "theoretical",
63580
63586
  min_avg_size = 0,
63581
- distribution
63587
+ distribution,
63588
+ distribution_params
63582
63589
  }) {
63583
63590
  let fee = app_config.fee / 100;
63584
63591
  let working_risk = risk || app_config.risk_per_trade;
@@ -63609,7 +63616,8 @@ function buildConfig(app_config, {
63609
63616
  kelly_prediction_model: kelly_prediction_model || app_config.kelly?.kelly_prediction_model,
63610
63617
  kelly_func: kelly_func || app_config.kelly?.kelly_func,
63611
63618
  symbol: app_config.symbol,
63612
- max_quantity: app_config.max_quantity
63619
+ max_quantity: app_config.max_quantity,
63620
+ distribution_params: distribution_params || app_config.distribution_params
63613
63621
  };
63614
63622
  const instance = new Signal(config2);
63615
63623
  if (raw_instance) {
@@ -63626,7 +63634,8 @@ function buildConfig(app_config, {
63626
63634
  risk: working_risk,
63627
63635
  kind: kind || app_config.kind,
63628
63636
  no_of_trades: trade_no,
63629
- distribution
63637
+ distribution,
63638
+ distribution_params
63630
63639
  }) || [] : [];
63631
63640
  const new_trades = computeTotalAverageForEachTrade(result, config2);
63632
63641
  let filtered = new_trades.filter((o) => o.avg_size > min_avg_size);
@@ -63683,7 +63692,8 @@ function get_app_config_and_max_size(config2, payload) {
63683
63692
  kelly_minimum_risk: payload.kelly_minimum_risk,
63684
63693
  kelly_prediction_model: payload.kelly_prediction_model,
63685
63694
  kelly_func: payload.kelly_func,
63686
- distribution: payload.distribution
63695
+ distribution: payload.distribution,
63696
+ distribution_params: payload.distribution_params
63687
63697
  });
63688
63698
  const max_size = initialResult[0]?.avg_size;
63689
63699
  const last_value = initialResult[0];
@@ -63722,7 +63732,8 @@ function buildAppConfig(config2, payload) {
63722
63732
  kelly_minimum_risk: payload.kelly_minimum_risk,
63723
63733
  kelly_prediction_model: payload.kelly_prediction_model,
63724
63734
  kelly_func: payload.kelly_func,
63725
- distribution: payload.distribution
63735
+ distribution: payload.distribution,
63736
+ distribution_params: payload.distribution_params
63726
63737
  });
63727
63738
  app_config.max_size = max_size;
63728
63739
  app_config.entry = payload.entry || app_config.entry;
@@ -63736,10 +63747,12 @@ function buildAppConfig(config2, payload) {
63736
63747
  kelly_prediction_model: payload.kelly_prediction_model,
63737
63748
  kelly_func: payload.kelly_func
63738
63749
  };
63750
+ app_config.distribution = payload.distribution;
63751
+ app_config.distribution_params = payload.distribution_params;
63739
63752
  return app_config;
63740
63753
  }
63741
63754
  function getOptimumStopAndRisk(app_config, params) {
63742
- const { max_size, target_stop, distribution } = params;
63755
+ const { max_size, target_stop, distribution, distribution_params: _distribution_params } = params;
63743
63756
  const isLong = app_config.kind === "long";
63744
63757
  const stopRange = Math.abs(app_config.entry - target_stop) * 0.5;
63745
63758
  let low_stop = isLong ? target_stop - stopRange : Math.max(target_stop - stopRange, app_config.entry);
@@ -63763,7 +63776,8 @@ function getOptimumStopAndRisk(app_config, params) {
63763
63776
  gap: app_config.gap,
63764
63777
  price_places: app_config.price_places,
63765
63778
  decimal_places: app_config.decimal_places,
63766
- distribution
63779
+ distribution,
63780
+ distribution_params: _distribution_params
63767
63781
  });
63768
63782
  if (result.length === 0) {
63769
63783
  if (isLong) {
@@ -63818,7 +63832,8 @@ function getOptimumStopAndRisk(app_config, params) {
63818
63832
  gap: app_config.gap,
63819
63833
  price_places: app_config.price_places,
63820
63834
  decimal_places: app_config.decimal_places,
63821
- distribution
63835
+ distribution,
63836
+ distribution_params: _distribution_params
63822
63837
  });
63823
63838
  if (result.length === 0) {
63824
63839
  high_risk = mid_risk;
@@ -63864,7 +63879,8 @@ function getOptimumStopAndRisk(app_config, params) {
63864
63879
  gap: app_config.gap,
63865
63880
  price_places: app_config.price_places,
63866
63881
  decimal_places: app_config.decimal_places,
63867
- distribution
63882
+ distribution,
63883
+ distribution_params: _distribution_params
63868
63884
  });
63869
63885
  if (result.length === 0)
63870
63886
  continue;
@@ -64085,7 +64101,8 @@ function determineOptimumReward(payload) {
64085
64101
  kind: app_config.kind,
64086
64102
  gap: app_config.gap,
64087
64103
  decimal_places: app_config.decimal_places,
64088
- distribution
64104
+ distribution,
64105
+ distribution_params: payload.distribution_params
64089
64106
  });
64090
64107
  let total = 0;
64091
64108
  let max = -Infinity;
@@ -64274,6 +64291,7 @@ function computeRiskReward(payload) {
64274
64291
  app_config,
64275
64292
  target_loss,
64276
64293
  distribution,
64294
+ distribution_params: payload.distribution_params,
64277
64295
  high_range,
64278
64296
  max_size
64279
64297
  });
@@ -64298,7 +64316,8 @@ function getRiskReward(payload) {
64298
64316
  risk_reward: 30,
64299
64317
  risk,
64300
64318
  symbol: global_config.symbol,
64301
- distribution
64319
+ distribution,
64320
+ distribution_params: payload.distribution_params
64302
64321
  });
64303
64322
  const risk_reward = computeRiskReward({
64304
64323
  app_config,
@@ -64308,6 +64327,7 @@ function getRiskReward(payload) {
64308
64327
  high_range,
64309
64328
  target_loss,
64310
64329
  distribution,
64330
+ distribution_params: payload.distribution_params,
64311
64331
  max_size
64312
64332
  });
64313
64333
  if (force_exact_risk) {
@@ -64317,7 +64337,8 @@ function getRiskReward(payload) {
64317
64337
  risk_reward,
64318
64338
  risk,
64319
64339
  symbol: global_config.symbol,
64320
- distribution
64340
+ distribution,
64341
+ distribution_params: payload.distribution_params
64321
64342
  }, {
64322
64343
  highest_risk: risk * risk_factor
64323
64344
  }).optimal_risk;
@@ -64640,7 +64661,8 @@ function generateOppositeTradeConfig(payload) {
64640
64661
  }
64641
64662
  }
64642
64663
  },
64643
- global_config
64664
+ global_config,
64665
+ distribution_config: {}
64644
64666
  });
64645
64667
  const risk_reward = computeRiskReward({
64646
64668
  app_config,
@@ -64657,7 +64679,7 @@ function generateOppositeTradeConfig(payload) {
64657
64679
  };
64658
64680
  }
64659
64681
  function constructAppConfig(payload) {
64660
- const { account, global_config, kelly_config } = payload;
64682
+ const { account, global_config, kelly_config, distribution_config } = payload;
64661
64683
  const config2 = account.expand?.b_config;
64662
64684
  if (!config2) {
64663
64685
  return null;
@@ -64672,7 +64694,9 @@ function constructAppConfig(payload) {
64672
64694
  use_kelly: kelly_config?.use_kelly ?? kelly?.use_kelly,
64673
64695
  kelly_confidence_factor: kelly_config?.kelly_confidence_factor ?? kelly?.kelly_confidence_factor,
64674
64696
  kelly_minimum_risk: kelly_config?.kelly_minimum_risk ?? kelly?.kelly_minimum_risk,
64675
- kelly_prediction_model: kelly_config?.kelly_prediction_model ?? kelly?.kelly_prediction_model
64697
+ kelly_prediction_model: kelly_config?.kelly_prediction_model ?? kelly?.kelly_prediction_model,
64698
+ distribution: distribution_config?.distribution ?? config2?.distribution,
64699
+ distribution_params: distribution_config?.distribution_params ?? config2?.distribution_params
64676
64700
  };
64677
64701
  const { entries: _entries, ...appConfig } = buildAppConfig(global_config, options);
64678
64702
  return appConfig;
@@ -64682,7 +64706,8 @@ function generateDangerousConfig(payload) {
64682
64706
  const app_config = constructAppConfig({
64683
64707
  account,
64684
64708
  global_config,
64685
- kelly_config: {}
64709
+ kelly_config: {},
64710
+ distribution_config: {}
64686
64711
  });
64687
64712
  const { optimal_risk, optimal_stop } = getOptimumStopAndRisk(app_config, {
64688
64713
  max_size: config2.quantity,
@@ -65205,6 +65230,7 @@ class Strategy {
65205
65230
  function buildTrades(payload) {
65206
65231
  const { appConfig, settings, kind } = payload;
65207
65232
  const kelly_config = settings.kelly;
65233
+ const distribution_params = settings.distribution_params;
65208
65234
  const current_app_config = { ...appConfig[kind] };
65209
65235
  const entryNum = parseFloat(settings.entry);
65210
65236
  const stopNum = parseFloat(settings.stop);
@@ -65214,6 +65240,7 @@ function buildTrades(payload) {
65214
65240
  current_app_config.risk_reward = parseFloat(settings.risk_reward);
65215
65241
  current_app_config.kind = kind;
65216
65242
  current_app_config.kelly = kelly_config;
65243
+ current_app_config.distribution_params = distribution_params;
65217
65244
  const options = {
65218
65245
  take_profit: null,
65219
65246
  entry: current_app_config.entry,
@@ -65331,11 +65358,13 @@ function buildWithOptimumReward({
65331
65358
  const risk = settings.risk;
65332
65359
  const stop_ratio = settings.stop_ratio || 1;
65333
65360
  const distribution = settings.distribution || config2?.distribution;
65361
+ const distribution_params = settings.distribution_params || config2?.distribution_params;
65334
65362
  const custom_b_config = {
65335
65363
  entry,
65336
65364
  stop,
65337
65365
  risk,
65338
- distribution
65366
+ distribution,
65367
+ distribution_params
65339
65368
  };
65340
65369
  const appConfig = constructAppConfig2({
65341
65370
  config: config2,
@@ -65385,6 +65414,7 @@ function generateOppositeOptimum({
65385
65414
  settings,
65386
65415
  ratio = 1,
65387
65416
  distribution,
65417
+ distribution_params,
65388
65418
  risk_factor = 1
65389
65419
  }) {
65390
65420
  const configKind = config2.entry > config2.stop ? "long" : "short";
@@ -65405,6 +65435,7 @@ function generateOppositeOptimum({
65405
65435
  stop: settings.stop,
65406
65436
  risk: risk * ratio,
65407
65437
  distribution: distribution || "inverse-exponential",
65438
+ distribution_params: distribution_params || config2?.distribution_params,
65408
65439
  risk_factor
65409
65440
  };
65410
65441
  const appConfig = constructAppConfig2({
@@ -65491,11 +65522,13 @@ function increaseTradeHelper({
65491
65522
  entry,
65492
65523
  position: position2,
65493
65524
  stop_ratio = 1,
65494
- distribution: default_distribution
65525
+ distribution: default_distribution,
65526
+ distribution_params: default_distribution_params
65495
65527
  }) {
65496
65528
  const symbol_config = global_config;
65497
65529
  const kind = config2.entry > config2.stop ? "long" : "short";
65498
65530
  const distribution = default_distribution || config2.distribution || "inverse-exponential";
65531
+ const distribution_params = default_distribution_params || config2.distribution_params;
65499
65532
  const appConfig = constructAppConfig2({
65500
65533
  config: config2,
65501
65534
  global_config
@@ -65522,7 +65555,8 @@ function increaseTradeHelper({
65522
65555
  entry,
65523
65556
  stop,
65524
65557
  risk: style === "minimum" ? Math.abs(neg_pnl) : optimal_risk,
65525
- distribution
65558
+ distribution,
65559
+ distribution_params
65526
65560
  };
65527
65561
  const { result, trades, summary } = helperFuncToBuildTrades({
65528
65562
  custom_b_config,
@@ -65591,7 +65625,8 @@ function generatePositionIncreaseTrade({
65591
65625
  config: config2,
65592
65626
  global_config,
65593
65627
  style = "minimum",
65594
- distribution = "inverse-exponential"
65628
+ distribution = "inverse-exponential",
65629
+ distribution_params
65595
65630
  }) {
65596
65631
  const kind = config2.entry > config2.stop ? "long" : "short";
65597
65632
  const target_max_quantity = kind === "long" ? account.short.quantity : account.long.quantity;
@@ -65606,10 +65641,46 @@ function generatePositionIncreaseTrade({
65606
65641
  stop,
65607
65642
  style,
65608
65643
  increase_qty,
65609
- distribution
65644
+ distribution,
65645
+ distribution_params
65610
65646
  });
65611
65647
  }
65648
+ function determineHedgeTradeToPlace({
65649
+ position: position2,
65650
+ config: config2,
65651
+ global_config,
65652
+ profit_risk = 200,
65653
+ allowable_loss = 1000
65654
+ }) {
65655
+ const diff = profit_risk / position2.quantity;
65656
+ const kind = position2.kind === "long" ? "short" : "long";
65657
+ const tp_price = position2.kind === "long" ? diff + position2.entry : position2.entry - diff;
65658
+ const loss_diff = allowable_loss / position2.quantity;
65659
+ const loss_price = position2.kind === "long" ? position2.entry - loss_diff : position2.entry + loss_diff;
65660
+ const entry = kind === "short" ? loss_price : tp_price;
65661
+ const stop = kind === "short" ? tp_price : loss_price;
65662
+ const result = buildWithOptimumReward({
65663
+ config: {
65664
+ ...config2,
65665
+ entry,
65666
+ stop
65667
+ },
65668
+ global_config,
65669
+ force_exact: true,
65670
+ settings: {
65671
+ entry,
65672
+ stop,
65673
+ risk: profit_risk,
65674
+ distribution: config2.distribution
65675
+ }
65676
+ });
65677
+ return {
65678
+ opposite: result,
65679
+ take_profit: to_f(tp_price, global_config.price_places)
65680
+ };
65681
+ }
65612
65682
  var compoundAPI = {
65683
+ determineHedgeTradeToPlace,
65613
65684
  buildWithOptimumReward,
65614
65685
  constructAppConfig: constructAppConfig2,
65615
65686
  generateOppositeOptimum,
@@ -65622,8 +65693,10 @@ class BaseExchange {
65622
65693
  name;
65623
65694
  getCredentials;
65624
65695
  proxyAgent;
65696
+ remoteActionBaseUrl;
65625
65697
  constructor(client) {
65626
65698
  this.client = client;
65699
+ this.remoteActionBaseUrl = "https://app-dev.beeola.me";
65627
65700
  }
65628
65701
  async rawCreateLimitPurchaseOrders(payload) {
65629
65702
  const { symbol, orders, price_places, decimal_places } = payload;
@@ -65957,6 +66030,51 @@ class BaseExchange {
65957
66030
  setAccountDetails(payload) {
65958
66031
  this.getCredentials = payload.getCredentials;
65959
66032
  this.proxyAgent = payload.proxyAgent;
66033
+ if (payload.remoteActionBaseUrl) {
66034
+ this.remoteActionBaseUrl = payload.remoteActionBaseUrl;
66035
+ }
66036
+ }
66037
+ async getSymbolInformation(payload) {
66038
+ const { symbol, variant = "full" } = payload;
66039
+ if (!this.remoteActionBaseUrl) {
66040
+ throw new Error("Remote action base URL is not configured");
66041
+ }
66042
+ const url = `${this.remoteActionBaseUrl}/api/main_account/remote-actions`;
66043
+ const analysisType = variant === "short" ? "analyze_candlesticks_short" : "analyze_candlesticks";
66044
+ const requestPayload = {
66045
+ action: "base_model",
66046
+ symbol,
66047
+ name: "base_model",
66048
+ params: {
66049
+ args: [analysisType],
66050
+ kwargs: { symbol }
66051
+ }
66052
+ };
66053
+ try {
66054
+ const response = await fetch(url, {
66055
+ method: "POST",
66056
+ headers: {
66057
+ "Content-Type": "application/json"
66058
+ },
66059
+ body: JSON.stringify(requestPayload)
66060
+ });
66061
+ if (!response.ok) {
66062
+ throw new Error(`HTTP error! status: ${response.status}`);
66063
+ }
66064
+ const result = await response.json();
66065
+ const data = result.data;
66066
+ return {
66067
+ candlesticks: data.candlesticks || {},
66068
+ resistance: data.resistance || {},
66069
+ support: data.support || {},
66070
+ currentPrice: data.current_price || 0,
66071
+ minimumWeekly: data.minimum_weekly,
66072
+ lowest: data.lowest
66073
+ };
66074
+ } catch (error) {
66075
+ console.error("Error fetching symbol information:", error);
66076
+ throw error;
66077
+ }
65960
66078
  }
65961
66079
  }
65962
66080
 
@@ -68591,6 +68709,7 @@ class ExchangePosition {
68591
68709
  if (condition) {
68592
68710
  let entry = payload.tp ? position2.entry || config2.entry : config2.entry;
68593
68711
  const v = stop ? "place_stop_orders" : risky ? "dangerous_entry_orders" : "place_limit_orders";
68712
+ console.log("distribution_params", config2.distribution_params);
68594
68713
  return await this.placeSharedOrder(v, {
68595
68714
  entry,
68596
68715
  stop: config2.stop,
@@ -68601,6 +68720,7 @@ class ExchangePosition {
68601
68720
  use_current,
68602
68721
  stop_percent: config2.stop_percent || 100,
68603
68722
  distribution: config2.distribution,
68723
+ distribution_params: config2.distribution_params,
68604
68724
  hedge: payload.hedge,
68605
68725
  stop_ratio
68606
68726
  });
@@ -68620,7 +68740,9 @@ class ExchangePosition {
68620
68740
  kelly_confidence_factor: config2.kelly?.kelly_confidence_factor,
68621
68741
  kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
68622
68742
  kelly_prediction_model: config2.kelly?.kelly_prediction_model,
68623
- kelly_func: config2.kelly?.kelly_func
68743
+ kelly_func: config2.kelly?.kelly_func,
68744
+ distribution: payload.distribution || config2.distribution,
68745
+ distribution_params: payload.distribution_params || config2.distribution_params
68624
68746
  });
68625
68747
  const { entry_orders, stop_orders, trades } = await this.placeConfigOrders(app_config, {
68626
68748
  risk_reward: payload.risk_reward,
@@ -68637,7 +68759,8 @@ class ExchangePosition {
68637
68759
  kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
68638
68760
  kelly_prediction_model: config2.kelly?.kelly_prediction_model,
68639
68761
  kelly_func: config2.kelly?.kelly_func,
68640
- distribution: config2.distribution
68762
+ distribution: config2.distribution,
68763
+ distribution_params: payload.distribution_params || config2.distribution_params
68641
68764
  }, false);
68642
68765
  if (payload.raw) {
68643
68766
  let actual_orders_to_buy = await this.determineAmountToBuy({
@@ -68762,7 +68885,8 @@ class ExchangePosition {
68762
68885
  kelly_minimum_risk: solution.kelly_minimum_risk,
68763
68886
  kelly_prediction_model: solution.kelly_prediction_model,
68764
68887
  kelly_func: solution.kelly_func,
68765
- distribution: solution.distribution
68888
+ distribution: solution.distribution,
68889
+ distribution_params: solution.distribution_params
68766
68890
  };
68767
68891
  const trades = sortedBuildConfig(app_config, options);
68768
68892
  const entry_orders = {
@@ -69197,7 +69321,9 @@ class ExchangePosition {
69197
69321
  entry,
69198
69322
  stop,
69199
69323
  risk_reward,
69200
- risk
69324
+ risk,
69325
+ distribution: db_config.distribution,
69326
+ distribution_params: db_config.distribution_params
69201
69327
  });
69202
69328
  let config2 = generate_config_params(app_config, {
69203
69329
  entry,
@@ -69213,7 +69339,9 @@ class ExchangePosition {
69213
69339
  risk_reward: config2.risk_reward,
69214
69340
  risk: config2.risk,
69215
69341
  profit: 0,
69216
- update_db: false
69342
+ update_db: false,
69343
+ distribution: db_config.distribution,
69344
+ distribution_params: db_config.distribution_params
69217
69345
  });
69218
69346
  const { trades } = await this.placeConfigOrders(app_config2, {
69219
69347
  risk_reward: config2.risk_reward,
@@ -69311,7 +69439,9 @@ class ExchangePosition {
69311
69439
  entry: config2.entry,
69312
69440
  stop: config2.stop,
69313
69441
  risk_reward: config2.risk_reward,
69314
- risk: risk || config2.risk
69442
+ risk: risk || config2.risk,
69443
+ distribution: config2.distribution,
69444
+ distribution_params: config2.distribution_params
69315
69445
  });
69316
69446
  const { trades } = await this.placeConfigOrders(app_config, {
69317
69447
  risk_reward: config2.risk_reward,
@@ -69367,6 +69497,8 @@ class ExchangePosition {
69367
69497
  kelly_minimum_risk: config2.kelly?.kelly_minimum_risk,
69368
69498
  kelly_prediction_model: config2.kelly?.kelly_prediction_model,
69369
69499
  kelly_func: config2.kelly?.kelly_func,
69500
+ distribution: config2.distribution,
69501
+ distribution_params: config2.distribution_params,
69370
69502
  ...override
69371
69503
  });
69372
69504
  return app_config;
@@ -69941,7 +70073,7 @@ class ExchangeAccount {
69941
70073
  kind: "short"
69942
70074
  });
69943
70075
  const long_config = await long_position.getConfig();
69944
- const short_config = await short_position.getConfig();
70076
+ const short_config = short_position.getInstance().expand.b_config;
69945
70077
  const config2 = build_reduce_config({
69946
70078
  account: this.instance,
69947
70079
  symbol: payload.symbol,