@gbozee/ultimate 0.0.2-75 → 0.0.2-77

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.
@@ -401,6 +401,7 @@ export declare function getRiskReward(payload: {
401
401
  export type StrategyPosition = {
402
402
  entry: number;
403
403
  quantity: number;
404
+ avg_price?: number;
404
405
  };
405
406
  export type GapCloserResult = {
406
407
  avg_entry: number;
package/dist/index.cjs CHANGED
@@ -58001,10 +58001,57 @@ class ExchangeAccount {
58001
58001
  }
58002
58002
  return 0;
58003
58003
  }
58004
+ async buildOppositeTrades(payload) {
58005
+ const { symbol, kind, place } = payload;
58006
+ const strategy = await this.runSimulation({
58007
+ symbol,
58008
+ kind,
58009
+ raw: true
58010
+ });
58011
+ const result = strategy.generateOppositeTrades({
58012
+ kind,
58013
+ avg_entry: strategy.position[kind].avg_price
58014
+ });
58015
+ if (place && result?.kind) {
58016
+ const position2 = await this.syncAccount({
58017
+ symbol,
58018
+ kind: result.kind,
58019
+ as_view: true
58020
+ });
58021
+ if (position2.avg_qty !== result.avg.quantity) {
58022
+ const config2 = await this.getPositionConfig({
58023
+ symbol,
58024
+ kind: result.kind
58025
+ });
58026
+ await this.app_db.updateScheduledTrade(config2.id, {
58027
+ entry: result.entry,
58028
+ stop: result.stop,
58029
+ risk: result.risk_per_trade,
58030
+ profit_percent: result.profit_percent,
58031
+ risk_reward: result.risk_reward
58032
+ });
58033
+ await this.placeTrade({
58034
+ symbol,
58035
+ kind: result.kind,
58036
+ place: true,
58037
+ ignore_config: true
58038
+ });
58039
+ await this.placeTrade({
58040
+ symbol,
58041
+ kind: result.kind,
58042
+ place: true,
58043
+ stop: true,
58044
+ ignore_config: true
58045
+ });
58046
+ }
58047
+ }
58048
+ return result;
58049
+ }
58004
58050
  async runSimulation(payload) {
58005
58051
  const { symbol, kind, iterations = 2, raw = false } = payload;
58006
58052
  const positions = await this.syncAccount({
58007
- symbol
58053
+ symbol,
58054
+ as_view: true
58008
58055
  });
58009
58056
  const symbol_config = await this.recomputeSymbolConfig({
58010
58057
  symbol
@@ -58038,11 +58085,13 @@ class ExchangeAccount {
58038
58085
  const strategy = new Strategy({
58039
58086
  long: {
58040
58087
  entry: long_position.entry,
58041
- quantity: long_position.quantity
58088
+ quantity: long_position.quantity,
58089
+ avg_price: long_position.avg_price
58042
58090
  },
58043
58091
  short: {
58044
58092
  entry: short_position.entry,
58045
- quantity: short_position.quantity
58093
+ quantity: short_position.quantity,
58094
+ avg_price: short_position.avg_price
58046
58095
  },
58047
58096
  config: strategy_config
58048
58097
  });
package/dist/index.d.ts CHANGED
@@ -527,6 +527,7 @@ export declare class AppDatabase {
527
527
  export type StrategyPosition = {
528
528
  entry: number;
529
529
  quantity: number;
530
+ avg_price?: number;
530
531
  };
531
532
  export type GapCloserResult = {
532
533
  avg_entry: number;
@@ -1493,6 +1494,43 @@ declare class ExchangeAccount$1 {
1493
1494
  symbol: string;
1494
1495
  kind: "long" | "short";
1495
1496
  }): Promise<number>;
1497
+ buildOppositeTrades(payload: {
1498
+ symbol: string;
1499
+ kind: "long" | "short";
1500
+ place?: boolean;
1501
+ }): Promise<{
1502
+ avg: {
1503
+ entry: number;
1504
+ price: number;
1505
+ quantity: number;
1506
+ };
1507
+ loss: number;
1508
+ profit_percent: number;
1509
+ fee: number;
1510
+ risk_per_trade: number;
1511
+ risk_reward: number;
1512
+ symbol?: string;
1513
+ focus: number;
1514
+ budget: number;
1515
+ support: number;
1516
+ resistance: number;
1517
+ percent_change: number;
1518
+ tradeSplit?: number;
1519
+ take_profit?: number;
1520
+ kind: "long" | "short";
1521
+ entry: number;
1522
+ stop: number;
1523
+ min_size: number;
1524
+ price_places?: string;
1525
+ strategy?: "quantity" | "entry";
1526
+ as_array?: boolean;
1527
+ decimal_places?: string;
1528
+ min_profit?: number;
1529
+ raw?: boolean;
1530
+ gap?: number;
1531
+ rr?: number;
1532
+ max_size?: number;
1533
+ }>;
1496
1534
  runSimulation(payload: {
1497
1535
  symbol: string;
1498
1536
  kind: "long" | "short";
package/dist/index.js CHANGED
@@ -57956,10 +57956,57 @@ class ExchangeAccount {
57956
57956
  }
57957
57957
  return 0;
57958
57958
  }
57959
+ async buildOppositeTrades(payload) {
57960
+ const { symbol, kind, place } = payload;
57961
+ const strategy = await this.runSimulation({
57962
+ symbol,
57963
+ kind,
57964
+ raw: true
57965
+ });
57966
+ const result = strategy.generateOppositeTrades({
57967
+ kind,
57968
+ avg_entry: strategy.position[kind].avg_price
57969
+ });
57970
+ if (place && result?.kind) {
57971
+ const position2 = await this.syncAccount({
57972
+ symbol,
57973
+ kind: result.kind,
57974
+ as_view: true
57975
+ });
57976
+ if (position2.avg_qty !== result.avg.quantity) {
57977
+ const config2 = await this.getPositionConfig({
57978
+ symbol,
57979
+ kind: result.kind
57980
+ });
57981
+ await this.app_db.updateScheduledTrade(config2.id, {
57982
+ entry: result.entry,
57983
+ stop: result.stop,
57984
+ risk: result.risk_per_trade,
57985
+ profit_percent: result.profit_percent,
57986
+ risk_reward: result.risk_reward
57987
+ });
57988
+ await this.placeTrade({
57989
+ symbol,
57990
+ kind: result.kind,
57991
+ place: true,
57992
+ ignore_config: true
57993
+ });
57994
+ await this.placeTrade({
57995
+ symbol,
57996
+ kind: result.kind,
57997
+ place: true,
57998
+ stop: true,
57999
+ ignore_config: true
58000
+ });
58001
+ }
58002
+ }
58003
+ return result;
58004
+ }
57959
58005
  async runSimulation(payload) {
57960
58006
  const { symbol, kind, iterations = 2, raw = false } = payload;
57961
58007
  const positions = await this.syncAccount({
57962
- symbol
58008
+ symbol,
58009
+ as_view: true
57963
58010
  });
57964
58011
  const symbol_config = await this.recomputeSymbolConfig({
57965
58012
  symbol
@@ -57993,11 +58040,13 @@ class ExchangeAccount {
57993
58040
  const strategy = new Strategy({
57994
58041
  long: {
57995
58042
  entry: long_position.entry,
57996
- quantity: long_position.quantity
58043
+ quantity: long_position.quantity,
58044
+ avg_price: long_position.avg_price
57997
58045
  },
57998
58046
  short: {
57999
58047
  entry: short_position.entry,
58000
- quantity: short_position.quantity
58048
+ quantity: short_position.quantity,
58049
+ avg_price: short_position.avg_price
58001
58050
  },
58002
58051
  config: strategy_config
58003
58052
  });
@@ -64692,10 +64692,57 @@ class ExchangeAccount {
64692
64692
  }
64693
64693
  return 0;
64694
64694
  }
64695
+ async buildOppositeTrades(payload) {
64696
+ const { symbol, kind, place } = payload;
64697
+ const strategy = await this.runSimulation({
64698
+ symbol,
64699
+ kind,
64700
+ raw: true
64701
+ });
64702
+ const result = strategy.generateOppositeTrades({
64703
+ kind,
64704
+ avg_entry: strategy.position[kind].avg_price
64705
+ });
64706
+ if (place && result?.kind) {
64707
+ const position2 = await this.syncAccount({
64708
+ symbol,
64709
+ kind: result.kind,
64710
+ as_view: true
64711
+ });
64712
+ if (position2.avg_qty !== result.avg.quantity) {
64713
+ const config2 = await this.getPositionConfig({
64714
+ symbol,
64715
+ kind: result.kind
64716
+ });
64717
+ await this.app_db.updateScheduledTrade(config2.id, {
64718
+ entry: result.entry,
64719
+ stop: result.stop,
64720
+ risk: result.risk_per_trade,
64721
+ profit_percent: result.profit_percent,
64722
+ risk_reward: result.risk_reward
64723
+ });
64724
+ await this.placeTrade({
64725
+ symbol,
64726
+ kind: result.kind,
64727
+ place: true,
64728
+ ignore_config: true
64729
+ });
64730
+ await this.placeTrade({
64731
+ symbol,
64732
+ kind: result.kind,
64733
+ place: true,
64734
+ stop: true,
64735
+ ignore_config: true
64736
+ });
64737
+ }
64738
+ }
64739
+ return result;
64740
+ }
64695
64741
  async runSimulation(payload) {
64696
64742
  const { symbol, kind, iterations = 2, raw = false } = payload;
64697
64743
  const positions = await this.syncAccount({
64698
- symbol
64744
+ symbol,
64745
+ as_view: true
64699
64746
  });
64700
64747
  const symbol_config = await this.recomputeSymbolConfig({
64701
64748
  symbol
@@ -64729,11 +64776,13 @@ class ExchangeAccount {
64729
64776
  const strategy = new Strategy({
64730
64777
  long: {
64731
64778
  entry: long_position.entry,
64732
- quantity: long_position.quantity
64779
+ quantity: long_position.quantity,
64780
+ avg_price: long_position.avg_price
64733
64781
  },
64734
64782
  short: {
64735
64783
  entry: short_position.entry,
64736
- quantity: short_position.quantity
64784
+ quantity: short_position.quantity,
64785
+ avg_price: short_position.avg_price
64737
64786
  },
64738
64787
  config: strategy_config
64739
64788
  });
@@ -64669,10 +64669,57 @@ class ExchangeAccount {
64669
64669
  }
64670
64670
  return 0;
64671
64671
  }
64672
+ async buildOppositeTrades(payload) {
64673
+ const { symbol, kind, place } = payload;
64674
+ const strategy = await this.runSimulation({
64675
+ symbol,
64676
+ kind,
64677
+ raw: true
64678
+ });
64679
+ const result = strategy.generateOppositeTrades({
64680
+ kind,
64681
+ avg_entry: strategy.position[kind].avg_price
64682
+ });
64683
+ if (place && result?.kind) {
64684
+ const position2 = await this.syncAccount({
64685
+ symbol,
64686
+ kind: result.kind,
64687
+ as_view: true
64688
+ });
64689
+ if (position2.avg_qty !== result.avg.quantity) {
64690
+ const config2 = await this.getPositionConfig({
64691
+ symbol,
64692
+ kind: result.kind
64693
+ });
64694
+ await this.app_db.updateScheduledTrade(config2.id, {
64695
+ entry: result.entry,
64696
+ stop: result.stop,
64697
+ risk: result.risk_per_trade,
64698
+ profit_percent: result.profit_percent,
64699
+ risk_reward: result.risk_reward
64700
+ });
64701
+ await this.placeTrade({
64702
+ symbol,
64703
+ kind: result.kind,
64704
+ place: true,
64705
+ ignore_config: true
64706
+ });
64707
+ await this.placeTrade({
64708
+ symbol,
64709
+ kind: result.kind,
64710
+ place: true,
64711
+ stop: true,
64712
+ ignore_config: true
64713
+ });
64714
+ }
64715
+ }
64716
+ return result;
64717
+ }
64672
64718
  async runSimulation(payload) {
64673
64719
  const { symbol, kind, iterations = 2, raw = false } = payload;
64674
64720
  const positions = await this.syncAccount({
64675
- symbol
64721
+ symbol,
64722
+ as_view: true
64676
64723
  });
64677
64724
  const symbol_config = await this.recomputeSymbolConfig({
64678
64725
  symbol
@@ -64706,11 +64753,13 @@ class ExchangeAccount {
64706
64753
  const strategy = new Strategy({
64707
64754
  long: {
64708
64755
  entry: long_position.entry,
64709
- quantity: long_position.quantity
64756
+ quantity: long_position.quantity,
64757
+ avg_price: long_position.avg_price
64710
64758
  },
64711
64759
  short: {
64712
64760
  entry: short_position.entry,
64713
- quantity: short_position.quantity
64761
+ quantity: short_position.quantity,
64762
+ avg_price: short_position.avg_price
64714
64763
  },
64715
64764
  config: strategy_config
64716
64765
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-75",
4
+ "version": "0.0.2-77",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",