Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ dotenv.config();
GrowdataMarketMakingPair,
IndicatorStrategyHistory,
],
synchronize: false,
synchronize: true,
ssl: process.env.POSTGRES_SSL === 'true',
}),
ScheduleModule.forRoot(),
Expand Down
3 changes: 0 additions & 3 deletions server/src/common/entities/strategy-instances.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export class StrategyInstance {
@Column()
strategyType: string;

@Column()
startPrice: number;

@Column('json')
parameters: Record<string, any>;

Expand Down
23 changes: 22 additions & 1 deletion server/src/modules/exchangeInit/exchangeInit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/modules/strategy/dex-volume.strategy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class DexVolumeStrategyService {
strategyType: 'dexVolume',
parameters: dto,
status: 'running',
startPrice: 0,
// startPrice: 0,
}),
);

Expand Down
49 changes: 22 additions & 27 deletions server/src/modules/strategy/strategy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -258,17 +258,17 @@ 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,
clientId,
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);
}
Expand Down Expand Up @@ -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,
Expand All @@ -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 },
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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,
);
Expand Down
Loading