@gbozee/ultimate 0.0.2-158 → 0.0.2-159

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.
@@ -328,6 +328,20 @@ export interface ScheduledTrade extends BaseSystemFields {
328
328
  kelly_prediction_model?: "exponential" | "normal" | "uniform";
329
329
  };
330
330
  }
331
+ export interface AccountStrategy extends BaseSystemFields {
332
+ account: string;
333
+ symbol: string;
334
+ risk?: number;
335
+ reward_factor?: number;
336
+ kind?: "long" | "short";
337
+ support?: number;
338
+ resistance?: number;
339
+ running?: boolean;
340
+ max_reward_factor?: number;
341
+ follow?: boolean;
342
+ risk_reward?: number;
343
+ dynamic?: boolean;
344
+ }
331
345
  interface Proxy$1 extends BaseSystemFields {
332
346
  ip_address?: string;
333
347
  type?: "http" | "socks5";
@@ -371,6 +385,7 @@ export interface PositionsView {
371
385
  p_account?: ExchangeAccount;
372
386
  b_config?: ScheduledTrade;
373
387
  proxy?: Proxy$1;
388
+ account_strategy?: AccountStrategy;
374
389
  };
375
390
  }
376
391
  export type AppConfig = {
package/dist/index.cjs CHANGED
@@ -55167,9 +55167,9 @@ class AppDatabase {
55167
55167
  }
55168
55168
  return null;
55169
55169
  }
55170
- async getRunningAccountStrategies() {
55170
+ async getRunningAccountStrategies(filter = "running=true") {
55171
55171
  const result = await this.pb.collection("account_strategies").getFullList({
55172
- filter: `running=true`,
55172
+ filter,
55173
55173
  expand: "account"
55174
55174
  });
55175
55175
  return result;
@@ -60922,7 +60922,14 @@ class ExchangePosition {
60922
60922
  place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
60923
60923
  profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
60924
60924
  };
60925
- return await this.app_db.createOrUpdatePositionConfig(this.instance, params);
60925
+ return await this.app_db.createOrUpdatePositionConfig({
60926
+ ...this.instance,
60927
+ expand: {
60928
+ ...this.instance.expand || {},
60929
+ account: this.account
60930
+ },
60931
+ account: this.account.id
60932
+ }, params);
60926
60933
  }
60927
60934
  }
60928
60935
  if (this.instance.expand?.b_config) {
@@ -61701,8 +61708,8 @@ class ExchangePosition {
61701
61708
  });
