@gbozee/ultimate 0.0.2-100 → 0.0.2-101

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.
@@ -716,6 +716,43 @@ export declare class Strategy {
716
716
  price_places: string;
717
717
  decimal_places: string;
718
718
  };
719
+ simulateGapReduction(payload: {
720
+ factor: number;
721
+ kind: "long" | "short";
722
+ sell_factor?: number;
723
+ }): {
724
+ results: {
725
+ profit_percent: {
726
+ long: number;
727
+ short: number;
728
+ };
729
+ risk: {
730
+ short: number;
731
+ long: number;
732
+ };
733
+ take_profit: {
734
+ long: number;
735
+ short: number;
736
+ };
737
+ sell_quantity: {
738
+ short: number;
739
+ long: number;
740
+ };
741
+ gap_loss: number;
742
+ position: {
743
+ long: {
744
+ entry: number;
745
+ quantity: number;
746
+ };
747
+ short: {
748
+ entry: number;
749
+ quantity: number;
750
+ };
751
+ };
752
+ }[];
753
+ quantity: number;
754
+ counter: number;
755
+ };
719
756
  }
720
757
 
721
758
  export {};
@@ -2291,6 +2291,61 @@ class Strategy {
2291
2291
  });
2292
2292
  return result;
2293
2293
  }
2294
+ simulateGapReduction(payload) {
2295
+ const { factor, kind, sell_factor = 1 } = payload;
2296
+ const results = [];
2297
+ let params = {
2298
+ long: this.position.long,
2299
+ short: this.position.short,
2300
+ config: this.config
2301
+ };
2302
+ let counter = 1;
2303
+ while (true) {
2304
+ const instance = new Strategy(params);
2305
+ const { profit_percent, risk, take_profit, sell_quantity, gap_loss } = instance.identifyGapConfig({
2306
+ factor,
2307
+ sell_factor
2308
+ });
2309
+ const to_add = {
2310
+ profit_percent,
2311
+ risk,
2312
+ take_profit,
2313
+ sell_quantity,
2314
+ gap_loss,
2315
+ position: {
2316
+ long: {
2317
+ entry: this.to_f(params.long.entry),
2318
+ quantity: this.to_df(params.long.quantity)
2319
+ },
2320
+ short: {
2321
+ entry: this.to_f(params.short.entry),
2322
+ quantity: this.to_df(params.short.quantity)
2323
+ }
2324
+ }
2325
+ };
2326
+ results.push(to_add);
2327
+ const sell_kind = kind == "long" ? "short" : "long";
2328
+ const remaining = this.to_df(params[sell_kind].quantity - sell_quantity[sell_kind]);
2329
+ if (remaining <= 0) {
2330
+ break;
2331
+ }
2332
+ params[sell_kind].quantity = remaining;
2333
+ params[kind] = {
2334
+ entry: take_profit[kind],
2335
+ quantity: remaining
2336
+ };
2337
+ counter++;
2338
+ }
2339
+ const last_gap_loss = results.at(-1)?.gap_loss;
2340
+ const last_tp = results.at(-1)?.take_profit[kind];
2341
+ const entry = this.position[kind].entry;
2342
+ const quantity = this.to_df(Math.abs(last_tp - entry) / last_gap_loss);
2343
+ return {
2344
+ results,
2345
+ quantity,
2346
+ counter
2347
+ };
2348
+ }
2294
2349
  }
2295
2350
  export {
2296
2351
  to_f,
package/dist/index.cjs CHANGED
@@ -54303,6 +54303,61 @@ class Strategy {
54303
54303
  });
54304
54304
  return result;
54305
54305
  }
