@gbozee/ultimate 0.0.2-51 → 0.0.2-54

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.
@@ -367,13 +367,11 @@ export type StrategyPosition = {
367
367
  quantity: number;
368
368
  };
369
369
  export type Config = {
370
- leverage: number;
371
370
  tp_percent: number;
372
371
  short_tp_factor: number;
373
- price_places: string;
374
- decimal_places: string;
375
372
  fee_percent?: number;
376
373
  budget: number;
374
+ risk_reward: number;
377
375
  global_config: GlobalConfig;
378
376
  };
379
377
  export declare class Strategy {
@@ -387,6 +385,8 @@ export declare class Strategy {
387
385
  short: StrategyPosition;
388
386
  config: Config;
389
387
  });
388
+ get price_places(): string;
389
+ get decimal_places(): string;
390
390
  to_f(price: number): number;
391
391
  to_df(quantity: number): number;
392
392
  pnl(kind: "long" | "short"): number;
@@ -399,10 +399,10 @@ export declare class Strategy {
399
399
  get short_tp(): number;
400
400
  generateGapClosingAlgorithm(payload: {
401
401
  kind: "long" | "short";
402
- risk_reward?: number;
403
402
  }): {
404
403
  [x: string]: any;
405
404
  risk: number;
405
+ risk_reward: number;
406
406
  last_entry: any;
407
407
  first_entry: any;
408
408
  threshold: any;
@@ -414,6 +414,7 @@ export declare class Strategy {
414
414
  }): {
415
415
  [x: string]: any;
416
416
  risk: number;
417
+ risk_reward: number;
417
418
  last_entry: any;
418
419
  first_entry: any;
419
420
  threshold: any;
@@ -1651,11 +1651,17 @@ class Strategy {
1651
1651
  this.config.fee_percent = 0.05;
1652
1652
  }
1653
1653
  }
1654
+ get price_places() {
1655
+ return this.config.global_config.price_places;
1656
+ }
1657
+ get decimal_places() {
1658
+ return this.config.global_config.decimal_places;
1659
+ }
1654
1660
  to_f(price) {
1655
- return to_f(price, this.config.price_places);
1661
+ return to_f(price, this.price_places);
1656
1662
  }
1657
1663
  to_df(quantity) {
1658
- return to_f(quantity, this.config.decimal_places);
1664
+ return to_f(quantity, this.decimal_places);
1659
1665
  }
1660
1666
  pnl(kind) {
1661
1667
  const position2 = this.position[kind];
@@ -1687,15 +1693,20 @@ class Strategy {
1687
1693
  return this.tp("short");
1688
1694
  }
1689
1695
  generateGapClosingAlgorithm(payload) {
1690
- const { kind, risk_reward = 199 } = payload;
1696
+ const { kind } = payload;
1691
1697
  const { entry, quantity } = this.position[kind];
1692
1698
  const focus_position = this.position[kind];
1693
1699
  const reverse_kind = kind == "long" ? "short" : "long";
1694
1700
  const reverse_position = this.position[reverse_kind];
1701
+ let _entry = this.tp(kind);
1702
+ let _stop = this.tp(reverse_kind);
1703
+ if (!_entry && !_stop) {
1704
+ return null;
1705
+ }
1695
1706
  const second_payload = {
1696
- entry: this.tp(kind),
1697
- stop: this.tp(reverse_kind),
1698
- risk_reward,
1707
+ entry: _entry,
1708
+ stop: _stop,
1709
+ risk_reward: this.config.risk_reward,
1699
1710
  start_risk: this.pnl(reverse_kind),
1700
1711
  max_risk: this.config.budget
1701
1712
  };
@@ -1772,6 +1783,7 @@ class Strategy {
1772
1783
  const remaining_quantity = this.to_df(avg.quantity - quantity_to_sell);
1773
1784
  return {
1774
1785
  risk,
1786
+ risk_reward: this.config.risk_reward,
1775
1787
  [kind]: {
1776
1788
  avg_entry: avg.entry,
1777
1789
  avg_size: avg.quantity,
@@ -1796,7 +1808,7 @@ class Strategy {
1796
1808
  };
1797
1809
  }
1798
1810
  runIterations(payload) {
1799
- const { kind, iterations, risk_reward = 199 } = payload;
1811
+ const { kind, iterations } = payload;
1800
1812
  const reverse_kind = kind == "long" ? "short" : "long";
1801
1813
  const result = [];
1802
1814
  let position2 = {
@@ -1813,8 +1825,7 @@ class Strategy {
1813
1825
  }
1814
1826
  });
1815
1827
  const algorithm = instance.generateGapClosingAlgorithm({
1816
- kind,
1817
- risk_reward
1828
+ kind
1818
1829
  });
1819
1830
  if (!algorithm) {
1820
1831
  console.log("No algorithm found");