@gbozee/ultimate 0.0.2-next.27 → 0.0.2-next.29

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.
package/dist/index.cjs CHANGED
@@ -49897,6 +49897,7 @@ __export(exports_src, {
49897
49897
  initSqliteDb: () => initSqliteDb,
49898
49898
  initApp: () => initApp,
49899
49899
  get_app_config_and_max_size: () => get_app_config_and_max_size,
49900
+ getTradeSymbols: () => getTradeSymbols,
49900
49901
  getRiskReward: () => getRiskReward,
49901
49902
  getOptimumStopAndRisk: () => getOptimumStopAndRisk,
49902
49903
  getOptimumHedgeFactor: () => getOptimumHedgeFactor,
@@ -59765,6 +59766,12 @@ class AppDatabase {
59765
59766
  return fields.join(", ");
59766
59767
  }
59767
59768
  async fetchCentralPositions(payload) {
59769
+ if (this.drizzlePb) {
59770
+ return this.drizzlePb.fetchCentralPositions({
59771
+ ...payload,
59772
+ email: this.email
59773
+ });
59774
+ }
59768
59775
  const { asset: assetName, symbol, customFilter = "" } = payload;
59769
59776
  const pb = this.pb;
59770
59777
  let symbolFilter = assetName ? `symbol ~ "${assetName}"` : `symbol = "${symbol}"`;
@@ -72470,7 +72477,8 @@ var orderColumns = {
72470
72477
  opposite_qty: real("opposite_qty"),
72471
72478
  avg_entry_price: real("avg_entry_price"),
72472
72479
  avg_price: real("avg_price"),
72473
- avg_qty: real("avg_qty")
72480
+ avg_qty: real("avg_qty"),
72481
+ account_id: text("account_id")
72474
72482
  };
72475
72483
  var orders = sqliteTable("orders", {
72476
72484
  id: text("id").primaryKey(),
@@ -72726,7 +72734,7 @@ class DrizzlePocketbase {
72726
72734
  proxy: row.proxies,
72727
72735
  symbol_config: row.symbol_configs,
72728
72736
  compound_instance: row.compound_instances,
72729
- short_compound_strategy: row.short_compound_strategy,
72737
+ short_compound_strategy: this.updateShortStrategyView(row.short_compound_strategy),
72730
72738
  watch_instance: row.watch_positions
72731
72739
  }
72732
72740
  }));
@@ -72790,6 +72798,15 @@ class DrizzlePocketbase {
72790
72798
  }
72791
72799
  return null;
72792
72800
  }
72801
+ updateShortStrategyView(xx) {
72802
+ if (xx) {
72803
+ return {
72804
+ ...xx,
72805
+ support: xx.support ? JSON.parse(xx.support) : null
72806
+ };
72807
+ }
72808
+ return null;
72809
+ }
72793
72810
  async createOrUpdatePositionConfig(db_position, payload) {
72794
72811
  let config2 = null;
72795
72812
  if (db_position.config) {
@@ -72875,6 +72892,135 @@ class DrizzlePocketbase {
72875
72892
  return result[0];
72876
72893
  }
72877
72894
  async update_db_position(_position, _payload) {}
72895
+ get positionExpand() {
72896
+ const fields = [
72897
+ "b_config",
72898
+ "account_strategy",
72899
+ "p_account",
72900
+ "proxy",
72901
+ "compound_instance.ref",
72902
+ "support",
72903
+ "resistance",
72904
+ "symbol_config",
72905
+ "anchor",
72906
+ "watch_instance",
72907
+ "short_compound_strategy.tracking_account.account"
72908
+ ];
72909
+ return fields.join(", ");
72910
+ }
72911
+ async fetchCentralPositions(payload) {
72912
+ const { asset: assetName, symbol, customFilter = "" } = payload;
72913
+ await this.client.sync();
72914
+ const query = this.db.select().from(derivedPositionView).leftJoin(exchangeAccounts, eq(derivedPositionView.p_account, exchangeAccounts.id)).leftJoin(scheduledTrades, eq(derivedPositionView.b_config, scheduledTrades.id)).leftJoin(proxies, eq(derivedPositionView.proxy, proxies.id)).leftJoin(symbolConfigs, eq(derivedPositionView.symbol_config, symbolConfigs.id)).leftJoin(compoundInstances, eq(derivedPositionView.compound_instance, compoundInstances.id)).leftJoin(shortCompoundStrategy, eq(derivedPositionView.short_compound_strategy, shortCompoundStrategy.id)).leftJoin(watchPositions, eq(derivedPositionView.watch_instance, watchPositions.id));
72915
+ const filters = [];
72916
+ if (assetName) {
72917
+ filters.push(sql`${derivedPositionView.symbol} LIKE ${`${assetName}%`}`);
72918
+ } else if (symbol) {
72919
+ filters.push(eq(lower(derivedPositionView.symbol), symbol.toLowerCase()));
72920
+ }
72921
+ if (payload.email) {
72922
+ filters.push(eq(lower(exchangeAccounts.email), payload.email.toLowerCase()));
72923
+ }
72924
+ if (customFilter) {
72925
+ filters.push(customFilter);
72926
+ }
72927
+ const queryWithFilters = filters.length > 0 ? query.where(and(...filters)) : query;
72928
+ const results = await queryWithFilters;
72929
+ return results.map((row) => ({
72930
+ ...row.derived_positions_view,
72931
+ expand: {
72932
+ p_account: row.exchange_accounts,
72933
+ b_config: this.updateScheduledTrades({
72934
+ scheduled_trades: row.scheduled_trades,
72935
+ exchange_accounts: row.exchange_accounts
72936
+ }),
72937
+ proxy: row.proxies,
72938
+ symbol_config: row.symbol_configs,
72939
+ compound_instance: row.compound_instances,
72940
+ short_compound_strategy: this.updateShortStrategyView(row.short_compound_strategy),
72941
+ watch_instance: row.watch_positions
72942
+ }
72943
+ }));
72944
+ }
72945
+ }
72946
+ async function getTradeSymbols(getApp, _symbol, auth2) {
72947
+ const app = await getApp(auth2);
72948
+ const pb = app.app_db.pb;
72949
+ let symbols = [];
72950
+ let positions = [];
72951
+ let exchange_accounts = [];
72952
+ if (app.app_db.email) {
72953
+ const exchangeAccountResults = await pb.db.select().from(exchangeAccounts).where(eq(lower(exchangeAccounts.email), app.app_db.email.toLowerCase()));
72954
+ exchange_accounts = exchangeAccountResults;
72955
+ const exchange_ids = exchange_accounts.map((ea) => ea.id);
72956
+ if (exchange_ids.length === 0) {
72957
+ return [];
72958
+ }
72959
+ const positionFilters = [
72960
+ sql`${derivedPositionView.p_account} IN (${exchange_ids.join(", ")})`
72961
+ ];
72962
+ if (_symbol) {
72963
+ positionFilters.push(eq(lower(derivedPositionView.symbol), _symbol.toLowerCase()));
72964
+ }
72965
+ const positionResults = await pb.db.select().from(derivedPositionView).leftJoin(exchangeAccounts, eq(derivedPositionView.p_account, exchangeAccounts.id)).where(and(...positionFilters));
72966
+ positions = positionResults.map((row) => ({
72967
+ ...row.derived_positions_view,
72968
+ expand: {
72969
+ account: row.exchange_accounts
72970
+ },
72971
+ account: row.exchange_accounts?.id
72972
+ }));
72973
+ const raw_symbols = positions.map((p) => p.symbol);
72974
+ const unique_symbols = [...new Set(raw_symbols)];
72975
+ if (unique_symbols.length === 0) {
72976
+ return [];
72977
+ }
72978
+ const symbolFilters = [
72979
+ sql`${symbolConfigs.symbol} IN (${unique_symbols.map((s2) => `'${s2}'`).join(", ")})`
72980
+ ];
72981
+ if (_symbol) {
72982
+ symbolFilters.push(eq(lower(symbolConfigs.symbol), _symbol.toLowerCase()));
72983
+ }
72984
+ const symbolResults = await pb.db.select().from(symbolConfigs).where(and(...symbolFilters));
72985
+ symbols = symbolResults;
72986
+ } else {
72987
+ const symbolQuery = _symbol ? pb.db.select().from(symbolConfigs).where(eq(lower(symbolConfigs.symbol), _symbol.toLowerCase())) : pb.db.select().from(symbolConfigs);
72988
+ symbols = await symbolQuery;
72989
+ const positionQuery = pb.db.select().from(derivedPositionView).leftJoin(exchangeAccounts, eq(derivedPositionView.p_account, exchangeAccounts.id));
72990
+ const positionQueryWithFilter = _symbol ? positionQuery.where(eq(lower(derivedPositionView.symbol), _symbol.toLowerCase())) : positionQuery;
72991
+ const positionResults = await positionQueryWithFilter;
72992
+ positions = positionResults.map((row) => ({
72993
+ ...row.derived_positions_view,
72994
+ expand: {
72995
+ account: row.exchange_accounts
72996
+ },
72997
+ account: row.exchange_accounts?.id
72998
+ }));
72999
+ const exchangeAccountResults = await pb.db.select().from(exchangeAccounts);
73000
+ exchange_accounts = exchangeAccountResults;
73001
+ }
73002
+ exchange_accounts = exchange_accounts.map((ea) => ({
73003
+ id: ea.id,
73004
+ owner: ea.owner,
73005
+ exchange: ea.exchange
73006
+ }));
73007
+ let symbolsWithCount = [];
73008
+ for (const symbol of symbols) {
73009
+ const matchingPositions = positions.filter((p) => p.symbol === symbol.symbol);
73010
+ const uniqueAccounts = new Set(matchingPositions.map((p) => p.account));
73011
+ const account_ids = Array.from(uniqueAccounts);
73012
+ const account_details = account_ids.map((id) => exchange_accounts.find((ea) => ea.id === id)).filter(Boolean);
73013
+ symbolsWithCount.push({
73014
+ ...symbol,
73015
+ exchange_count: uniqueAccounts.size,
73016
+ account_ids: uniqueAccounts,
73017
+ account_details,
73018
+ symbol: symbol.symbol
73019
+ });
73020
+ }
73021
+ symbolsWithCount.sort((a, b) => b.exchange_count - a.exchange_count);
73022
+ const filteredSymbols = symbolsWithCount;
73023
+ return filteredSymbols;
72878
73024
  }
72879
73025
 
72880
73026
  // src/db/index.ts
@@ -72888,7 +73034,8 @@ async function initSqliteDb({
72888
73034
  let import_4 = await Promise.resolve().then(() => (init_web2(), exports_web2));
72889
73035
  const turso = import_3.createClient({
72890
73036
  url: syncUrl,
72891
- authToken
73037
+ authToken,
73038
+ intMode: "bigint"
72892
73039
  });
72893
73040
  const db2 = import_4.drizzle(turso);
72894
73041
  const client = {
package/dist/index.d.ts CHANGED
@@ -2714,6 +2714,28 @@ export declare const orders: import("drizzle-orm/sqlite-core").SQLiteTableWithCo
2714
2714
  identity: undefined;
2715
2715
  generated: undefined;
2716
2716
  }, {}, {}>;
2717
+ account_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
2718
+ name: "account_id";
2719
+ tableName: "orders";
2720
+ dataType: "string";
2721
+ columnType: "SQLiteText";
2722
+ data: string;
2723
+ driverParam: string;
2724
+ notNull: false;
2725
+ hasDefault: false;
2726
+ isPrimaryKey: false;
2727
+ isAutoincrement: false;
2728
+ hasRuntimeDefault: false;
2729
+ enumValues: [
2730
+ string,
2731
+ ...string[]
2732
+ ];
2733
+ baseColumn: never;
2734
+ identity: undefined;
2735
+ generated: undefined;
2736
+ }, {}, {
2737
+ length: number;
2738
+ }>;
2717
2739
  id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
2718
2740
  name: "id";
2719
2741
  tableName: "orders";
@@ -4322,6 +4344,7 @@ export declare class DrizzlePocketbase {
4322
4344
  avg_entry_price: number;
4323
4345
  avg_price: number;
4324
4346
  avg_qty: number;
4347
+ account_id: string;
4325
4348
  id: string;
4326
4349
  }[]>;
4327
4350
  getPositionConfig(payload: {
@@ -4330,6 +4353,7 @@ export declare class DrizzlePocketbase {
4330
4353
  account: ExchangeType;
4331
4354
  }): Promise<ScheduledTrade | null>;
4332
4355
  private updateScheduledTrades;
4356
+ private updateShortStrategyView;
4333
4357
  createOrUpdatePositionConfig(db_position: any, payload: {
4334
4358
  entry: number;
4335
4359
  stop: number;
@@ -4342,7 +4366,120 @@ export declare class DrizzlePocketbase {
4342
4366
  }): Promise<ScheduledTrade>;
4343
4367
  updateScheduledTrade(id: string, payload: any): Promise<ScheduledTrade>;
4344
4368
  update_db_position(_position: any, _payload: any): Promise<void>;
4369
+ get positionExpand(): string;
4370
+ fetchCentralPositions(payload: {
4371
+ asset?: string;
4372
+ symbol?: string;
4373
+ customFilter?: SQL;
4374
+ email?: string;
4375
+ }): Promise<{
4376
+ expand: {
4377
+ p_account: {
4378
+ created: string;
4379
+ updated: string;
4380
+ id: string;
4381
+ exchange: "binance" | "bybit";
4382
+ owner: string;
4383
+ email: string;
4384
+ usdt: number;
4385
+ usdc: number;
4386
+ proxy: string;
4387
+ bullish: boolean;
4388
+ bearish: boolean;
4389
+ movePercent: number;
4390
+ totalRisk: number;
4391
+ max_non_essential: number;
4392
+ profit_percent: number;
4393
+ risk_reward: number;
4394
+ exclude_coins: unknown;
4395
+ include_delisted: boolean;
4396
+ };
4397
+ b_config: ScheduledTrade;
4398
+ proxy: {
4399
+ created: string;
4400
+ updated: string;
4401
+ id: string;
4402
+ ip_address: string;
4403
+ type: string;
4404
+ };
4405
+ symbol_config: {
4406
+ created: string;
4407
+ updated: string;
4408
+ id: string;
4409
+ symbol: string;
4410
+ support: number;
4411
+ resistance: number;
4412
+ stop_percent: number;
4413
+ price_places: string;
4414
+ decimal_places: string;
4415
+ min_size: number;
4416
+ max_quantity: number;
4417
+ weight: number;
4418
+ leverage: number;
4419
+ candle_count: number;
4420
+ interval: string;
4421
+ fee_percent: number;
4422
+ essential: boolean;
4423
+ };
4424
+ compound_instance: {
4425
+ created: string;
4426
+ updated: string;
4427
+ id: string;
4428
+ ref: string;
4429
+ risk: number;
4430
+ hedged: boolean;
4431
+ loss: number;
4432
+ record: string;
4433
+ };
4434
+ short_compound_strategy: any;
4435
+ watch_instance: {
4436
+ created: string;
4437
+ updated: string;
4438
+ id: string;
4439
+ stop: number;
4440
+ kind: "long" | "short";
4441
+ record: string;
4442
+ };
4443
+ };
4444
+ id: string;
4445
+ account_id: string;
4446
+ p_account: string;
4447
+ account: string;
4448
+ symbol: string;
4449
+ entry: number;
4450
+ kind: string;
4451
+ liquidation: number;
4452
+ quantity: number;
4453
+ stop_quantity: number;
4454
+ avg_price: number;
4455
+ avg_qty: number;
4456
+ next_trade: unknown;
4457
+ next_order: number;
4458
+ last_order: number;
4459
+ stop_loss: unknown;
4460
+ stop_pnl: number;
4461
+ tp: unknown;
4462
+ take_profit: number;
4463
+ target_pnl: number;
4464
+ tp_quantity: number;
4465
+ current_price: number;
4466
+ record: string;
4467
+ leverage: number;
4468
+ balance: number;
4469
+ opposite_entry: number;
4470
+ opposite_quantity: number;
4471
+ proxy: string;
4472
+ matched_order: unknown;
4473
+ support: string;
4474
+ resistance: string;
4475
+ symbol_config: string;
4476
+ compound_instance: string;
4477
+ b_config: string;
4478
+ short_compound_strategy: string;
4479
+ watch_instance: string;
4480
+ }[]>;
4345
4481
  }
4482
+ export declare function getTradeSymbols(getApp: any, _symbol?: string, auth?: any): Promise<any[]>;
4346
4483
  declare function encryptObject(obj: any, password: string): string;
4347
4484
  declare function decryptObject(encryptedString: string, password: string): any;
4348
4485
  declare function initPocketBaseClient(proxy_credentials: {
@@ -4512,8 +4649,113 @@ export declare class AppDatabase {
4512
4649
  fetchCentralPositions(payload: {
4513
4650
  asset?: string;
4514
4651
  symbol?: string;
4515
- customFilter?: string;
4516
- }): Promise<import("pocketbase").RecordModel[]>;
4652
+ customFilter?: any;
4653
+ }): Promise<import("pocketbase").RecordModel[] | {
4654
+ expand: {
4655
+ p_account: {
4656
+ created: string;
4657
+ updated: string;
4658
+ id: string;
4659
+ exchange: "binance" | "bybit";
4660
+ owner: string;
4661
+ email: string;
4662
+ usdt: number;
4663
+ usdc: number;
4664
+ proxy: string;
4665
+ bullish: boolean;
4666
+ bearish: boolean;
4667
+ movePercent: number;
4668
+ totalRisk: number;
4669
+ max_non_essential: number;
4670
+ profit_percent: number;
4671
+ risk_reward: number;
4672
+ exclude_coins: unknown;
4673
+ include_delisted: boolean;
4674
+ };
4675
+ b_config: ScheduledTrade;
4676
+ proxy: {
4677
+ created: string;
4678
+ updated: string;
4679
+ id: string;
4680
+ ip_address: string;
4681
+ type: string;
4682
+ };
4683
+ symbol_config: {
4684
+ created: string;
4685
+ updated: string;
4686
+ id: string;
4687
+ symbol: string;
4688
+ support: number;
4689
+ resistance: number;
4690
+ stop_percent: number;
4691
+ price_places: string;
4692
+ decimal_places: string;
4693
+ min_size: number;
4694
+ max_quantity: number;
4695
+ weight: number;
4696
+ leverage: number;
4697
+ candle_count: number;
4698
+ interval: string;
4699
+ fee_percent: number;
4700
+ essential: boolean;
4701
+ };
4702
+ compound_instance: {
4703
+ created: string;
4704
+ updated: string;
4705
+ id: string;
4706
+ ref: string;
4707
+ risk: number;
4708
+ hedged: boolean;
4709
+ loss: number;
4710
+ record: string;
4711
+ };
4712
+ short_compound_strategy: any;
4713
+ watch_instance: {
4714
+ created: string;
4715
+ updated: string;
4716
+ id: string;
4717
+ stop: number;
4718
+ kind: "long" | "short";
4719
+ record: string;
4720
+ };
4721
+ };
4722
+ id: string;
4723
+ account_id: string;
4724
+ p_account: string;
4725
+ account: string;
4726
+ symbol: string;
4727
+ entry: number;
4728
+ kind: string;
4729
+ liquidation: number;
4730
+ quantity: number;
4731
+ stop_quantity: number;
4732
+ avg_price: number;
4733
+ avg_qty: number;
4734
+ next_trade: unknown;
4735
+ next_order: number;
4736
+ last_order: number;
4737
+ stop_loss: unknown;
4738
+ stop_pnl: number;
4739
+ tp: unknown;
4740
+ take_profit: number;
4741
+ target_pnl: number;
4742
+ tp_quantity: number;
4743
+ current_price: number;
4744
+ record: string;
4745
+ leverage: number;
4746
+ balance: number;
4747
+ opposite_entry: number;
4748
+ opposite_quantity: number;
4749
+ proxy: string;
4750
+ matched_order: unknown;
4751
+ support: string;
4752
+ resistance: string;
4753
+ symbol_config: string;
4754
+ compound_instance: string;
4755
+ b_config: string;
4756
+ short_compound_strategy: string;
4757
+ watch_instance: string;
4758
+ }[]>;
4517
4759
  getPositions(options: {
4518
4760
  account?: ExchangeType;
4519
4761
  symbol?: string;
@@ -4619,6 +4861,7 @@ export declare class AppDatabase {
4619
4861
  avg_entry_price: number;
4620
4862
  avg_price: number;
4621
4863
  avg_qty: number;
4864
+ account_id: string;
4622
4865
  id: string;
4623
4866
  }[]>;
4624
4867
  cancelLimitOrders(payload: {
@@ -6478,6 +6721,7 @@ export declare class ExchangePosition {
6478
6721
  avg_entry_price: number;
6479
6722
  avg_price: number;
6480
6723
  avg_qty: number;
6724
+ account_id: string;
6481
6725
  id: string;
6482
6726
  }[] | Order[];
6483
6727
  }>;
@@ -6938,6 +7182,7 @@ declare class ExchangeAccount$1 {
6938
7182
  avg_entry_price: number;
6939
7183
  avg_price: number;
6940
7184
  avg_qty: number;
7185
+ account_id: string;
6941
7186
  id: string;
6942
7187
  }[] | Order[]>;
6943
7188
  toggleStopBuying(payload: {
@@ -7224,6 +7469,7 @@ declare class ExchangeAccount$1 {
7224
7469
  avg_entry_price: number;
7225
7470
  avg_price: number;
7226
7471
  avg_qty: number;
7472
+ account_id: string;
7227
7473
  id: string;
7228
7474
  }[] | Order[]>;
7229
7475
  windDownSymbol(payload: {
package/dist/index.js CHANGED
@@ -59679,6 +59679,12 @@ class AppDatabase {
59679
59679
  return fields.join(", ");
59680
59680
  }
59681
59681
  async fetchCentralPositions(payload) {
59682
+ if (this.drizzlePb) {
59683
+ return this.drizzlePb.fetchCentralPositions({
59684
+ ...payload,
59685
+ email: this.email
59686
+ });
59687
+ }
59682
59688
  const { asset: assetName, symbol, customFilter = "" } = payload;
59683
59689
  const pb = this.pb;
59684
59690
  let symbolFilter = assetName ? `symbol ~ "${assetName}"` : `symbol = "${symbol}"`;
@@ -72384,7 +72390,8 @@ var orderColumns = {
72384
72390
  opposite_qty: real("opposite_qty"),
72385
72391
  avg_entry_price: real("avg_entry_price"),
72386
72392
  avg_price: real("avg_price"),
72387
- avg_qty: real("avg_qty")
72393
+ avg_qty: real("avg_qty"),
72394
+ account_id: text("account_id")
72388
72395
  };
72389
72396
  var orders = sqliteTable("orders", {
72390
72397
  id: text("id").primaryKey(),
@@ -72640,7 +72647,7 @@ class DrizzlePocketbase {
72640
72647
  proxy: row.proxies,
72641
72648
  symbol_config: row.symbol_configs,
72642
72649
  compound_instance: row.compound_instances,
72643
- short_compound_strategy: row.short_compound_strategy,
72650
+ short_compound_strategy: this.updateShortStrategyView(row.short_compound_strategy),
72644
72651
  watch_instance: row.watch_positions
72645
72652
  }
72646
72653
  }));
@@ -72704,6 +72711,15 @@ class DrizzlePocketbase {
72704
72711
  }
72705
72712
  return null;
72706
72713
  }
72714
+ updateShortStrategyView(xx) {
72715
+ if (xx) {
72716
+ return {
72717
+ ...xx,
72718
+ support: xx.support ? JSON.parse(xx.support) : null
72719
+ };
72720
+ }
72721
+ return null;
72722
+ }
72707
72723
  async createOrUpdatePositionConfig(db_position, payload) {
72708
72724
  let config2 = null;
72709
72725
  if (db_position.config) {
@@ -72789,6 +72805,135 @@ class DrizzlePocketbase {
72789
72805
  return result[0];
72790
72806
  }
72791
72807
  async update_db_position(_position, _payload) {}
72808
+ get positionExpand() {
72809
+ const fields = [
72810
+ "b_config",
72811
+ "account_strategy",
72812
+ "p_account",
72813
+ "proxy",
72814
+ "compound_instance.ref",
72815
+ "support",
72816
+ "resistance",
72817
+ "symbol_config",
72818
+ "anchor",
72819
+ "watch_instance",
72820
+ "short_compound_strategy.tracking_account.account"
72821
+ ];
72822
+ return fields.join(", ");
72823
+ }
72824
+ async fetchCentralPositions(payload) {
72825
+ const { asset: assetName, symbol, customFilter = "" } = payload;
72826
+ await this.client.sync();
72827
+ const query = this.db.select().from(derivedPositionView).leftJoin(exchangeAccounts, eq(derivedPositionView.p_account, exchangeAccounts.id)).leftJoin(scheduledTrades, eq(derivedPositionView.b_config, scheduledTrades.id)).leftJoin(proxies, eq(derivedPositionView.proxy, proxies.id)).leftJoin(symbolConfigs, eq(derivedPositionView.symbol_config, symbolConfigs.id)).leftJoin(compoundInstances, eq(derivedPositionView.compound_instance, compoundInstances.id)).leftJoin(shortCompoundStrategy, eq(derivedPositionView.short_compound_strategy, shortCompoundStrategy.id)).leftJoin(watchPositions, eq(derivedPositionView.watch_instance, watchPositions.id));
72828
+ const filters = [];
72829
+ if (assetName) {
72830
+ filters.push(sql`${derivedPositionView.symbol} LIKE ${`${assetName}%`}`);
72831
+ } else if (symbol) {
72832
+ filters.push(eq(lower(derivedPositionView.symbol), symbol.toLowerCase()));
72833
+ }
72834
+ if (payload.email) {
72835
+ filters.push(eq(lower(exchangeAccounts.email), payload.email.toLowerCase()));
72836
+ }
72837
+ if (customFilter) {
72838
+ filters.push(customFilter);
72839
+ }
72840
+ const queryWithFilters = filters.length > 0 ? query.where(and(...filters)) : query;
72841
+ const results = await queryWithFilters;
72842
+ return results.map((row) => ({
72843
+ ...row.derived_positions_view,
72844
+ expand: {
72845
+ p_account: row.exchange_accounts,
72846
+ b_config: this.updateScheduledTrades({
72847
+ scheduled_trades: row.scheduled_trades,
72848
+ exchange_accounts: row.exchange_accounts
72849
+ }),
72850
+ proxy: row.proxies,
72851
+ symbol_config: row.symbol_configs,
72852
+ compound_instance: row.compound_instances,
72853
+ short_compound_strategy: this.updateShortStrategyView(row.short_compound_strategy),
72854
+ watch_instance: row.watch_positions
72855
+ }
72856
+ }));
72857
+ }
72858
+ }
72859
+ async function getTradeSymbols(getApp, _symbol, auth2) {
72860
+ const app = await getApp(auth2);
72861
+ const pb = app.app_db.pb;
72862
+ let symbols = [];
72863
+ let positions = [];
72864
+ let exchange_accounts = [];
72865
+ if (app.app_db.email) {
72866
+ const exchangeAccountResults = await pb.db.select().from(exchangeAccounts).where(eq(lower(exchangeAccounts.email), app.app_db.email.toLowerCase()));
72867
+ exchange_accounts = exchangeAccountResults;
72868
+ const exchange_ids = exchange_accounts.map((ea) => ea.id);
72869
+ if (exchange_ids.length === 0) {
72870
+ return [];
72871
+ }
72872
+ const positionFilters = [
72873
+ sql`${derivedPositionView.p_account} IN (${exchange_ids.join(", ")})`
72874
+ ];
72875
+ if (_symbol) {
72876
+ positionFilters.push(eq(lower(derivedPositionView.symbol), _symbol.toLowerCase()));
72877
+ }
72878
+ const positionResults = await pb.db.select().from(derivedPositionView).leftJoin(exchangeAccounts, eq(derivedPositionView.p_account, exchangeAccounts.id)).where(and(...positionFilters));
72879
+ positions = positionResults.map((row) => ({
72880
+ ...row.derived_positions_view,
72881
+ expand: {
72882
+ account: row.exchange_accounts
72883
+ },
72884
+ account: row.exchange_accounts?.id
72885
+ }));
72886
+ const raw_symbols = positions.map((p) => p.symbol);
72887
+ const unique_symbols = [...new Set(raw_symbols)];
72888
+ if (unique_symbols.length === 0) {
72889
+ return [];
72890
+ }
72891
+ const symbolFilters = [
72892
+ sql`${symbolConfigs.symbol} IN (${unique_symbols.map((s2) => `'${s2}'`).join(", ")})`
72893
+ ];
72894
+ if (_symbol) {
72895
+ symbolFilters.push(eq(lower(symbolConfigs.symbol), _symbol.toLowerCase()));
72896
+ }
72897
+ const symbolResults = await pb.db.select().from(symbolConfigs).where(and(...symbolFilters));
72898
+ symbols = symbolResults;
72899
+ } else {
72900
+ const symbolQuery = _symbol ? pb.db.select().from(symbolConfigs).where(eq(lower(symbolConfigs.symbol), _symbol.toLowerCase())) : pb.db.select().from(symbolConfigs);
72901
+ symbols = await symbolQuery;
72902
+ const positionQuery = pb.db.select().from(derivedPositionView).leftJoin(exchangeAccounts, eq(derivedPositionView.p_account, exchangeAccounts.id));
72903
+ const positionQueryWithFilter = _symbol ? positionQuery.where(eq(lower(derivedPositionView.symbol), _symbol.toLowerCase())) : positionQuery;
72904
+ const positionResults = await positionQueryWithFilter;
72905
+ positions = positionResults.map((row) => ({
72906
+ ...row.derived_positions_view,
72907
+ expand: {
72908
+ account: row.exchange_accounts
72909
+ },
72910
+ account: row.exchange_accounts?.id
72911
+ }));
72912
+ const exchangeAccountResults = await pb.db.select().from(exchangeAccounts);
72913
+ exchange_accounts = exchangeAccountResults;
72914
+ }
72915
+ exchange_accounts = exchange_accounts.map((ea) => ({
72916
+ id: ea.id,
72917
+ owner: ea.owner,
72918
+ exchange: ea.exchange
72919
+ }));
72920
+ let symbolsWithCount = [];
72921
+ for (const symbol of symbols) {
72922
+ const matchingPositions = positions.filter((p) => p.symbol === symbol.symbol);
72923
+ const uniqueAccounts = new Set(matchingPositions.map((p) => p.account));
72924
+ const account_ids = Array.from(uniqueAccounts);
72925
+ const account_details = account_ids.map((id) => exchange_accounts.find((ea) => ea.id === id)).filter(Boolean);
72926
+ symbolsWithCount.push({
72927
+ ...symbol,
72928
+ exchange_count: uniqueAccounts.size,
72929
+ account_ids: uniqueAccounts,
72930
+ account_details,
72931
+ symbol: symbol.symbol
72932
+ });
72933
+ }
72934
+ symbolsWithCount.sort((a, b) => b.exchange_count - a.exchange_count);
72935
+ const filteredSymbols = symbolsWithCount;
72936
+ return filteredSymbols;
72792
72937
  }
72793
72938
 
72794
72939
  // src/db/index.ts
@@ -72802,7 +72947,8 @@ async function initSqliteDb({
72802
72947
  let import_4 = await Promise.resolve().then(() => (init_web2(), exports_web2));
72803
72948
  const turso = import_3.createClient({
72804
72949
  url: syncUrl,
72805
- authToken
72950
+ authToken,
72951
+ intMode: "bigint"
72806
72952
  });
72807
72953
  const db2 = import_4.drizzle(turso);
72808
72954
  const client = {
@@ -73303,6 +73449,7 @@ export {
73303
73449
  initSqliteDb,
73304
73450
  initApp,
73305
73451
  get_app_config_and_max_size,
73452
+ getTradeSymbols,
73306
73453
  getRiskReward,
73307
73454
  getOptimumStopAndRisk,
73308
73455
  getOptimumHedgeFactor,
@@ -72840,6 +72840,12 @@ class AppDatabase {
72840
72840
  return fields.join(", ");
72841
72841
  }
72842
72842
  async fetchCentralPositions(payload) {
72843
+ if (this.drizzlePb) {
72844
+ return this.drizzlePb.fetchCentralPositions({
72845
+ ...payload,
72846
+ email: this.email
72847
+ });
72848
+ }
72843
72849
  const { asset: assetName, symbol, customFilter = "" } = payload;
72844
72850
  const pb = this.pb;
72845
72851
  let symbolFilter = assetName ? `symbol ~ "${assetName}"` : `symbol = "${symbol}"`;
@@ -85138,7 +85144,8 @@ var orderColumns = {
85138
85144
  opposite_qty: real("opposite_qty"),
85139
85145
  avg_entry_price: real("avg_entry_price"),
85140
85146
  avg_price: real("avg_price"),
85141
- avg_qty: real("avg_qty")
85147
+ avg_qty: real("avg_qty"),
85148
+ account_id: text("account_id")
85142
85149
  };
85143
85150
  var orders = sqliteTable("orders", {
85144
85151
  id: text("id").primaryKey(),
@@ -85394,7 +85401,7 @@ class DrizzlePocketbase {
85394
85401
  proxy: row.proxies,
85395
85402
  symbol_config: row.symbol_configs,
85396
85403
  compound_instance: row.compound_instances,
85397
- short_compound_strategy: row.short_compound_strategy,
85404
+ short_compound_strategy: this.updateShortStrategyView(row.short_compound_strategy),
85398
85405
  watch_instance: row.watch_positions
85399
85406
  }
85400
85407
  }));
@@ -85458,6 +85465,15 @@ class DrizzlePocketbase {
85458
85465
  }
85459
85466
  return null;
85460
85467
  }
85468
+ updateShortStrategyView(xx) {
85469
+ if (xx) {
85470
+ return {
85471
+ ...xx,
85472
+ support: xx.support ? JSON.parse(xx.support) : null
85473
+ };
85474
+ }
85475
+ return null;
85476
+ }
85461
85477
  async createOrUpdatePositionConfig(db_position, payload) {
85462
85478
  let config2 = null;
85463
85479
  if (db_position.config) {
@@ -85543,6 +85559,56 @@ class DrizzlePocketbase {
85543
85559
  return result[0];
85544
85560
  }
85545
85561
  async update_db_position(_position, _payload) {}
85562
+ get positionExpand() {
85563
+ const fields = [
85564
+ "b_config",
85565
+ "account_strategy",
85566
+ "p_account",
85567
+ "proxy",
85568
+ "compound_instance.ref",
85569
+ "support",
85570
+ "resistance",
85571
+ "symbol_config",
85572
+ "anchor",
85573
+ "watch_instance",
85574
+ "short_compound_strategy.tracking_account.account"
85575
+ ];
85576
+ return fields.join(", ");
85577
+ }
85578
+ async fetchCentralPositions(payload) {
85579
+ const { asset: assetName, symbol, customFilter = "" } = payload;
85580
+ await this.client.sync();
85581
+ const query = this.db.select().from(derivedPositionView).leftJoin(exchangeAccounts, eq(derivedPositionView.p_account, exchangeAccounts.id)).leftJoin(scheduledTrades, eq(derivedPositionView.b_config, scheduledTrades.id)).leftJoin(proxies, eq(derivedPositionView.proxy, proxies.id)).leftJoin(symbolConfigs, eq(derivedPositionView.symbol_config, symbolConfigs.id)).leftJoin(compoundInstances, eq(derivedPositionView.compound_instance, compoundInstances.id)).leftJoin(shortCompoundStrategy, eq(derivedPositionView.short_compound_strategy, shortCompoundStrategy.id)).leftJoin(watchPositions, eq(derivedPositionView.watch_instance, watchPositions.id));
85582
+ const filters = [];
85583
+ if (assetName) {
85584
+ filters.push(sql`${derivedPositionView.symbol} LIKE ${`${assetName}%`}`);
85585
+ } else if (symbol) {
85586
+ filters.push(eq(lower(derivedPositionView.symbol), symbol.toLowerCase()));
85587
+ }
85588
+ if (payload.email) {
85589
+ filters.push(eq(lower(exchangeAccounts.email), payload.email.toLowerCase()));
85590
+ }
85591
+ if (customFilter) {
85592
+ filters.push(customFilter);
85593
+ }
85594
+ const queryWithFilters = filters.length > 0 ? query.where(and(...filters)) : query;
85595
+ const results = await queryWithFilters;
85596
+ return results.map((row) => ({
85597
+ ...row.derived_positions_view,
85598
+ expand: {
85599
+ p_account: row.exchange_accounts,
85600
+ b_config: this.updateScheduledTrades({
85601
+ scheduled_trades: row.scheduled_trades,
85602
+ exchange_accounts: row.exchange_accounts
85603
+ }),
85604
+ proxy: row.proxies,
85605
+ symbol_config: row.symbol_configs,
85606
+ compound_instance: row.compound_instances,
85607
+ short_compound_strategy: this.updateShortStrategyView(row.short_compound_strategy),
85608
+ watch_instance: row.watch_positions
85609
+ }
85610
+ }));
85611
+ }
85546
85612
  }
85547
85613
 
85548
85614
  // src/db/index.ts
@@ -85556,7 +85622,8 @@ async function initSqliteDb({
85556
85622
  let import_4 = await Promise.resolve().then(() => (init_web2(), exports_web2));
85557
85623
  const turso = import_3.createClient({
85558
85624
  url: syncUrl,
85559
- authToken
85625
+ authToken,
85626
+ intMode: "bigint"
85560
85627
  });
85561
85628
  const db2 = import_4.drizzle(turso);
85562
85629
  const client = {
@@ -72813,6 +72813,12 @@ class AppDatabase {
72813
72813
  return fields.join(", ");
72814
72814
  }
72815
72815
  async fetchCentralPositions(payload) {
72816
+ if (this.drizzlePb) {
72817
+ return this.drizzlePb.fetchCentralPositions({
72818
+ ...payload,
72819
+ email: this.email
72820
+ });
72821
+ }
72816
72822
  const { asset: assetName, symbol, customFilter = "" } = payload;
72817
72823
  const pb = this.pb;
72818
72824
  let symbolFilter = assetName ? `symbol ~ "${assetName}"` : `symbol = "${symbol}"`;
@@ -85111,7 +85117,8 @@ var orderColumns = {
85111
85117
  opposite_qty: real("opposite_qty"),
85112
85118
  avg_entry_price: real("avg_entry_price"),
85113
85119
  avg_price: real("avg_price"),
85114
- avg_qty: real("avg_qty")
85120
+ avg_qty: real("avg_qty"),
85121
+ account_id: text("account_id")
85115
85122
  };
85116
85123
  var orders = sqliteTable("orders", {
85117
85124
  id: text("id").primaryKey(),
@@ -85367,7 +85374,7 @@ class DrizzlePocketbase {
85367
85374
  proxy: row.proxies,
85368
85375
  symbol_config: row.symbol_configs,
85369
85376
  compound_instance: row.compound_instances,
85370
- short_compound_strategy: row.short_compound_strategy,
85377
+ short_compound_strategy: this.updateShortStrategyView(row.short_compound_strategy),
85371
85378
  watch_instance: row.watch_positions
85372
85379
  }
85373
85380
  }));
@@ -85431,6 +85438,15 @@ class DrizzlePocketbase {
85431
85438
  }
85432
85439
  return null;
85433
85440
  }
85441
+ updateShortStrategyView(xx) {
85442
+ if (xx) {
85443
+ return {
85444
+ ...xx,
85445
+ support: xx.support ? JSON.parse(xx.support) : null
85446
+ };
85447
+ }
85448
+ return null;
85449
+ }
85434
85450
  async createOrUpdatePositionConfig(db_position, payload) {
85435
85451
  let config2 = null;
85436
85452
  if (db_position.config) {
@@ -85516,6 +85532,56 @@ class DrizzlePocketbase {
85516
85532
  return result[0];
85517
85533
  }
85518
85534
  async update_db_position(_position, _payload) {}
85535
+ get positionExpand() {
85536
+ const fields = [
85537
+ "b_config",
85538
+ "account_strategy",
85539
+ "p_account",
85540
+ "proxy",
85541
+ "compound_instance.ref",
85542
+ "support",
85543
+ "resistance",
85544
+ "symbol_config",
85545
+ "anchor",
85546
+ "watch_instance",
85547
+ "short_compound_strategy.tracking_account.account"
85548
+ ];
85549
+ return fields.join(", ");
85550
+ }
85551
+ async fetchCentralPositions(payload) {
85552
+ const { asset: assetName, symbol, customFilter = "" } = payload;
85553
+ await this.client.sync();
85554
+ const query = this.db.select().from(derivedPositionView).leftJoin(exchangeAccounts, eq(derivedPositionView.p_account, exchangeAccounts.id)).leftJoin(scheduledTrades, eq(derivedPositionView.b_config, scheduledTrades.id)).leftJoin(proxies, eq(derivedPositionView.proxy, proxies.id)).leftJoin(symbolConfigs, eq(derivedPositionView.symbol_config, symbolConfigs.id)).leftJoin(compoundInstances, eq(derivedPositionView.compound_instance, compoundInstances.id)).leftJoin(shortCompoundStrategy, eq(derivedPositionView.short_compound_strategy, shortCompoundStrategy.id)).leftJoin(watchPositions, eq(derivedPositionView.watch_instance, watchPositions.id));
85555
+ const filters = [];
85556
+ if (assetName) {
85557
+ filters.push(sql`${derivedPositionView.symbol} LIKE ${`${assetName}%`}`);
85558
+ } else if (symbol) {
85559
+ filters.push(eq(lower(derivedPositionView.symbol), symbol.toLowerCase()));
85560
+ }
85561
+ if (payload.email) {
85562
+ filters.push(eq(lower(exchangeAccounts.email), payload.email.toLowerCase()));
85563
+ }
85564
+ if (customFilter) {
85565
+ filters.push(customFilter);
85566
+ }
85567
+ const queryWithFilters = filters.length > 0 ? query.where(and(...filters)) : query;
85568
+ const results = await queryWithFilters;
85569
+ return results.map((row) => ({
85570
+ ...row.derived_positions_view,
85571
+ expand: {
85572
+ p_account: row.exchange_accounts,
85573
+ b_config: this.updateScheduledTrades({
85574
+ scheduled_trades: row.scheduled_trades,
85575
+ exchange_accounts: row.exchange_accounts
85576
+ }),
85577
+ proxy: row.proxies,
85578
+ symbol_config: row.symbol_configs,
85579
+ compound_instance: row.compound_instances,
85580
+ short_compound_strategy: this.updateShortStrategyView(row.short_compound_strategy),
85581
+ watch_instance: row.watch_positions
85582
+ }
85583
+ }));
85584
+ }
85519
85585
  }
85520
85586
 
85521
85587
  // src/db/index.ts
@@ -85529,7 +85595,8 @@ async function initSqliteDb({
85529
85595
  let import_4 = await Promise.resolve().then(() => (init_web2(), exports_web2));
85530
85596
  const turso = import_3.createClient({
85531
85597
  url: syncUrl,
85532
- authToken
85598
+ authToken,
85599
+ intMode: "bigint"
85533
85600
  });
85534
85601
  const db2 = import_4.drizzle(turso);
85535
85602
  const client = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-next.27",
4
+ "version": "0.0.2-next.29",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",