54306
+ simulateGapReduction(payload) {
54307
+ const { factor, kind, sell_factor = 1 } = payload;
54308
+ const results = [];
54309
+ let params = {
54310
+ long: this.position.long,
54311
+ short: this.position.short,
54312
+ config: this.config
54313
+ };
54314
+ let counter = 1;
54315
+ while (true) {
54316
+ const instance = new Strategy(params);
54317
+ const { profit_percent, risk, take_profit, sell_quantity, gap_loss } = instance.identifyGapConfig({
54318
+ factor,
54319
+ sell_factor
54320
+ });
54321
+ const to_add = {
54322
+ profit_percent,
54323
+ risk,
54324
+ take_profit,
54325
+ sell_quantity,
54326
+ gap_loss,
54327
+ position: {
54328
+ long: {
54329
+ entry: this.to_f(params.long.entry),
54330
+ quantity: this.to_df(params.long.quantity)
54331
+ },
54332
+ short: {
54333
+ entry: this.to_f(params.short.entry),
54334
+ quantity: this.to_df(params.short.quantity)
54335
+ }
54336
+ }
54337
+ };
54338
+ results.push(to_add);
54339
+ const sell_kind = kind == "long" ? "short" : "long";
54340
+ const remaining = this.to_df(params[sell_kind].quantity - sell_quantity[sell_kind]);
54341
+ if (remaining <= 0) {
54342
+ break;
54343
+ }
54344
+ params[sell_kind].quantity = remaining;
54345
+ params[kind] = {
54346
+ entry: take_profit[kind],
54347
+ quantity: remaining
54348
+ };
54349
+ counter++;
54350
+ }
54351
+ const last_gap_loss = results.at(-1)?.gap_loss;
54352
+ const last_tp = results.at(-1)?.take_profit[kind];
54353
+ const entry = this.position[kind].entry;
54354
+ const quantity = this.to_df(Math.abs(last_tp - entry) / last_gap_loss);
54355
+ return {
54356
+ results,
54357
+ quantity,
54358
+ counter
54359
+ };
54360
+ }
54306
54361
  }
54307
54362
 
54308
54363
  // src/exchanges/binance.ts
@@ -58199,19 +58254,24 @@ class ExchangeAccount {
58199
58254
  kind,
58200
58255
  raw: true
58201
58256
  });
58202
- const result = strategy.generateOppositeTrades({
58203
- kind,
58204
- avg_entry: strategy.position[kind].avg_price
58205
- });
58206
- if (place && result?.kind) {
58207
- const _symbol = place_symbol || symbol;
58208
- await this.placeOppositeTradeAction({
58209
- symbol: _symbol,
58210
- kind: result.kind,
58211
- data: result
58212
- });
58257
+ try {
58258
+ const result = strategy.generateOppositeTrades({
58259
+ kind,
58260
+ avg_entry: strategy.position[kind].avg_price
58261
+ });
58262
+ if (place && result?.kind) {
58263
+ const _symbol = place_symbol || symbol;
58264
+ await this.placeOppositeTradeAction({
58265
+ symbol: _symbol,
58266
+ kind: result.kind,
58267
+ data: result
58268
+ });
58269
+ }
58270
+ return result;
58271
+ } catch (error) {
58272
+ console.log("Error in buildOppositeTrades", error);
58273
+ return null;
58213
58274
  }
58214
- return result;
58215
58275
  }
58216
58276
  async runSimulation(payload) {
58217
58277
  const { symbol, kind, iterations = 2, raw = false } = payload;
@@ -59056,6 +59116,9 @@ class ExchangeAccount {
59056
59116
  symbol,
59057
59117
  kind
59058
59118
  });
59119
+ if (!reverse_action) {
59120
+ return;
59121
+ }
59059
59122
  console.log("Updating config for ", symbol, reverse_action.kind);
59060
59123
  await this.getPositionConfig({
59061
59124
  symbol,
package/dist/index.d.ts CHANGED
@@ -805,6 +805,43 @@ export declare class Strategy {
805
805
  price_places: string;
806
806
  decimal_places: string;
807
807
  };
808
+ simulateGapReduction(payload: {
809
+ factor: number;
810
+ kind: "long" | "short";
811
+ sell_factor?: number;
812
+ }): {
813
+ results: {
814
+ profit_percent: {
815
+ long: number;
816
+ short: number;
817
+ };
818
+ risk: {
819
+ short: number;
820
+ long: number;
821
+ };
822
+ take_profit: {
823
+ long: number;
824
+ short: number;
825
+ };
826
+ sell_quantity: {
827
+ short: number;
828
+ long: number;
829
+ };
830
+ gap_loss: number;
831
+ position: {
832
+ long: {
833
+ entry: number;
834
+ quantity: number;
835
+ };
836
+ short: {
837
+ entry: number;
838
+ quantity: number;
839
+ };
840
+ };
841
+ }[];
842
+ quantity: number;
843
+ counter: number;
844
+ };
808
845
  }
809
846
  export type SignalConfigType = {
810
847
  focus: number;
package/dist/index.js CHANGED
@@ -54252,6 +54252,61 @@ class Strategy {
54252
54252
  });
54253
54253
  return result;
54254
54254
  }
