@gbozee/ultimate 0.0.2-5 → 0.0.2-7

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
@@ -117,6 +117,10 @@ export interface BaseExchange {
117
117
  price_places?: string;
118
118
  decimal_places?: string;
119
119
  }): Promise<any>;
120
+ setLeverage(payload: {
121
+ symbol: string;
122
+ leverage: number;
123
+ }): Promise<any>;
120
124
  }
121
125
  export interface BaseSystemFields {
122
126
  id: string;
@@ -324,6 +328,21 @@ export declare class AppDatabase {
324
328
  updated_bullish: BullishMarket[];
325
329
  moved_to_winding: WindingDownMarket[];
326
330
  }>;
331
+ updateSymbolConfigs(payload?: {
332
+ configs: Array<{
333
+ symbol: string;
334
+ support: number;
335
+ leverage: number;
336
+ min_size: number;
337
+ resistance: number;
338
+ price_places: string;
339
+ decimal_places: string;
340
+ }>;
341
+ }): Promise<{
342
+ updated: number;
343
+ created: number;
344
+ } | SymbolConfig[]>;
345
+ unwindSymbolFromDB(symbol: string): Promise<void>;
327
346
  }
328
347
  export interface CodeNode {
329
348
  minimum_pnl: number;
@@ -383,6 +402,7 @@ declare class ExchangeAccount$1 {
383
402
  kind?: "long" | "short";
384
403
  update?: boolean;
385
404
  as_view?: boolean;
405
+ leverage?: number;
386
406
  }): Promise<(PositionsView & {
387
407
  expand?: {
388
408
  config: ScheduledTrade;
@@ -632,6 +652,20 @@ declare class App {
632
652
  moved_to_winding: WindingDownMarket[];
633
653
  }>;
634
654
  getWindingDownMarkets(): Promise<WindingDownMarket[]>;
655
+ updateSymbolConfigs(payload: {
656
+ configs: {
657
+ symbol: string;
658
+ support: number;
659
+ leverage: number;
660
+ min_size: number;
661
+ resistance: number;
662
+ price_places: string;
663
+ decimal_places: string;
664
+ }[];
665
+ }): Promise<{
666
+ updated: number;
667
+ created: number;
668
+ } | SymbolConfig[]>;
635
669
  }
636
670
  export declare function initApp(payload: {
637
671
  db: {
package/dist/index.js CHANGED
@@ -32054,6 +32054,80 @@ class AppDatabase {
32054
32054
  const updated_bullish = await this.pb.collection("bullish_markets").getFullList();
32055
32055
  return { updated_bullish, moved_to_winding };
32056
32056
  }
32057
+ async updateSymbolConfigs(payload) {
32058
+ if (!payload || !payload.configs) {
32059
+ console.log("No payload provided. Fetching all symbol configs...");
32060
+ try {
32061
+ const allConfigs = await this.pb.collection("symbol_configs").getFullList();
32062
+ console.log(`Found ${allConfigs.length} symbol configs.`);
32063
+ return allConfigs;
32064
+ } catch (error) {
32065
+ console.error("Error fetching all symbol configs:", error);
32066
+ throw error;
32067
+ }
32068
+ }
32069
+ console.log(`Processing ${payload.configs.length} symbol config updates/creates...`);
32070
+ let existingConfigsMap = new Map;
32071
+ try {
32072
+ const existingConfigsList = await this.pb.collection("symbol_configs").getFullList();
32073
+ existingConfigsMap = new Map(existingConfigsList.map((c) => [c.symbol.toLowerCase(), c]));
32074
+ console.log(`Found ${existingConfigsMap.size} existing symbol configs in DB.`);
32075
+ } catch (error) {
32076
+ console.error("Error fetching existing symbol configs:", error);
32077
+ }
32078
+ let updatedCount = 0;
32079
+ let createdCount = 0;
32080
+ for (const config of payload.configs) {
32081
+ const lowerCaseSymbol = config.symbol.toLowerCase();
32082
+ const existingConfig = existingConfigsMap.get(lowerCaseSymbol);
32083
+ const dataToUpsert = {
32084
+ symbol: config.symbol,
32085
+ support: config.support,
32086
+ resistance: config.resistance,
32087
+ leverage: config.leverage,
32088
+ min_size: config.min_size,
32089
+ price_places: config.price_places,
32090
+ decimal_places: config.decimal_places
32091
+ };
32092
+ if (existingConfig) {
32093
+ try {
32094
+ if (Object.keys(dataToUpsert).some((key) => dataToUpsert[key] !== existingConfig[key])) {
32095
+ console.log(`Updating symbol config for: ${config.symbol}`);
32096
+ await this.pb.collection("symbol_configs").update(existingConfig.id, dataToUpsert);
32097
+ updatedCount++;
32098
+ } else {
32099
+ console.log(`No changes detected for symbol config: ${config.symbol}. Skipping update.`);
32100
+ }
32101
+ } catch (updateError) {
32102
+ console.error(`Error updating symbol config for ${config.symbol}:`, updateError);
32103
+ }
32104
+ } else {
32105
+ try {
32106
+ console.log(`Creating new symbol config for: ${config.symbol}`);
32107
+ await this.pb.collection("symbol_configs").create(dataToUpsert);
32108
+ createdCount++;
32109
+ } catch (createError) {
32110
+ console.error(`Error creating symbol config for ${config.symbol}:`, createError);
32111
+ }
32112
+ }
32113
+ }
32114
+ console.log(`Finished processing symbol configs. Updated: ${updatedCount}, Created: ${createdCount}`);
32115
+ return { updated: updatedCount, created: createdCount };
32116
+ }
32117
+ async unwindSymbolFromDB(symbol) {
32118
+ const symbol_configs = await this.pb.collection("symbol_configs").getFullList({
32119
+ filter: `symbol:lower="${symbol.toLowerCase()}"`
32120
+ });
32121
+ if (symbol_configs.length > 0) {
32122
+ await this.pb.collection("symbol_configs").delete(symbol_configs[0].id);
32123
+ }
32124
+ const found_unwinding_market = await this.pb.collection("unwinding_markets").getFullList({
32125
+ filter: `symbol:lower="${symbol.toLowerCase()}"`
32126
+ });
32127
+ if (found_unwinding_market.length > 0) {
32128
+ await this.pb.collection("unwinding_markets").delete(found_unwinding_market[0].id);
32129
+ }
32130
+ }
32057
32131
  }
32058
32132
 
32059
32133
  // src/exchanges/binance.ts
@@ -33624,6 +33698,9 @@ class BinanceExchange {
33624
33698
  decimal_places: payload.decimal_places
33625
33699
  });
33626
33700
  }
33701
+ async setLeverage(payload) {
33702
+ return await this.client.setLeverage(payload);
33703
+ }
33627
33704
  }
33628
33705
 
33629
33706
  // src/exchanges/bybit.ts
@@ -34228,6 +34305,14 @@ class BybitExchange {
34228
34305
  decimal_places: payload.decimal_places
34229
34306
  });
