diff --git a/server/src/app.module.ts b/server/src/app.module.ts index 545fd307..e9276410 100644 --- a/server/src/app.module.ts +++ b/server/src/app.module.ts @@ -129,7 +129,7 @@ dotenv.config(); GrowdataMarketMakingPair, IndicatorStrategyHistory, ], - synchronize: false, + synchronize: true, ssl: process.env.POSTGRES_SSL === 'true', }), ScheduleModule.forRoot(), diff --git a/server/src/common/entities/strategy-instances.entity.ts b/server/src/common/entities/strategy-instances.entity.ts index c7fb404a..aafd0098 100644 --- a/server/src/common/entities/strategy-instances.entity.ts +++ b/server/src/common/entities/strategy-instances.entity.ts @@ -25,9 +25,6 @@ export class StrategyInstance { @Column() strategyType: string; - @Column() - startPrice: number; - @Column('json') parameters: Record; diff --git a/server/src/modules/exchangeInit/exchangeInit.service.ts b/server/src/modules/exchangeInit/exchangeInit.service.ts index 5d7a8407..15cc13bc 100644 --- a/server/src/modules/exchangeInit/exchangeInit.service.ts +++ b/server/src/modules/exchangeInit/exchangeInit.service.ts @@ -88,6 +88,27 @@ export class ExchangeInitService { return ex; } + private async loadMarketsWithRetry( + exchange: ccxt.Exchange, + exName: string, + label: string, + maxRetries = 3, + ) { + for (let attempt = 1; attempt <= maxRetries; attempt++) { + try { + await exchange.loadMarkets(); + return; + } catch (e: any) { + this.logger.warn( + `[${exName}:${label}] loadMarkets attempt ${attempt}/${maxRetries} failed: ${ + e?.message ?? e + }`, + ); + if (attempt === maxRetries) throw e; + await new Promise((r) => setTimeout(r, 2000 * attempt)); + } + } + } /** quick targeted diagnostics to catch auth/time issues early */ private async postInitDiagnostics( exName: string, @@ -286,7 +307,7 @@ export class ExchangeInitService { } // Preload markets to configure symbol routing/types - await exchange.loadMarkets(); + await this.loadMarketsWithRetry(exchange, exName, acct.label); // ProBit requires signIn for private endpoints if (cfg.name === 'probit' && exchange.has?.signIn) { diff --git a/server/src/modules/strategy/dex-volume.strategy.service.ts b/server/src/modules/strategy/dex-volume.strategy.service.ts index 4a3b2208..758887eb 100644 --- a/server/src/modules/strategy/dex-volume.strategy.service.ts +++ b/server/src/modules/strategy/dex-volume.strategy.service.ts @@ -78,7 +78,7 @@ export class DexVolumeStrategyService { strategyType: 'dexVolume', parameters: dto, status: 'running', - startPrice: 0, + // startPrice: 0, }), ); diff --git a/server/src/modules/strategy/strategy.service.ts b/server/src/modules/strategy/strategy.service.ts index dad2c4ad..ee7eea15 100644 --- a/server/src/modules/strategy/strategy.service.ts +++ b/server/src/modules/strategy/strategy.service.ts @@ -16,7 +16,7 @@ * - Enums: PriceSourceType for specifying the price source type in market making. * * Methods: - * + *x * - constructor: Initializes the service with injected dependencies and sets up exchange instances. * * - initializeExchanges(): Sets up the exchange instances with the provided API keys and secrets. @@ -258,7 +258,7 @@ export class StrategyService { ); } else { // Otherwise, create a new instance - const exchange = this.exchangeInitService.getExchange(exchangeAName); + // const exchange = this.exchangeInitService.getExchange(exchangeAName); strategyInstance = this.strategyInstanceRepository.create({ strategyKey, userId, @@ -266,9 +266,9 @@ export class StrategyService { strategyType: 'arbitrage', parameters: strategyParamsDto, status: 'running', - startPrice: await exchange - .fetchTicker(pair) - .then((ticker) => ticker.last), + // startPrice: await exchange + // .fetchTicker(pair) + // .then((ticker) => ticker.last), }); await this.strategyInstanceRepository.save(strategyInstance); } @@ -401,8 +401,8 @@ export class StrategyService { const minAmt = market.limits?.amount?.min ?? 0; const minPrice = market.limits?.price?.min ?? 0; - const startTicker = await ex1.fetchTicker(symbol); - const startPrice = Number(startTicker.last); + // const startTicker = await ex1.fetchTicker(symbol); + // const startPrice = Number(startTicker.last); const parameters = { exchangeName, @@ -425,9 +425,9 @@ export class StrategyService { strategyType: 'volume', parameters, status: 'running', - startPrice, + // startPrice, }); - // await this.strategyInstanceRepository.save(strategyInstance); + await this.strategyInstanceRepository.save(strategyInstance); } else { await this.strategyInstanceRepository.update( { strategyKey }, @@ -1711,8 +1711,8 @@ export class StrategyService { ); } else { // The exchange we place orders on - const executionExchange = - this.exchangeInitService.getExchange(exchangeName); + // const executionExchange = + // this.exchangeInitService.getExchange(exchangeName); strategyInstance = this.strategyInstanceRepository.create({ strategyKey, @@ -1722,15 +1722,15 @@ export class StrategyService { parameters: strategyParamsDto, status: 'running', // For startPrice, we fetch from the oracle exchange if provided, else the executionExchange - startPrice: await (async () => { - const priceExchange = oracleExchangeName - ? this.exchangeInitService.getExchange(oracleExchangeName) - : executionExchange; - const ticker = await priceExchange.fetchTicker(pair); - return ticker.last; - })(), + // startPrice: await (async () => { + // const priceExchange = oracleExchangeName + // ? this.exchangeInitService.getExchange(oracleExchangeName) + // : executionExchange; + // const ticker = await priceExchange.fetchTicker(pair); + // return ticker.last; + // })(), }); - // await this.strategyInstanceRepository.save(strategyInstance); + await this.strategyInstanceRepository.save(strategyInstance); } } @@ -1782,19 +1782,14 @@ export class StrategyService { floorPrice?: number, oracleExchangeName?: string, // optional ) { - // 1. Determine which exchange to use for pricing - const priceExchange = oracleExchangeName - ? this.exchangeInitService.getExchange(oracleExchangeName) - : this.exchangeInitService.getExchange(executionExchangeName); - - // 2. Execution exchange is always the main exchangeName + // 1. Execution exchange is always the main exchangeName const executionExchange = this.exchangeInitService.getExchange( executionExchangeName, ); - // 3. Fetch the current market price from the selected price exchange + // 2. Fetch the current market price from the selected price exchange const priceSource = await this.getPriceSource( - priceExchange.id, // use priceExchange for data + oracleExchangeName, // use priceExchange for data pair, priceSourceType, );