54255
+ simulateGapReduction(payload) {
54256
+ const { factor, kind, sell_factor = 1 } = payload;
54257
+ const results = [];
54258
+ let params = {
54259
+ long: this.position.long,
54260
+ short: this.position.short,
54261
+ config: this.config
54262
+ };
54263
+ let counter = 1;
54264
+ while (true) {
54265
+ const instance = new Strategy(params);
54266
+ const { profit_percent, risk, take_profit, sell_quantity, gap_loss } = instance.identifyGapConfig({
54267
+ factor,
54268
+ sell_factor
54269
+ });
54270
+ const to_add = {
54271
+ profit_percent,
54272
+ risk,
54273
+ take_profit,
54274
+ sell_quantity,
54275
+ gap_loss,
54276
+ position: {
54277
+ long: {
54278
+ entry: this.to_f(params.long.entry),
54279
+ quantity: this.to_df(params.long.quantity)
54280
+ },
54281
+ short: {
54282
+ entry: this.to_f(params.short.entry),
54283
+ quantity: this.to_df(params.short.quantity)
54284
+ }
54285
+ }
54286
+ };
54287
+ results.push(to_add);
54288
+ const sell_kind = kind == "long" ? "short" : "long";
54289
+ const remaining = this.to_df(params[sell_kind].quantity - sell_quantity[sell_kind]);
54290
+ if (remaining <= 0) {
54291
+ break;
54292
+ }
54293
+ params[sell_kind].quantity = remaining;
54294
+ params[kind] = {
54295
+ entry: take_profit[kind],
54296
+ quantity: remaining
54297
+ };
54298
+ counter++;
54299
+ }
54300
+ const last_gap_loss = results.at(-1)?.gap_loss;
54301
+ const last_tp = results.at(-1)?.take_profit[kind];
54302
+ const entry = this.position[kind].entry;
54303
+ const quantity = this.to_df(Math.abs(last_tp - entry) / last_gap_loss);
54304
+ return {
54305
+ results,
54306
+ quantity,
54307
+ counter
54308
+ };
54309
+ }
54255
54310
  }
54256
54311
 
54257
54312
  // src/exchanges/binance.ts
@@ -58148,19 +58203,24 @@ class ExchangeAccount {
58148
58203
  kind,
58149
58204
  raw: true
58150
58205
  });
58151
- const result = strategy.generateOppositeTrades({
58152
- kind,
58153
- avg_entry: strategy.position[kind].avg_price
58154
- });
58155
- if (place && result?.kind) {
58156
- const _symbol = place_symbol || symbol;
58157
- await this.placeOppositeTradeAction({
58158
- symbol: _symbol,
58159
- kind: result.kind,
58160
- data: result
58161
- });
58206
+ try {
58207
+ const result = strategy.generateOppositeTrades({
58208
+ kind,
58209
+ avg_entry: strategy.position[kind].avg_price
58210
+ });
58211
+ if (place && result?.kind) {
58212
+ const _symbol = place_symbol || symbol;
58213
+ await this.placeOppositeTradeAction({
58214
+ symbol: _symbol,
58215
+ kind: result.kind,
58216
+ data: result
58217
+ });
58218
+ }
58219
+ return result;
58220
+ } catch (error) {
58221
+ console.log("Error in buildOppositeTrades", error);
58222
+ return null;
58162
58223
  }
58163
- return result;
58164
58224
  }
58165
58225
  async runSimulation(payload) {
58166
58226
  const { symbol, kind, iterations = 2, raw = false } = payload;
@@ -59005,6 +59065,9 @@ class ExchangeAccount {
59005
59065
  symbol,
59006
59066
  kind
59007
59067
  });