61702
61709
  return this.getConfig({
61703
61710
  params: {
61704
- entry: config2.entry,
61705
- stop: config2.stop,
61711
+ entry: long_c.entry,
61712
+ stop: long_c.stop,
61706
61713
  risk_reward: long_c.risk_reward,
61707
61714
  risk: long_c.risk
61708
61715
  }
@@ -63166,6 +63173,53 @@ class ExchangeAccount {
63166
63173
  short_percent
63167
63174
  };
63168
63175
  }
63176
+ async oppositeGapExists(payload) {
63177
+ const focus_position = await this.getFocusPosition({
63178
+ symbol: payload.symbol,
63179
+ kind: payload.kind
63180
+ });
63181
+ const strategy2 = focus_position.getInstance().expand?.account_strategy;
63182
+ if (!strategy2) {
63183
+ return;
63184
+ }
63185
+ const kind = strategy2.kind;
63186
+ const reward_factor = strategy2.reward_factor;
63187
+ const { symbol } = payload;
63188
+ const reversePosition = await this.getFocusPosition({
63189
+ symbol,
63190
+ kind: kind === "long" ? "short" : "long"
63191
+ });
63192
+ if (focus_position.getInstance().quantity > 0) {
63193
+ const opposite_config = focus_position.getOppositeConfig({
63194
+ ratio: reward_factor
63195
+ });
63196
+ const reverse_config = await reversePosition.getConfig();
63197
+ if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
63198
+ console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
63199
+ await reversePosition.getConfig({
63200
+ params: {
63201
+ entry: opposite_config.entry,
63202
+ stop: opposite_config.stop,
63203
+ risk: opposite_config.risk,
63204
+ risk_reward: opposite_config.risk_reward
63205
+ }
63206
+ });
63207
+ console.log("Placing trade for ", symbol, reversePosition.kind);
63208
+ await reversePosition.placeTrade({
63209
+ ignore_config: true,
63210
+ limit: true,
63211
+ place: true
63212
+ });
63213
+ }
63214
+ console.log("Opposite config for ", symbol, kind, opposite_config);
63215
+ } else {
63216
+ if (focus_position.getInstance().avg_qty > 0 && strategy2.running === false) {
63217
+ await focus_position.cancelOrders({
63218
+ limit: true
63219
+ });
63220
+ }
63221
+ }
63222
+ }
63169
63223
  async profitWithinGapStrategy(payload) {
63170
63224
  const { symbol } = payload;
63171
63225
  console.log("Fetching positions for ", symbol);
@@ -63182,7 +63236,6 @@ class ExchangeAccount {
63182
63236
  return;
63183
63237
  }
63184
63238
  const kind = strategy2.kind;
63185
- const reward_factor = strategy2.reward_factor;
63186
63239
  const { entries, last_value, ...app_config } = await this.tradeConfig({
63187
63240
  symbol,
63188
63241
  kind
@@ -63210,34 +63263,10 @@ class ExchangeAccount {
63210
63263
  });
63211
63264
  }
63212
63265
  console.log("Checking if focus position has quantity for ", symbol, kind);
63213
- const reversePosition = await this.getFocusPosition({
63266
+ await this.oppositeGapExists({
63214
63267
  symbol,
63215
- kind: kind === "long" ? "short" : "long"
63268
+ kind
63216
63269
  });
63217
- if (focusPosition.getInstance().quantity > 0) {
63218
- const opposite_config = focusPosition.getOppositeConfig({
63219
- ratio: reward_factor
63220
- });
63221
- const reverse_config = await reversePosition.getConfig();
63222
- if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focusPosition.getInstance().quantity > 0) {
63223
- console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
63224
- await reversePosition.getConfig({
63225
- params: {
63226
- entry: opposite_config.entry,
63227
- stop: opposite_config.stop,
63228
- risk: opposite_config.risk,
63229
- risk_reward: opposite_config.risk_reward
63230
- }
63231
- });
63232
- console.log("Placing trade for ", symbol, reversePosition.kind);
63233
- await reversePosition.placeTrade({
63234
- ignore_config: true,
63235
- limit: true,
63236
- place: true
63237
- });
63238
- }
63239
- console.log("Opposite config for ", symbol, kind, opposite_config);
63240
- }
63241
63270
  return {
63242
63271
  config_details: {
63243
63272
  app_config,
@@ -63702,15 +63731,25 @@ class App {
63702
63731
  });
63703
63732
  return result;
63704
63733
  }
63705
- async runDbStrategyAccounts(callback) {
63734
+ async runDbStrategyAccounts(payload) {
63735
+ const { runningCallback, notRunningCallback } = payload;
63706
63736
  const strategies = await this.app_db.getRunningAccountStrategies();
63707
63737
  for (const strategy2 of strategies) {
63708
63738
  console.log("Running strategy for ", strategy2.symbol, "for account", strategy2.expand.account.owner, strategy2.expand.account.exchange);
63709
- await callback({
63739
+ await runningCallback({
63710
63740
  symbol: strategy2.symbol,
63711
63741
  account: strategy2.expand.account
63712
63742
  });
63713
63743
  }
63744
+ const not_running_strategies = await this.app_db.getRunningAccountStrategies("running=false");
63745
+ for (const strategy2 of not_running_strategies) {
63746
+ console.log("Not running strategy for ", strategy2.symbol);
63747
+ await notRunningCallback({
63748
+ symbol: strategy2.symbol,
63749
+ account: strategy2.expand.account,
63750
+ kind: strategy2.kind
63751
+ });
63752
+ }
63714
63753
  }
63715
63754
  async profitWithinGapStrategy(payload) {
63716
63755
  const { account, symbol } = payload;
package/dist/index.d.ts CHANGED
@@ -141,6 +141,7 @@ export interface PositionsView {
141
141
  p_account?: ExchangeAccount;
142
142
  b_config?: ScheduledTrade;
143
143
  proxy?: Proxy$1;
144
+ account_strategy?: AccountStrategy;
144
145
  };
145
146
  }
146
147
  export interface BullishMarket extends RecordModel {
@@ -739,7 +740,7 @@ export declare class AppDatabase {
739
740
  kind: "long" | "short";
740
741
  account: ExchangeType;
741
742
  }): Promise<ScheduledTrade | null>;
742
- getRunningAccountStrategies(): Promise<(AccountStrategy & {
743
+ getRunningAccountStrategies(filter?: string): Promise<(AccountStrategy & {
743
744
  expand?: {
744
745
  account: ExchangeAccount;
745
746
  };
@@ -2570,6 +2571,10 @@ declare class ExchangeAccount$1 {
2570
2571
  long_percent: number;
2571
2572
  short_percent: number;
2572
2573
  }>;
2574
+ oppositeGapExists(payload: {
2575
+ symbol: string;
2576
+ kind: "long" | "short";
2577
+ }): Promise<void>;
2573
2578
  profitWithinGapStrategy(payload: {
2574
2579
  symbol: string;
2575
2580
  }): Promise<{
@@ -2817,10 +2822,17 @@ declare class App {
2817
2822
  cancel?: boolean;
2818
2823
  raw?: boolean;
2819
2824
  }): Promise<any>;
2820
- runDbStrategyAccounts(callback: (params: {
2821
- symbol: string;
2822
- account: ExchangeType;
2823
- }) => Promise<any>): Promise<void>;
2825
+ runDbStrategyAccounts(payload: {
2826
+ runningCallback: (params: {
2827
+ symbol: string;
2828
+ account: ExchangeType;
2829
+ }) => Promise<any>;
2830
+ notRunningCallback: (params: {
2831
+ symbol: string;
2832
+ account: ExchangeType;
2833
+ kind: "long" | "short";
2834
+ }) => Promise<any>;
2835
+ }): Promise<void>;
2824
2836
  profitWithinGapStrategy(payload: {
2825
2837
  account: ExchangeType;
2826
2838
  symbol: string;
package/dist/index.js CHANGED
@@ -55113,9 +55113,9 @@ class AppDatabase {
55113
55113
  }
55114
55114
  return null;
55115
55115
  }
55116
- async getRunningAccountStrategies() {
55116
+ async getRunningAccountStrategies(filter = "running=true") {
55117
55117
  const result = await this.pb.collection("account_strategies").getFullList({
55118
- filter: `running=true`,
55118
+ filter,
55119
55119
  expand: "account"
55120
55120
  });
55121
55121
  return result;
@@ -60868,7 +60868,14 @@ class ExchangePosition {
60868
60868
  place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
60869
60869
  profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
60870
60870
  };
60871
- return await this.app_db.createOrUpdatePositionConfig(this.instance, params);
60871
+ return await this.app_db.createOrUpdatePositionConfig({
60872
+ ...this.instance,
60873
+ expand: {
60874
+ ...this.instance.expand || {},
60875
+ account: this.account
60876
+ },
60877
+ account: this.account.id
60878
+ }, params);
60872
60879
  }
60873
60880
  }
60874
60881
  if (this.instance.expand?.b_config) {
@@ -61647,8 +61654,8 @@ class ExchangePosition {
61647
61654
  });
61648
61655
  return this.getConfig({
61649
61656
  params: {
61650
- entry: config2.entry,
61651
- stop: config2.stop,
61657
+ entry: long_c.entry,
61658
+ stop: long_c.stop,
61652
61659
  risk_reward: long_c.risk_reward,
61653
61660
  risk: long_c.risk
61654
61661
  }
@@ -63112,6 +63119,53 @@ class ExchangeAccount {
63112
63119
  short_percent
63113
63120
  };
63114
63121
  }
63122
+ async oppositeGapExists(payload) {
63123
+ const focus_position = await this.getFocusPosition({
63124
+ symbol: payload.symbol,
63125
+ kind: payload.kind
63126
+ });
63127
+ const strategy2 = focus_position.getInstance().expand?.account_strategy;
63128
+ if (!strategy2) {
63129
+ return;
63130
+ }
63131
+ const kind = strategy2.kind;
63132
+ const reward_factor = strategy2.reward_factor;
63133
+ const { symbol } = payload;
63134
+ const reversePosition = await this.getFocusPosition({
63135
+ symbol,
63136
+ kind: kind === "long" ? "short" : "long"
63137
+ });
63138
+ if (focus_position.getInstance().quantity > 0) {
63139
+ const opposite_config = focus_position.getOppositeConfig({
63140
+ ratio: reward_factor
63141
+ });
63142
+ const reverse_config = await reversePosition.getConfig();
63143
+ if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
63144
+ console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
63145
+ await reversePosition.getConfig({
63146
+ params: {
63147
+ entry: opposite_config.entry,
63148
+ stop: opposite_config.stop,
63149
+ risk: opposite_config.risk,
63150
+ risk_reward: opposite_config.risk_reward
63151
+ }
63152
+ });
63153
+ console.log("Placing trade for ", symbol, reversePosition.kind);
63154
+ await reversePosition.placeTrade({
63155
+ ignore_config: true,
63156
+ limit: true,
63157
+ place: true
63158
+ });
63159
+ }
63160
+ console.log("Opposite config for ", symbol, kind, opposite_config);
63161
+ } else {
63162
+ if (focus_position.getInstance().avg_qty > 0 && strategy2.running === false) {
63163
+ await focus_position.cancelOrders({
63164
+ limit: true
63165
+ });
63166
+ }
63167
+ }
63168
+ }
63115
63169
  async profitWithinGapStrategy(payload) {
63116
63170
  const { symbol } = payload;
63117
63171
  console.log("Fetching positions for ", symbol);
@@ -63128,7 +63182,6 @@ class ExchangeAccount {
63128
63182
  return;
63129
63183
  }
63130
63184
  const kind = strategy2.kind;
63131
- const reward_factor = strategy2.reward_factor;
63132
63185
  const { entries, last_value, ...app_config } = await this.tradeConfig({
63133
63186
  symbol,
63134
63187
  kind
@@ -63156,34 +63209,10 @@ class ExchangeAccount {
63156
63209
  });
63157
63210
  }
63158
63211
  console.log("Checking if focus position has quantity for ", symbol, kind);
63159
- const reversePosition = await this.getFocusPosition({
63212
+ await this.oppositeGapExists({
63160
63213
  symbol,
63161
- kind: kind === "long" ? "short" : "long"
63214
+ kind
63162
63215
  });
63163
- if (focusPosition.getInstance().quantity > 0) {
63164
- const opposite_config = focusPosition.getOppositeConfig({
63165
- ratio: reward_factor
63166
- });
63167
- const reverse_config = await reversePosition.getConfig();
63168
- if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focusPosition.getInstance().quantity > 0) {
63169
- console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
63170
- await reversePosition.getConfig({
63171
- params: {
63172
- entry: opposite_config.entry,
63173
- stop: opposite_config.stop,
63174
- risk: opposite_config.risk,
63175
- risk_reward: opposite_config.risk_reward
63176
- }
63177
- });
63178
- console.log("Placing trade for ", symbol, reversePosition.kind);
63179
- await reversePosition.placeTrade({
63180
- ignore_config: true,
63181
- limit: true,
63182
- place: true
63183
- });
63184
- }
63185
- console.log("Opposite config for ", symbol, kind, opposite_config);
63186
- }
63187
63216
  return {
63188
63217
  config_details: {
63189
63218
  app_config,
@@ -63648,15 +63677,25 @@ class App {
63648
63677
  });
63649
63678
  return result;
63650
63679
  }
63651
- async runDbStrategyAccounts(callback) {
63680
+ async runDbStrategyAccounts(payload) {
63681
+ const { runningCallback, notRunningCallback } = payload;
63652
63682
  const strategies = await this.app_db.getRunningAccountStrategies();
63653
63683
  for (const strategy2 of strategies) {
63654
63684
  console.log("Running strategy for ", strategy2.symbol, "for account", strategy2.expand.account.owner, strategy2.expand.account.exchange);
63655
- await callback({
63685
+ await runningCallback({
63656
63686
  symbol: strategy2.symbol,
63657
63687
  account: strategy2.expand.account
63658
63688
  });
63659
63689
  }
63690
+ const not_running_strategies = await this.app_db.getRunningAccountStrategies("running=false");
63691
+ for (const strategy2 of not_running_strategies) {
63692
+ console.log("Not running strategy for ", strategy2.symbol);
63693
+ await notRunningCallback({
63694
+ symbol: strategy2.symbol,
63695
+ account: strategy2.expand.account,
63696
+ kind: strategy2.kind
63697
+ });
63698
+ }
63660
63699
  }
63661
63700
  async profitWithinGapStrategy(payload) {
63662
63701
  const { account, symbol } = payload;
@@ -61867,9 +61867,9 @@ class AppDatabase {
61867
61867
  }
61868
61868
  return null;
61869
61869
  }
61870
- async getRunningAccountStrategies() {
61870
+ async getRunningAccountStrategies(filter = "running=true") {
61871
61871
  const result = await this.pb.collection("account_strategies").getFullList({
61872
- filter: `running=true`,
61872
+ filter,
61873
61873
  expand: "account"
61874
61874
  });
61875
61875
  return result;
@@ -67596,7 +67596,14 @@ class ExchangePosition {
67596
67596
  place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
67597
67597
  profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
67598
67598
  };
67599
- return await this.app_db.createOrUpdatePositionConfig(this.instance, params);
67599
+ return await this.app_db.createOrUpdatePositionConfig({
67600
+ ...this.instance,
67601
+ expand: {
67602
+ ...this.instance.expand || {},
67603
+ account: this.account
67604
+ },
67605
+ account: this.account.id
67606
+ }, params);
67600
67607
  }
67601
67608
  }
67602
67609
  if (this.instance.expand?.b_config) {
@@ -68375,8 +68382,8 @@ class ExchangePosition {
68375
68382
  });
68376
68383
  return this.getConfig({
68377
68384
  params: {
68378
- entry: config2.entry,
68379
- stop: config2.stop,
68385
+ entry: long_c.entry,
68386
+ stop: long_c.stop,
68380
68387
  risk_reward: long_c.risk_reward,
68381
68388
  risk: long_c.risk
68382
68389
  }
@@ -69840,6 +69847,53 @@ class ExchangeAccount {
69840
69847
  short_percent
69841
69848
  };
69842
69849
  }
69850
+ async oppositeGapExists(payload) {
69851
+ const focus_position = await this.getFocusPosition({
69852
+ symbol: payload.symbol,
69853
+ kind: payload.kind
69854
+ });
69855
+ const strategy2 = focus_position.getInstance().expand?.account_strategy;
69856
+ if (!strategy2) {
69857
+ return;
69858
+ }
69859
+ const kind = strategy2.kind;
69860
+ const reward_factor = strategy2.reward_factor;
69861
+ const { symbol } = payload;
69862
+ const reversePosition = await this.getFocusPosition({
69863
+ symbol,
69864
+ kind: kind === "long" ? "short" : "long"
69865
+ });
69866
+ if (focus_position.getInstance().quantity > 0) {
69867
+ const opposite_config = focus_position.getOppositeConfig({
69868
+ ratio: reward_factor
69869
+ });
69870
+ const reverse_config = await reversePosition.getConfig();
69871
+ if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
69872
+ console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
69873
+ await reversePosition.getConfig({
69874
+ params: {
69875
+ entry: opposite_config.entry,
69876
+ stop: opposite_config.stop,
69877
+ risk: opposite_config.risk,
69878
+ risk_reward: opposite_config.risk_reward
69879
+ }
69880
+ });
69881
+ console.log("Placing trade for ", symbol, reversePosition.kind);
69882
+ await reversePosition.placeTrade({
69883
+ ignore_config: true,
69884
+ limit: true,
69885
+ place: true
69886
+ });
69887
+ }
69888
+ console.log("Opposite config for ", symbol, kind, opposite_config);
69889
+ } else {
69890
+ if (focus_position.getInstance().avg_qty > 0 && strategy2.running === false) {
69891
+ await focus_position.cancelOrders({
69892
+ limit: true
69893
+ });
69894
+ }
69895
+ }
69896
+ }
69843
69897
  async profitWithinGapStrategy(payload) {
69844
69898
  const { symbol } = payload;
69845
69899
  console.log("Fetching positions for ", symbol);
@@ -69856,7 +69910,6 @@ class ExchangeAccount {
69856
69910
  return;
69857
69911
  }
69858
69912
  const kind = strategy2.kind;
69859
- const reward_factor = strategy2.reward_factor;
69860
69913
  const { entries, last_value, ...app_config } = await this.tradeConfig({
69861
69914
  symbol,
69862
69915
  kind
@@ -69884,34 +69937,10 @@ class ExchangeAccount {
69884
69937
  });
69885
69938
  }
69886
69939
  console.log("Checking if focus position has quantity for ", symbol, kind);
69887
- const reversePosition = await this.getFocusPosition({
69940
+ await this.oppositeGapExists({
69888
69941
  symbol,
69889
- kind: kind === "long" ? "short" : "long"
69942
+ kind
69890
69943
  });
69891
- if (focusPosition.getInstance().quantity > 0) {
69892
- const opposite_config = focusPosition.getOppositeConfig({
69893
- ratio: reward_factor
69894
- });
69895
- const reverse_config = await reversePosition.getConfig();
69896
- if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focusPosition.getInstance().quantity > 0) {
69897
- console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
69898
- await reversePosition.getConfig({
69899
- params: {
69900
- entry: opposite_config.entry,
69901
- stop: opposite_config.stop,
69902
- risk: opposite_config.risk,
69903
- risk_reward: opposite_config.risk_reward
69904
- }
69905
- });
69906
- console.log("Placing trade for ", symbol, reversePosition.kind);
69907
- await reversePosition.placeTrade({
69908
- ignore_config: true,
69909
- limit: true,
69910
- place: true
69911
- });
69912
- }
69913
- console.log("Opposite config for ", symbol, kind, opposite_config);
69914
- }
69915
69944
  return {
69916
69945
  config_details: {
69917
69946
  app_config,
@@ -70376,15 +70405,25 @@ class App {
70376
70405
  });
70377
70406
  return result;
70378
70407
  }
70379
- async runDbStrategyAccounts(callback) {
70408
+ async runDbStrategyAccounts(payload) {
70409
+ const { runningCallback, notRunningCallback } = payload;
70380
70410
  const strategies = await this.app_db.getRunningAccountStrategies();
70381
70411
  for (const strategy2 of strategies) {
70382
70412
  console.log("Running strategy for ", strategy2.symbol, "for account", strategy2.expand.account.owner, strategy2.expand.account.exchange);
70383
- await callback({
70413
+ await runningCallback({
70384
70414
  symbol: strategy2.symbol,
70385
70415
  account: strategy2.expand.account
70386
70416
  });
70387
70417
  }
70418
+ const not_running_strategies = await this.app_db.getRunningAccountStrategies("running=false");
70419
+ for (const strategy2 of not_running_strategies) {
70420
+ console.log("Not running strategy for ", strategy2.symbol);
70421
+ await notRunningCallback({
70422
+ symbol: strategy2.symbol,
70423
+ account: strategy2.expand.account,
70424
+ kind: strategy2.kind
70425
+ });
70426
+ }
70388
70427
  }
70389
70428
  async profitWithinGapStrategy(payload) {
70390
70429
  const { account, symbol } = payload;
@@ -61844,9 +61844,9 @@ class AppDatabase {
61844
61844
  }
61845
61845
  return null;
61846
61846
  }
61847
- async getRunningAccountStrategies() {
61847
+ async getRunningAccountStrategies(filter = "running=true") {
61848
61848
  const result = await this.pb.collection("account_strategies").getFullList({
61849
- filter: `running=true`,
61849
+ filter,
61850
61850
  expand: "account"
61851
61851
  });
61852
61852
  return result;
@@ -67573,7 +67573,14 @@ class ExchangePosition {
67573
67573
  place_tp: payload.params.place_tp !== undefined ? payload.params.place_tp : true,
67574
67574
  profit: payload.params.profit !== undefined ? payload.params.profit : config2?.profit
67575
67575
  };
67576
- return await this.app_db.createOrUpdatePositionConfig(this.instance, params);
67576
+ return await this.app_db.createOrUpdatePositionConfig({
67577
+ ...this.instance,
67578
+ expand: {
67579
+ ...this.instance.expand || {},
67580
+ account: this.account
67581
+ },
67582
+ account: this.account.id
67583
+ }, params);
67577
67584
  }
67578
67585
  }
67579
67586
  if (this.instance.expand?.b_config) {
@@ -68352,8 +68359,8 @@ class ExchangePosition {
68352
68359
  });
68353
68360
  return this.getConfig({
68354
68361
  params: {
68355
- entry: config2.entry,
68356
- stop: config2.stop,
68362
+ entry: long_c.entry,
68363
+ stop: long_c.stop,
68357
68364
  risk_reward: long_c.risk_reward,
68358
68365
  risk: long_c.risk
68359
68366
  }
@@ -69817,6 +69824,53 @@ class ExchangeAccount {
69817
69824
  short_percent
69818
69825
  };
69819
69826
  }
69827
+ async oppositeGapExists(payload) {
69828
+ const focus_position = await this.getFocusPosition({
69829
+ symbol: payload.symbol,
69830
+ kind: payload.kind
69831
+ });
69832
+ const strategy2 = focus_position.getInstance().expand?.account_strategy;
69833
+ if (!strategy2) {
69834
+ return;
69835
+ }
69836
+ const kind = strategy2.kind;
69837
+ const reward_factor = strategy2.reward_factor;
69838
+ const { symbol } = payload;
69839
+ const reversePosition = await this.getFocusPosition({
69840
+ symbol,
69841
+ kind: kind === "long" ? "short" : "long"
69842
+ });
69843
+ if (focus_position.getInstance().quantity > 0) {
69844
+ const opposite_config = focus_position.getOppositeConfig({
69845
+ ratio: reward_factor
69846
+ });
69847
+ const reverse_config = await reversePosition.getConfig();
69848
+ if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focus_position.getInstance().quantity > 0) {
69849
+ console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
69850
+ await reversePosition.getConfig({
69851
+ params: {
69852
+ entry: opposite_config.entry,
69853
+ stop: opposite_config.stop,
69854
+ risk: opposite_config.risk,
69855
+ risk_reward: opposite_config.risk_reward
69856
+ }
69857
+ });
69858
+ console.log("Placing trade for ", symbol, reversePosition.kind);
69859
+ await reversePosition.placeTrade({
69860
+ ignore_config: true,
69861
+ limit: true,
69862
+ place: true
69863
+ });
69864
+ }
69865
+ console.log("Opposite config for ", symbol, kind, opposite_config);
69866
+ } else {
69867
+ if (focus_position.getInstance().avg_qty > 0 && strategy2.running === false) {
69868
+ await focus_position.cancelOrders({
69869
+ limit: true
69870
+ });
69871
+ }
69872
+ }
69873
+ }
69820
69874
  async profitWithinGapStrategy(payload) {
69821
69875
  const { symbol } = payload;
69822
69876
  console.log("Fetching positions for ", symbol);
@@ -69833,7 +69887,6 @@ class ExchangeAccount {
69833
69887
  return;
69834
69888
  }
69835
69889
  const kind = strategy2.kind;
69836
- const reward_factor = strategy2.reward_factor;
69837
69890
  const { entries, last_value, ...app_config } = await this.tradeConfig({
69838
69891
  symbol,
69839
69892
  kind
@@ -69861,34 +69914,10 @@ class ExchangeAccount {
69861
69914
  });
69862
69915
  }
69863
69916
  console.log("Checking if focus position has quantity for ", symbol, kind);
69864
- const reversePosition = await this.getFocusPosition({
69917
+ await this.oppositeGapExists({
69865
69918
  symbol,
69866
- kind: kind === "long" ? "short" : "long"
69919
+ kind
69867
69920
  });
69868
- if (focusPosition.getInstance().quantity > 0) {
69869
- const opposite_config = focusPosition.getOppositeConfig({
69870
- ratio: reward_factor
69871
- });
69872
- const reverse_config = await reversePosition.getConfig();
69873
- if ((reverse_config.entry !== opposite_config.entry || reverse_config.stop !== opposite_config.stop || reverse_config.risk !== opposite_config.risk || reverse_config.risk_reward !== opposite_config.risk_reward) && focusPosition.getInstance().quantity > 0) {
69874
- console.log("Updating reverse config for ", symbol, kind, "with opposite config", opposite_config);
69875
- await reversePosition.getConfig({
69876
- params: {
69877
- entry: opposite_config.entry,
69878
- stop: opposite_config.stop,
69879
- risk: opposite_config.risk,
69880
- risk_reward: opposite_config.risk_reward
69881
- }
69882
- });
69883
- console.log("Placing trade for ", symbol, reversePosition.kind);
69884
- await reversePosition.placeTrade({
69885
- ignore_config: true,
69886
- limit: true,
69887
- place: true
69888
- });
69889
- }
69890
- console.log("Opposite config for ", symbol, kind, opposite_config);
69891
- }
69892
69921
  return {
69893
69922
  config_details: {
69894
69923
  app_config,
@@ -70353,15 +70382,25 @@ class App {
70353
70382
  });
70354
70383
  return result;
70355
70384
  }
70356
- async runDbStrategyAccounts(callback) {
70385
+ async runDbStrategyAccounts(payload) {
70386
+ const { runningCallback, notRunningCallback } = payload;
70357
70387
  const strategies = await this.app_db.getRunningAccountStrategies();
70358
70388
  for (const strategy2 of strategies) {
70359
70389
  console.log("Running strategy for ", strategy2.symbol, "for account", strategy2.expand.account.owner, strategy2.expand.account.exchange);
70360
- await callback({
70390
+ await runningCallback({
70361
70391
  symbol: strategy2.symbol,
70362
70392
  account: strategy2.expand.account
70363
70393
  });
70364
70394
  }
70395
+ const not_running_strategies = await this.app_db.getRunningAccountStrategies("running=false");
70396
+ for (const strategy2 of not_running_strategies) {
70397
+ console.log("Not running strategy for ", strategy2.symbol);
70398
+ await notRunningCallback({
70399
+ symbol: strategy2.symbol,
70400
+ account: strategy2.expand.account,
70401
+ kind: strategy2.kind
70402
+ });
70403
+ }
70365
70404
  }
70366
70405
  async profitWithinGapStrategy(payload) {
70367
70406
  const { account, symbol } = payload;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-158",
4
+ "version": "0.0.2-159",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",