@gbozee/ultimate 0.0.2-67 → 0.0.2-69

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.
@@ -392,6 +392,12 @@ export declare function computeRiskReward(payload: {
392
392
  neg_pnl: any;
393
393
  entry: any;
394
394
  };
395
+ export declare function getRiskReward(payload: {
396
+ entry: number;
397
+ stop: number;
398
+ risk: number;
399
+ global_config: GlobalConfig;
400
+ }): any;
395
401
  export type StrategyPosition = {
396
402
  entry: number;
397
403
  quantity: number;
@@ -410,11 +416,13 @@ export declare class Strategy {
410
416
  long: StrategyPosition;
411
417
  short: StrategyPosition;
412
418
  };
419
+ dominant_position?: "long" | "short";
413
420
  config: Config;
414
421
  constructor(payload: {
415
422
  long: StrategyPosition;
416
423
  short: StrategyPosition;
417
424
  config: Config;
425
+ dominant_position?: "long" | "short";
418
426
  });
419
427
  get price_places(): string;
420
428
  get decimal_places(): string;
@@ -491,6 +499,41 @@ export declare class Strategy {
491
499
  };
492
500
  spread: number;
493
501
  }[];
502
+ generateOppositeTrades(payload: {
503
+ kind: "long" | "short";
504
+ risk_factor?: number;
505
+ }): {
506
+ avg: {
507
+ entry: number;
508
+ price: number;
509
+ quantity: number;
510
+ };
511
+ loss: number;
512
+ fee: number;
513
+ risk_per_trade: number;
514
+ risk_reward: number;
515
+ symbol?: string;
516
+ focus: number;
517
+ budget: number;
518
+ support: number;
519
+ resistance: number;
520
+ percent_change: number;
521
+ tradeSplit?: number;
522
+ take_profit?: number;
523
+ kind: "long" | "short";
524
+ entry: number;
525
+ stop: number;
526
+ min_size: number;
527
+ price_places?: string;
528
+ strategy?: "quantity" | "entry";
529
+ as_array?: boolean;
530
+ decimal_places?: string;
531
+ min_profit?: number;
532
+ raw?: boolean;
533
+ gap?: number;
534
+ rr?: number;
535
+ max_size?: number;
536
+ };
494
537
  }
495
538
 
496
539
  export {};
@@ -1751,15 +1751,34 @@ function computeRiskReward(payload) {
1751
1751
  const result = determineOptimumReward(app_config);
1752
1752
  return result;
1753
1753
  }
1754
+ function getRiskReward(payload) {
1755
+ const { entry, stop, risk, global_config } = payload;
1756
+ const { entries, last_value, ...app_config } = buildAppConfig(global_config, {
1757
+ entry,
1758
+ stop,
1759
+ risk_reward: 30,
1760
+ risk,
1761
+ symbol: global_config.symbol
1762
+ });
1763
+ const risk_reward = computeRiskReward({
1764
+ app_config,
1765
+ entry,
1766
+ stop,
1767
+ risk_per_trade: risk
1768
+ });
1769
+ return risk_reward;
1770
+ }
1754
1771
  // src/helpers/strategy.ts