59068
+ if (!reverse_action) {
59069
+ return;
59070
+ }
59008
59071
  console.log("Updating config for ", symbol, reverse_action.kind);
59009
59072
  await this.getPositionConfig({
59010
59073
  symbol,
@@ -60990,6 +60990,61 @@ class Strategy {
60990
60990
  });
60991
60991
  return result;
60992
60992
  }
60993
+ simulateGapReduction(payload) {
60994
+ const { factor, kind, sell_factor = 1 } = payload;
60995
+ const results = [];
60996
+ let params = {
60997
+ long: this.position.long,
60998
+ short: this.position.short,
60999
+ config: this.config
61000
+ };
61001
+ let counter = 1;
61002
+ while (true) {
61003
+ const instance = new Strategy(params);
61004
+ const { profit_percent, risk, take_profit, sell_quantity, gap_loss } = instance.identifyGapConfig({
61005
+ factor,
61006
+ sell_factor
61007
+ });
61008
+ const to_add = {
61009
+ profit_percent,
61010
+ risk,
61011
+ take_profit,
61012
+ sell_quantity,
61013
+ gap_loss,
61014
+ position: {
61015
+ long: {
61016
+ entry: this.to_f(params.long.entry),
61017
+ quantity: this.to_df(params.long.quantity)
61018
+ },
61019
+ short: {
61020
+ entry: this.to_f(params.short.entry),
61021
+ quantity: this.to_df(params.short.quantity)
61022
+ }
61023
+ }
61024
+ };
61025
+ results.push(to_add);
61026
+ const sell_kind = kind == "long" ? "short" : "long";
61027
+ const remaining = this.to_df(params[sell_kind].quantity - sell_quantity[sell_kind]);
61028
+ if (remaining <= 0) {
61029
+ break;
61030
+ }
61031
+ params[sell_kind].quantity = remaining;
61032
+ params[kind] = {
61033
+ entry: take_profit[kind],
61034
+ quantity: remaining
61035
+ };
61036
+ counter++;
61037
+ }
61038
+ const last_gap_loss = results.at(-1)?.gap_loss;
61039
+ const last_tp = results.at(-1)?.take_profit[kind];
61040
+ const entry = this.position[kind].entry;
61041
+ const quantity = this.to_df(Math.abs(last_tp - entry) / last_gap_loss);
61042
+ return {
61043
+ results,
61044
+ quantity,
61045
+ counter
61046
+ };
61047
+ }
60993
61048
  }
60994
61049
 
60995
61050
  // src/exchanges/binance.ts
@@ -64886,19 +64941,24 @@ class ExchangeAccount {
64886
64941
  kind,
64887
64942
  raw: true
64888
64943
  });
64889
- const result = strategy.generateOppositeTrades({
64890
- kind,
64891
- avg_entry: strategy.position[kind].avg_price
64892
- });
64893
- if (place && result?.kind) {
64894
- const _symbol = place_symbol || symbol;
64895
- await this.placeOppositeTradeAction({
64896
- symbol: _symbol,
64897
- kind: result.kind,
64898
- data: result
64899
- });
64944
+ try {
64945
+ const result = strategy.generateOppositeTrades({
64946
+ kind,
64947
+ avg_entry: strategy.position[kind].avg_price
64948
+ });
64949
+ if (place && result?.kind) {
64950
+ const _symbol = place_symbol || symbol;
64951
+ await this.placeOppositeTradeAction({
64952
+ symbol: _symbol,
64953
+ kind: result.kind,
64954
+ data: result
64955
+ });
64956
+ }
64957
+ return result;
64958
+ } catch (error) {
64959
+ console.log("Error in buildOppositeTrades", error);
64960
+ return null;
64900
64961
  }
64901
- return result;
64902
64962
  }
64903
64963
  async runSimulation(payload) {
64904
64964
  const { symbol, kind, iterations = 2, raw = false } = payload;
@@ -65743,6 +65803,9 @@ class ExchangeAccount {
65743
65803
  symbol,
65744
65804
  kind
65745
65805
  });
65806
+ if (!reverse_action) {
65807
+ return;
65808
+ }
65746
65809
  console.log("Updating config for ", symbol, reverse_action.kind);