34230
34307
  }
34308
+ async setLeverage(payload) {
34309
+ return await this.client.setLeverage({
34310
+ category: "linear",
34311
+ symbol: payload.symbol,
34312
+ buyLeverage: payload.leverage.toString(),
34313
+ sellLeverage: payload.leverage.toString()
34314
+ });
34315
+ }
34231
34316
  }
34232
34317
 
34233
34318
  // src/helpers/accounts.ts
@@ -34913,6 +34998,9 @@ class ExchangeAccount {
34913
34998
  return db_positions2;
34914
34999
  }
34915
35000
  const active_account = await this.getActiveAccount(symbol);
35001
+ if (options.leverage) {
35002
+ await this.exchange.setLeverage({ symbol, leverage: options.leverage });
35003
+ }
34916
35004
  const db_positions = await this.app_db.createOrUpdatePositions(this.instance, {
34917
35005
  symbol,
34918
35006
  long_position: active_account.position.long,
@@ -35566,6 +35654,9 @@ class App {
35566
35654
  async getWindingDownMarkets() {
35567
35655
  return await this.app_db.getWindingDownMarkets();
35568
35656
  }
35657
+ async updateSymbolConfigs(payload) {
35658
+ return await this.app_db.updateSymbolConfigs(payload);
35659
+ }
35569
35660
  }
35570
35661
  async function initApp(payload) {
35571
35662
  const pb = await initPocketBaseClient(payload.db);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gbozee/ultimate",
3
3
  "type": "module",
4
- "version": "0.0.2-5",
4
+ "version": "0.0.2-7",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",