1755
1772
  class Strategy {
1756
1773
  position;
1774
+ dominant_position = "long";
1757
1775
  config;
1758
1776
  constructor(payload) {
1759
1777
  this.position = {
1760
1778
  long: payload.long,
1761
1779
  short: payload.short
1762
1780
  };
1781
+ this.dominant_position = payload.dominant_position || "long";
1763
1782
  this.config = payload.config;
1764
1783
  if (!this.config.fee_percent) {
1765
1784
  this.config.fee_percent = 0.05;
@@ -2020,6 +2039,44 @@ class Strategy {
2020
2039
  }
2021
2040
  return result;
2022
2041
  }
2042
+ generateOppositeTrades(payload) {
2043
+ const { kind, risk_factor = 0.5 } = payload;
2044
+ const entry = this.position[kind].entry;
2045
+ const stop = this.tp(kind);
2046
+ const risk = this.pnl(kind) * risk_factor;
2047
+ const risk_reward = getRiskReward({
2048
+ entry,
2049
+ stop,
2050
+ risk,
2051
+ global_config: this.config.global_config
2052
+ });
2053
+ const { entries, last_value, ...app_config } = buildAppConfig(this.config.global_config, {
2054
+ entry,
2055
+ stop,
2056
+ risk_reward,
2057
+ risk,
2058
+ symbol: this.config.global_config.symbol
2059
+ });
2060
+ const trades_to_place = determine_amount_to_buy({
2061
+ orders: entries,
2062
+ kind: app_config.kind,
2063
+ decimal_places: app_config.decimal_places,
2064
+ price_places: app_config.price_places,
2065
+ position: this.position[app_config.kind],
2066
+ existingOrders: []
2067
+ });
2068
+ const avg = determine_average_entry_and_size(trades_to_place.map((u) => ({
2069
+ price: u.entry,
2070
+ quantity: u.quantity
2071
+ })).concat([
2072
+ {
2073
+ price: this.position[app_config.kind].entry,
2074
+ quantity: this.position[app_config.kind].quantity
2075
+ }
2076
+ ]), app_config.decimal_places, app_config.price_places);
2077
+ const expected_loss = Math.abs(avg.price - stop) * avg.quantity;
2078
+ return { ...app_config, avg, loss: -expected_loss };
2079
+ }
2023
2080
  }
2024
2081
  export {
2025
2082
  to_f,
@@ -2032,6 +2089,7 @@ export {
2032
2089
  groupBy,
2033
2090
  get_app_config_and_max_size,
2034
2091
  getTradeEntries,
2092
+ getRiskReward,
2035
2093
  getParamForField,
2036
2094
  getOptimumStopAndRisk,
2037
2095
  getDecimalPlaces,
package/dist/index.cjs CHANGED
@@ -41739,6 +41739,7 @@ __export(exports_src, {
41739
41739
  initialize: () => initialize,
41740
41740
  initApp: () => initApp,
41741
41741
  get_app_config_and_max_size: () => get_app_config_and_max_size,
41742
+ getRiskReward: () => getRiskReward,
41742
41743
  getOptimumStopAndRisk: () => getOptimumStopAndRisk,
41743
41744
  generate_config_params: () => generate_config_params,
41744
41745
  generateOptimumAppConfig: () => generateOptimumAppConfig,
@@ -51657,7 +51658,11 @@ class AppDatabase {
51657
51658
  const orders = await this.pb.collection("orders").getFullList({
51658
51659
  filter: `symbol:lower="${symbol.toLowerCase()}" && account.owner:lower="${account.owner.toLowerCase()}" && account.exchange:lower="${account.exchange.toLowerCase()}" && kind="${kind}" && side:lower="${side}" && stop = 0`
51659
51660
  });
51660
- const exchange_order_ids = orders.map((o) => parseInt(o.order_id, 10));
51661
+ const stop_side = kind === "long" ? "sell" : "buy";
51662
+ const existing_stop_orders = await this.pb.collection("orders").getFullList({
51663
+ filter: `symbol:lower="${symbol.toLowerCase()}" && account.owner:lower="${account.owner.toLowerCase()}" && account.exchange:lower="${account.exchange.toLowerCase()}" && kind="${kind}" && side:lower="${stop_side}" && stop > 0`
51664
+ });
51665
+ const exchange_order_ids = orders.concat(existing_stop_orders).map((o) => parseInt(o.order_id, 10));
51661
51666
  try {
51662
51667
  console.log(`Attempting to cancel ${exchange_order_ids.length} orders on ${account.exchange} for ${account.owner}...`);
51663
51668
  const cancel_result = await cancelExchangeOrders({
@@ -53652,16 +53657,35 @@ function computeRiskReward(payload) {
53652
53657
  const result = determineOptimumReward(app_config);
53653
53658
  return result;
53654
53659
  }
53660
+ function getRiskReward(payload) {
53661
+ const { entry, stop, risk, global_config } = payload;
53662
+ const { entries, last_value, ...app_config } = buildAppConfig(global_config, {
53663
+ entry,
53664
+ stop,
53665
+ risk_reward: 30,
53666
+ risk,
53667
+ symbol: global_config.symbol
53668
+ });
53669
+ const risk_reward = computeRiskReward({
53670
+ app_config,
53671
+ entry,
53672
+ stop,
53673
+ risk_per_trade: risk
53674
+ });
53675
+ return risk_reward;
53676
+ }
53655
53677
 
53656
53678
  // src/helpers/strategy.ts
53657
53679
  class Strategy {
53658
53680
  position;
53681
+ dominant_position = "long";
53659
53682
  config;
53660
53683
  constructor(payload) {
53661
53684
  this.position = {
53662
53685
  long: payload.long,
53663
53686
  short: payload.short
53664
53687
  };
53688
+ this.dominant_position = payload.dominant_position || "long";
53665
53689
  this.config = payload.config;
53666
53690
  if (!this.config.fee_percent) {
53667
53691
  this.config.fee_percent = 0.05;
@@ -53922,6 +53946,44 @@ class Strategy {
53922
53946
  }
53923
53947
  return result;
53924
53948
  }
53949
+ generateOppositeTrades(payload) {
53950
+ const { kind, risk_factor = 0.5 } = payload;
53951
+ const entry = this.position[kind].entry;
53952
+ const stop = this.tp(kind);
53953
+ const risk = this.pnl(kind) * risk_factor;
53954
+ const risk_reward = getRiskReward({
53955
+ entry,
53956
+ stop,
53957
+ risk,
53958
+ global_config: this.config.global_config
53959
+ });
53960
+ const { entries, last_value, ...app_config } = buildAppConfig(this.config.global_config, {
53961
+ entry,
53962
+ stop,
53963
+ risk_reward,
53964
+ risk,
53965
+ symbol: this.config.global_config.symbol
53966
+ });
53967
+ const trades_to_place = determine_amount_to_buy({
53968
+ orders: entries,
53969
+ kind: app_config.kind,
53970
+ decimal_places: app_config.decimal_places,
53971
+ price_places: app_config.price_places,
53972
+ position: this.position[app_config.kind],
53973
+ existingOrders: []
53974
+ });
53975
+ const avg = determine_average_entry_and_size(trades_to_place.map((u) => ({
53976
+ price: u.entry,
53977
+ quantity: u.quantity
53978
+ })).concat([
53979
+ {
53980
+ price: this.position[app_config.kind].entry,
53981
+ quantity: this.position[app_config.kind].quantity
53982
+ }
53983
+ ]), app_config.decimal_places, app_config.price_places);
53984
+ const expected_loss = Math.abs(avg.price - stop) * avg.quantity;
53985
+ return { ...app_config, avg, loss: -expected_loss };
53986
+ }
53925
53987
  }
53926
53988
 
53927
53989
  // src/exchanges/binance.ts
@@ -57709,13 +57771,12 @@ class ExchangeAccount {
57709
57771
  symbol,
57710
57772
  kind: "short"
57711
57773
  });
57712
- const focus_position = kind === "long" ? long_position : short_position;
57713
57774
  const focus_config = kind === "long" ? long_config : short_config;
57714
57775
  const short_tp_factor = short_config.profit_percent / long_config.profit_percent;
57715
- const reduce_ratio = focus_config.reduce_ratio || focus_position?.reduce_ratio;
57776
+ const reduce_ratio = focus_config.reduce_ratio;
57716
57777
  const budget = focus_config.risk;
57717
57778
  const risk_reward = focus_config.risk_reward;
57718
- const tp_percent = focus_config.profit_percent;
57779
+ const tp_percent = long_config.profit_percent;
57719
57780
  const fee_percent = symbol_config.fee_percent;
57720
57781
  const strategy_config = {
57721
57782
  tp_percent,
package/dist/index.d.ts CHANGED
@@ -119,6 +119,7 @@ export interface PositionsView {
119
119
  threshold_qty?: number;
120
120
  follow?: boolean | 1 | 0;
121
121
  current_price?: number;
122
+ usd_balance?: number;
122
123
  }
123
124
  export interface BullishMarket extends RecordModel {
124
125
  id: string;
@@ -541,11 +542,13 @@ export declare class Strategy {
541
542
  long: StrategyPosition;
542
543
  short: StrategyPosition;
543
544
  };
545
+ dominant_position?: "long" | "short";
544
546
  config: Config;
545
547
  constructor(payload: {
546
548
  long: StrategyPosition;
547
549
  short: StrategyPosition;
548
550
  config: Config;
551
+ dominant_position?: "long" | "short";
549
552
  });
550
553
  get price_places(): string;
551
554
  get decimal_places(): string;
@@ -622,6 +625,41 @@ export declare class Strategy {
622
625
  };
623
626
  spread: number;
624
627
  }[];
628
+ generateOppositeTrades(payload: {
629
+ kind: "long" | "short";
630
+ risk_factor?: number;
631
+ }): {
632
+ avg: {
633
+ entry: number;
634
+ price: number;
635
+ quantity: number;
636
+ };
637
+ loss: number;
638
+ fee: number;
639
+ risk_per_trade: number;
640
+ risk_reward: number;
641
+ symbol?: string;
642
+ focus: number;
643
+ budget: number;
644
+ support: number;
645
+ resistance: number;
646
+ percent_change: number;
647
+ tradeSplit?: number;
648
+ take_profit?: number;
649
+ kind: "long" | "short";
650
+ entry: number;
651
+ stop: number;
652
+ min_size: number;
653
+ price_places?: string;
654
+ strategy?: "quantity" | "entry";
655
+ as_array?: boolean;
656
+ decimal_places?: string;
657
+ min_profit?: number;
658
+ raw?: boolean;
659
+ gap?: number;
660
+ rr?: number;
661
+ max_size?: number;
662
+ };
625
663
  }
626
664
  export type SignalConfigType = {
627
665
  focus: number;
@@ -925,6 +963,12 @@ export declare function computeRiskReward(payload: {
925
963
  neg_pnl: any;
926
964
  entry: any;
927
965
  };
966
+ export declare function getRiskReward(payload: {
967
+ entry: number;
968
+ stop: number;
969
+ risk: number;
970
+ global_config: GlobalConfig;
971
+ }): any;
928
972
  declare class ExchangePosition {
929
973
  exchange: BaseExchange;
930
974
  exchange_account: ExchangeAccount$1;
package/dist/index.js CHANGED
@@ -51613,7 +51613,11 @@ class AppDatabase {
51613
51613
  const orders = await this.pb.collection("orders").getFullList({
51614
51614
  filter: `symbol:lower="${symbol.toLowerCase()}" && account.owner:lower="${account.owner.toLowerCase()}" && account.exchange:lower="${account.exchange.toLowerCase()}" && kind="${kind}" && side:lower="${side}" && stop = 0`
51615
51615
  });
51616
- const exchange_order_ids = orders.map((o) => parseInt(o.order_id, 10));
51616
+ const stop_side = kind === "long" ? "sell" : "buy";
51617
+ const existing_stop_orders = await this.pb.collection("orders").getFullList({
51618
+ filter: `symbol:lower="${symbol.toLowerCase()}" && account.owner:lower="${account.owner.toLowerCase()}" && account.exchange:lower="${account.exchange.toLowerCase()}" && kind="${kind}" && side:lower="${stop_side}" && stop > 0`
51619
+ });
51620
+ const exchange_order_ids = orders.concat(existing_stop_orders).map((o) => parseInt(o.order_id, 10));
51617
51621
  try {
51618
51622
  console.log(`Attempting to cancel ${exchange_order_ids.length} orders on ${account.exchange} for ${account.owner}...`);
51619
51623
  const cancel_result = await cancelExchangeOrders({
@@ -53608,16 +53612,35 @@ function computeRiskReward(payload) {
53608
53612
  const result = determineOptimumReward(app_config);
53609
53613
  return result;
53610
53614
  }
53615
+ function getRiskReward(payload) {
53616
+ const { entry, stop, risk, global_config } = payload;
53617
+ const { entries, last_value, ...app_config } = buildAppConfig(global_config, {
53618
+ entry,
53619
+ stop,
53620
+ risk_reward: 30,
53621
+ risk,
53622
+ symbol: global_config.symbol
53623
+ });
53624
+ const risk_reward = computeRiskReward({
53625
+ app_config,
53626
+ entry,
53627
+ stop,
53628
+ risk_per_trade: risk
53629
+ });
53630
+ return risk_reward;
53631
+ }
53611
53632
 
53612
53633
  // src/helpers/strategy.ts
53613
53634
  class Strategy {
53614
53635
  position;
53636
+ dominant_position = "long";
53615
53637
  config;
53616
53638
  constructor(payload) {
53617
53639
  this.position = {
53618
53640
  long: payload.long,
53619
53641
  short: payload.short
53620
53642
  };
53643
+ this.dominant_position = payload.dominant_position || "long";
53621
53644
  this.config = payload.config;
53622
53645
  if (!this.config.fee_percent) {
53623
53646
  this.config.fee_percent = 0.05;
@@ -53878,6 +53901,44 @@ class Strategy {
53878
53901
  }
53879
53902
  return result;
53880
53903
  }
53904
+ generateOppositeTrades(payload) {
53905
+ const { kind, risk_factor = 0.5 } = payload;
53906
+ const entry = this.position[kind].entry;
53907
+ const stop = this.tp(kind);
53908
+ const risk = this.pnl(kind) * risk_factor;
53909
+ const risk_reward = getRiskReward({
53910
+ entry,
53911
+ stop,
53912
+ risk,
53913
+ global_config: this.config.global_config
53914
+ });
53915
+ const { entries, last_value, ...app_config } = buildAppConfig(this.config.global_config, {
53916
+ entry,
53917
+ stop,
53918
+ risk_reward,
53919
+ risk,
53920
+ symbol: this.config.global_config.symbol
53921
+ });
53922
+ const trades_to_place = determine_amount_to_buy({
53923
+ orders: entries,
53924
+ kind: app_config.kind,
53925
+ decimal_places: app_config.decimal_places,
53926
+ price_places: app_config.price_places,
53927
+ position: this.position[app_config.kind],
53928
+ existingOrders: []
53929
+ });
53930
+ const avg = determine_average_entry_and_size(trades_to_place.map((u) => ({
53931
+ price: u.entry,
53932
+ quantity: u.quantity
53933
+ })).concat([
53934
+ {
53935
+ price: this.position[app_config.kind].entry,
53936
+ quantity: this.position[app_config.kind].quantity
53937
+ }
53938
+ ]), app_config.decimal_places, app_config.price_places);
53939
+ const expected_loss = Math.abs(avg.price - stop) * avg.quantity;
53940
+ return { ...app_config, avg, loss: -expected_loss };
53941
+ }
53881
53942
  }
53882
53943
 
53883
53944
  // src/exchanges/binance.ts
@@ -57665,13 +57726,12 @@ class ExchangeAccount {
57665
57726
  symbol,
57666
57727
  kind: "short"
57667
57728
  });
57668
- const focus_position = kind === "long" ? long_position : short_position;
57669
57729
  const focus_config = kind === "long" ? long_config : short_config;
57670
57730
  const short_tp_factor = short_config.profit_percent / long_config.profit_percent;
57671
- const reduce_ratio = focus_config.reduce_ratio || focus_position?.reduce_ratio;
57731
+ const reduce_ratio = focus_config.reduce_ratio;
57672
57732
  const budget = focus_config.risk;
57673
57733
  const risk_reward = focus_config.risk_reward;
57674
- const tp_percent = focus_config.profit_percent;
57734
+ const tp_percent = long_config.profit_percent;
57675
57735
  const fee_percent = symbol_config.fee_percent;
57676
57736
  const strategy_config = {
57677
57737
  tp_percent,
@@ -58749,6 +58809,7 @@ export {
58749
58809
  initialize,
58750
58810
  initApp,
58751
58811
  get_app_config_and_max_size,
58812
+ getRiskReward,
58752
58813
  getOptimumStopAndRisk,
58753
58814
  generate_config_params,
58754
58815
  generateOptimumAppConfig,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-67",
4
+ "version": "0.0.2-69",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",