65747
65810
  await this.getPositionConfig({
65748
65811
  symbol,
@@ -60963,6 +60963,61 @@ class Strategy {
60963
60963
  });
60964
60964
  return result;
60965
60965
  }
60966
+ simulateGapReduction(payload) {
60967
+ const { factor, kind, sell_factor = 1 } = payload;
60968
+ const results = [];
60969
+ let params = {
60970
+ long: this.position.long,
60971
+ short: this.position.short,
60972
+ config: this.config
60973
+ };
60974
+ let counter = 1;
60975
+ while (true) {
60976
+ const instance = new Strategy(params);
60977
+ const { profit_percent, risk, take_profit, sell_quantity, gap_loss } = instance.identifyGapConfig({
60978
+ factor,
60979
+ sell_factor
60980
+ });
60981
+ const to_add = {
60982
+ profit_percent,
60983
+ risk,
60984
+ take_profit,
60985
+ sell_quantity,
60986
+ gap_loss,
60987
+ position: {
60988
+ long: {
60989
+ entry: this.to_f(params.long.entry),
60990
+ quantity: this.to_df(params.long.quantity)
60991
+ },
60992
+ short: {
60993
+ entry: this.to_f(params.short.entry),
60994
+ quantity: this.to_df(params.short.quantity)
60995
+ }
60996
+ }
60997
+ };
60998
+ results.push(to_add);
60999
+ const sell_kind = kind == "long" ? "short" : "long";
61000
+ const remaining = this.to_df(params[sell_kind].quantity - sell_quantity[sell_kind]);
61001
+ if (remaining <= 0) {
61002
+ break;
61003
+ }
61004
+ params[sell_kind].quantity = remaining;
61005
+ params[kind] = {
61006
+ entry: take_profit[kind],
61007
+ quantity: remaining
61008
+ };
61009
+ counter++;
61010
+ }
61011
+ const last_gap_loss = results.at(-1)?.gap_loss;
61012
+ const last_tp = results.at(-1)?.take_profit[kind];
61013
+ const entry = this.position[kind].entry;
61014
+ const quantity = this.to_df(Math.abs(last_tp - entry) / last_gap_loss);
61015
+ return {
61016
+ results,
61017
+ quantity,
61018
+ counter
61019
+ };
61020
+ }
60966
61021
  }
60967
61022
 
60968
61023
  // src/exchanges/binance.ts
@@ -64859,19 +64914,24 @@ class ExchangeAccount {
64859
64914
  kind,
64860
64915
  raw: true
64861
64916
  });
64862
- const result = strategy.generateOppositeTrades({
64863
- kind,
64864
- avg_entry: strategy.position[kind].avg_price
64865
- });
64866
- if (place && result?.kind) {
64867
- const _symbol = place_symbol || symbol;
64868
- await this.placeOppositeTradeAction({
64869
- symbol: _symbol,
64870
- kind: result.kind,
64871
- data: result
64872
- });
64917
+ try {
64918
+ const result = strategy.generateOppositeTrades({
64919
+ kind,
64920
+ avg_entry: strategy.position[kind].avg_price
64921
+ });
64922
+ if (place && result?.kind) {
64923
+ const _symbol = place_symbol || symbol;
64924
+ await this.placeOppositeTradeAction({
64925
+ symbol: _symbol,
64926
+ kind: result.kind,
64927
+ data: result
64928
+ });
64929
+ }
64930
+ return result;
64931
+ } catch (error) {
64932
+ console.log("Error in buildOppositeTrades", error);
64933
+ return null;
64873
64934
  }
64874
- return result;
64875
64935
  }
64876
64936
  async runSimulation(payload) {
64877
64937
  const { symbol, kind, iterations = 2, raw = false } = payload;
@@ -65716,6 +65776,9 @@ class ExchangeAccount {
65716
65776
  symbol,
65717
65777
  kind
65718
65778
  });
65779
+ if (!reverse_action) {
65780
+ return;
65781
+ }
65719
65782
  console.log("Updating config for ", symbol, reverse_action.kind);
65720
65783
  await this.getPositionConfig({
65721
65784
  symbol,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-100",
4
+ "version": "0.0.2-101",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",