fixed web-api
This commit is contained in:
parent
46de1755e9
commit
96f515a76b
3 changed files with 71 additions and 13 deletions
|
|
@ -2,6 +2,58 @@
|
|||
"service": {
|
||||
"name": "web-api",
|
||||
"port": 4000,
|
||||
"environment": "development"
|
||||
"host": "0.0.0.0",
|
||||
"healthCheckPath": "/health",
|
||||
"metricsPath": "/metrics",
|
||||
"shutdownTimeout": 30000,
|
||||
"cors": {
|
||||
"enabled": true,
|
||||
"origin": ["http://localhost:4200", "http://localhost:3000", "http://localhost:3002"],
|
||||
"credentials": true
|
||||
}
|
||||
},
|
||||
"logging": {
|
||||
"level": "info",
|
||||
"format": "json"
|
||||
},
|
||||
"database": {
|
||||
"postgres": {
|
||||
"host": "localhost",
|
||||
"port": 5432,
|
||||
"database": "trading_bot",
|
||||
"user": "trading_user",
|
||||
"password": "trading_pass_dev",
|
||||
"ssl": false,
|
||||
"poolSize": 10,
|
||||
"connectionTimeout": 30000,
|
||||
"idleTimeout": 10000
|
||||
},
|
||||
"questdb": {
|
||||
"host": "localhost",
|
||||
"ilpPort": 9009,
|
||||
"httpPort": 9000,
|
||||
"pgPort": 8812,
|
||||
"database": "questdb",
|
||||
"user": "admin",
|
||||
"password": "quest",
|
||||
"bufferSize": 65536,
|
||||
"flushInterval": 1000
|
||||
},
|
||||
"mongodb": {
|
||||
"host": "localhost",
|
||||
"port": 27017,
|
||||
"database": "stock",
|
||||
"user": "trading_admin",
|
||||
"password": "trading_mongo_dev",
|
||||
"authSource": "admin",
|
||||
"poolSize": 10
|
||||
},
|
||||
"dragonfly": {
|
||||
"host": "localhost",
|
||||
"port": 6379,
|
||||
"db": 0,
|
||||
"maxRetries": 3,
|
||||
"retryDelay": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
import { Hono } from 'hono';
|
||||
import { cors } from 'hono/cors';
|
||||
import { initializeConfig, getServiceConfig, getLoggingConfig } from '@stock-bot/config-new';
|
||||
import { initializeConfig, getServiceConfig, getLoggingConfig, getDatabaseConfig } from '@stock-bot/config-new';
|
||||
import { getLogger, shutdownLoggers, setLoggerConfig } from '@stock-bot/logger';
|
||||
import { createAndConnectMongoDBClient, MongoDBClient } from '@stock-bot/mongodb-client';
|
||||
import { createAndConnectPostgreSQLClient, PostgreSQLClient } from '@stock-bot/postgres-client';
|
||||
|
|
@ -16,6 +16,7 @@ import { healthRoutes } from './routes/health.routes';
|
|||
// Initialize configuration
|
||||
await initializeConfig();
|
||||
const serviceConfig = getServiceConfig();
|
||||
const databaseConfig = getDatabaseConfig();
|
||||
|
||||
// Initialize logger with config
|
||||
const loggingConfig = getLoggingConfig();
|
||||
|
|
@ -75,16 +76,16 @@ async function initializeServices() {
|
|||
try {
|
||||
// Initialize MongoDB client
|
||||
logger.info('Connecting to MongoDB...');
|
||||
const mongoConfig = serviceConfig.database.mongodb;
|
||||
const mongoConfig = databaseConfig.mongodb;
|
||||
mongoClient = await createAndConnectMongoDBClient({
|
||||
uri: mongoConfig.uri,
|
||||
database: mongoConfig.database,
|
||||
host: 'localhost',
|
||||
port: 27017,
|
||||
host: mongoConfig.host,
|
||||
port: mongoConfig.port,
|
||||
timeouts: {
|
||||
connectTimeout: mongoConfig.connectionTimeout || 30000,
|
||||
connectTimeout: 30000,
|
||||
socketTimeout: 30000,
|
||||
serverSelectionTimeout: mongoConfig.serverSelectionTimeout || 5000,
|
||||
serverSelectionTimeout: 5000,
|
||||
},
|
||||
});
|
||||
setMongoDBClient(mongoClient);
|
||||
|
|
@ -92,17 +93,17 @@ async function initializeServices() {
|
|||
|
||||
// Initialize PostgreSQL client
|
||||
logger.info('Connecting to PostgreSQL...');
|
||||
const pgConfig = serviceConfig.database.postgres;
|
||||
const pgConfig = databaseConfig.postgres;
|
||||
postgresClient = await createAndConnectPostgreSQLClient({
|
||||
host: pgConfig.host,
|
||||
port: pgConfig.port,
|
||||
database: pgConfig.database,
|
||||
username: pgConfig.username,
|
||||
username: pgConfig.user,
|
||||
password: pgConfig.password,
|
||||
poolSettings: {
|
||||
min: 2,
|
||||
max: pgConfig.maxConnections || 10,
|
||||
idleTimeoutMillis: 30000,
|
||||
max: pgConfig.poolSize || 10,
|
||||
idleTimeoutMillis: pgConfig.idleTimeout || 30000,
|
||||
},
|
||||
});
|
||||
setPostgreSQLClient(postgresClient);
|
||||
|
|
|
|||
|
|
@ -15,8 +15,13 @@ import {
|
|||
const logger = getLogger('exchange-service');
|
||||
|
||||
export class ExchangeService {
|
||||
private postgresClient = getPostgreSQLClient();
|
||||
private mongoClient = getMongoDBClient();
|
||||
private get postgresClient() {
|
||||
return getPostgreSQLClient();
|
||||
}
|
||||
|
||||
private get mongoClient() {
|
||||
return getMongoDBClient();
|
||||
}
|
||||
|
||||
// Exchanges
|
||||
async getAllExchanges(): Promise<ExchangeWithMappings[]> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue