@gbozee/ultimate 0.0.2-18 → 0.0.2-19

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.d.ts CHANGED
@@ -125,6 +125,9 @@ export interface BaseExchange {
125
125
  symbol: string;
126
126
  limit?: number;
127
127
  }): Promise<any>;
128
+ checkDelistedMovers(payload: {
129
+ movePercent: number;
130
+ }): Promise<any>;
128
131
  }
129
132
  export interface BaseSystemFields {
130
133
  id: string;
@@ -404,7 +407,7 @@ export type AppConfig = {
404
407
  };
405
408
  declare class ExchangeAccount$1 {
406
409
  private instance;
407
- private exchange;
410
+ exchange: BaseExchange;
408
411
  private app_db;
409
412
  constructor(payload: ExchangeType, options: {
410
413
  exchange: BaseExchange;
@@ -700,6 +703,14 @@ declare class App {
700
703
  }>;
701
704
  updateAllAccountWithSymbols(with_positions?: boolean): Promise<void>;
702
705
  windDownSymbol(symbol: string): Promise<boolean>;
706
+ fetchAndUpdateTopMovers(payload: {
707
+ movePercent: number;
708
+ account: ExchangeType;
709
+ totalRisk: number;
710
+ }): Promise<{
711
+ updated_bullish: BullishMarket[];
712
+ moved_to_winding: WindingDownMarket[];
713
+ }>;
703
714
  }
704
715
  export declare function initApp(payload: {
705
716
  db: {
@@ -712,6 +723,7 @@ export declare function initApp(payload: {
712
723
  api_secret: string;
713
724
  }>;
714
725
  }): Promise<App>;
726
+ export declare function initialize(): Promise<App>;
715
727
 
716
728
  export {
717
729
  ExchangeAccount$1 as ExchangeAccount,
package/dist/index.js CHANGED
@@ -34126,6 +34126,43 @@ function calculateSupportResistance(klines) {
34126
34126
  const resistance = Math.max(...highs);
34127
34127
  return { support, resistance };
34128
34128
  }
34129
+ async function getTopMovers(payload) {
34130
+ const { client, percentThreshold = 20 } = payload;
34131
+ const data = await client.get24hrChangeStatistics();
34132
+ const movers = data.filter((s2) => parseFloat(s2.priceChangePercent) >= percentThreshold).map((s2) => ({
34133
+ symbol: s2.symbol,
34134
+ priceChangePercent: parseFloat(s2.priceChangePercent),
34135
+ lastPrice: parseFloat(s2.lastPrice),
34136
+ highPrice: parseFloat(s2.highPrice),
34137
+ lowPrice: parseFloat(s2.lowPrice),
34138
+ volume: parseFloat(s2.volume)
34139
+ })).sort((a, b) => Math.abs(b.priceChangePercent) - Math.abs(a.priceChangePercent));
34140
+ return movers;
34141
+ }
34142
+ async function isSymbolActive(payload) {
34143
+ const { client, symbol } = payload;
34144
+ try {
34145
+ const depth_data = await client.getOrderBook({
34146
+ symbol,
34147
+ limit: 5
34148
+ });
34149
+ if (depth_data.asks.length === 0 && depth_data.bids.length === 0) {
34150
+ return false;
34151
+ }
34152
+ return true;
34153
+ } catch (err) {
34154
+ if (err.response && err.response.data && err.response.data.code === -1121) {
34155
+ return false;
34156
+ }
34157
+ console.error(`Error checking ${symbol}:`, err.message);
34158
+ return false;
34159
+ }
34160
+ }
34161
+ async function getActiveSymbols(payload) {
34162
+ const { client } = payload;
34163
+ const response = await client.getExchangeInfo();
34164
+ return response.symbols;
34165
+ }
34129
34166
 
34130
34167
  class BinanceExchange {
34131
34168
  client;
@@ -34274,8 +34311,8 @@ class BinanceExchange {
34274
34311
  return maxLeverage;
34275
34312
  }
34276
34313
  async generateConfig(payload) {
34277
- const response = await this.client.getExchangeInfo();
34278
- const symbols = response.symbols;
34314
+ const symbols = await getActiveSymbols({ client: this.client });
34315
+ console.log("symbols", symbols);
34279
34316
  const { symbol, limit = 5 } = payload;
34280
34317
  const klines = await getWeeklyKlines({
34281
34318
  client: this.client,
@@ -34306,6 +34343,29 @@ class BinanceExchange {
34306
34343
  };
34307
34344
  return configObj;
34308
34345
  }
34346
+ async checkDelistedMovers(payload) {
34347
+ const movers = await getTopMovers({
34348
+ client: this.client,
34349
+ percentThreshold: payload.movePercent
34350
+ });
34351
+ const _activeSymbols = await getActiveSymbols({ client: this.client });
34352
+ const activeSymbols = _activeSymbols.map((s2) => s2.symbol);
34353
+ const delisted = movers.map((x) => x.symbol).filter((symbol) => !activeSymbols.includes(symbol));
34354
+ const validMovers = movers.filter((m) => !delisted.includes(m.symbol)).filter((m) => activeSymbols.includes(m.symbol));
34355
+ const activeMovers = [];
34356
+ for (const m of validMovers) {
34357
+ const isActive = await isSymbolActive({
34358
+ client: this.client,
34359
+ symbol: m.symbol
34360
+ });
34361
+ if (isActive) {
34362
+ activeMovers.push(m);
34363
+ }
34364
+ }
34365
+ console.log(`Top movers:`, movers);
34366
+ console.log(`Delisted movers:`, delisted);
34367
+ return { movers: activeMovers, delisted };
34368
+ }
34309
34369
  }
34310
34370
  function getPricePlaces(target) {
34311
34371
  const numStr = target.toString();
@@ -34928,6 +34988,8 @@ class BybitExchange {
34928
34988
  }
34929
34989
  async generateConfig(payload) {
34930
34990
  }
34991
+ async checkDelistedMovers(payload) {
34992
+ }
34931
34993
  }
34932
34994
 
34933
34995
  // src/helpers/accounts.ts
@@ -36575,6 +36637,20 @@ class App {
36575
36637
  }
36576
36638
  }
36577
36639
  }
36640
+ async fetchAndUpdateTopMovers(payload) {
36641
+ const exchange_account = await this.getExchangeAccount(payload.account);
36642
+ const { movers } = await exchange_account.exchange.checkDelistedMovers({
36643
+ movePercent: payload.movePercent
36644
+ });
36645
+ const result = await this.updateTopMovers({
36646
+ new_markets: movers.map((m) => ({
36647
+ symbol: m.symbol,
36648
+ percent: m.priceChangePercent
36649
+ })),
36650
+ totalRisk: payload.totalRisk
36651
+ });
36652
+ return result;
36653
+ }
36578
36654
  }
36579
36655
  async function initApp(payload) {
36580
36656
  const pb = await initPocketBaseClient(payload.db);
@@ -36582,7 +36658,50 @@ async function initApp(payload) {
36582
36658
  const app = new App(app_db, payload.getCredentials);
36583
36659
  return app;
36584
36660
  }
36661
+ async function getCredentials(account, exchange) {
36662
+ console.log(`Fetching credentials for account: ${account}, exchange: ${exchange}`);
36663
+ let apiKey;
36664
+ let apiSecret;
36665
+ switch (account) {
36666
+ case "sub_account":
36667
+ apiKey = process.env.SUB_ACCOUNT_API_KEY;
36668
+ apiSecret = process.env.SUB_ACCOUNT_API_SECRET;
36669
+ break;
36670
+ case "tola_sub_account":
36671
+ apiKey = process.env.TOLA_SUB_ACCOUNT_API_KEY;
36672
+ apiSecret = process.env.TOLA_SUB_ACCOUNT_API_SECRET;
36673
+ break;
36674
+ case "gbozee1_sub_account":
36675
+ apiKey = process.env.GBOZEE1_SUB_ACCOUNT_API_KEY;
36676
+ apiSecret = process.env.GBOZEE1_SUB_ACCOUNT_API_SECRET;
36677
+ break;
36678
+ case "main_account":
36679
+ default:
36680
+ apiKey = process.env.MAIN_ACCOUNT_API_KEY;
36681
+ apiSecret = process.env.MAIN_ACCOUNT_API_SECRET;
36682
+ break;
36683
+ }
36684
+ if (!apiKey || !apiSecret) {
36685
+ throw new Error(`Missing API Key or Secret for account '${account}' in .env file. Please check your environment variables.`);
36686
+ }
36687
+ return {
36688
+ api_key: apiKey,
36689
+ api_secret: apiSecret
36690
+ };
36691
+ }
36692
+ async function initialize() {
36693
+ const app = await initApp({
36694
+ db: {
36695
+ host: process.env.POCKETBASE_HOST,
36696
+ email: process.env.POCKETBASE_EMAIL,
36697
+ password: process.env.POCKETBASE_PASSWORD
36698
+ },
36699
+ getCredentials: (account, exchange) => getCredentials
36700
+ });
36701
+ return app;
36702
+ }
36585
36703
  export {
36704
+ initialize,
36586
36705
  initApp,
36587
36706
  ExchangeAccount,
36588
36707
  AppDatabase
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-18",
4
+ "version": "0.0.2-19",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -12,6 +12,8 @@
12
12
  "require": "./dist/index.cjs"
13
13
  },
14
14
  "scripts": {
15
+ "trigger:deploy": "npx trigger.dev@latest deploy",
16
+ "trigger:dev": "npx trigger.dev@latest dev",
15
17
  "yarn:publish": "yarn publish --prerelease",
16
18
  "build": "bun run build.ts",
17
19
  "prepublishOnly": "bun run build",