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": {
|
"service": {
|
||||||
"name": "web-api",
|
"name": "web-api",
|
||||||
"port": 4000,
|
"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 { Hono } from 'hono';
|
||||||
import { cors } from 'hono/cors';
|
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 { getLogger, shutdownLoggers, setLoggerConfig } from '@stock-bot/logger';
|
||||||
import { createAndConnectMongoDBClient, MongoDBClient } from '@stock-bot/mongodb-client';
|
import { createAndConnectMongoDBClient, MongoDBClient } from '@stock-bot/mongodb-client';
|
||||||
import { createAndConnectPostgreSQLClient, PostgreSQLClient } from '@stock-bot/postgres-client';
|
import { createAndConnectPostgreSQLClient, PostgreSQLClient } from '@stock-bot/postgres-client';
|
||||||
|
|
@ -16,6 +16,7 @@ import { healthRoutes } from './routes/health.routes';
|
||||||
// Initialize configuration
|
// Initialize configuration
|
||||||
await initializeConfig();
|
await initializeConfig();
|
||||||
const serviceConfig = getServiceConfig();
|
const serviceConfig = getServiceConfig();
|
||||||
|
const databaseConfig = getDatabaseConfig();
|
||||||
|
|
||||||
// Initialize logger with config
|
// Initialize logger with config
|
||||||
const loggingConfig = getLoggingConfig();
|
const loggingConfig = getLoggingConfig();
|
||||||
|
|
@ -75,16 +76,16 @@ async function initializeServices() {
|
||||||
try {
|
try {
|
||||||
// Initialize MongoDB client
|
// Initialize MongoDB client
|
||||||
logger.info('Connecting to MongoDB...');
|
logger.info('Connecting to MongoDB...');
|
||||||
const mongoConfig = serviceConfig.database.mongodb;
|
const mongoConfig = databaseConfig.mongodb;
|
||||||
mongoClient = await createAndConnectMongoDBClient({
|
mongoClient = await createAndConnectMongoDBClient({
|
||||||
uri: mongoConfig.uri,
|
uri: mongoConfig.uri,
|
||||||
database: mongoConfig.database,
|
database: mongoConfig.database,
|
||||||
host: 'localhost',
|
host: mongoConfig.host,
|
||||||
port: 27017,
|
port: mongoConfig.port,
|
||||||
timeouts: {
|
timeouts: {
|
||||||
connectTimeout: mongoConfig.connectionTimeout || 30000,
|
connectTimeout: 30000,
|
||||||
socketTimeout: 30000,
|
socketTimeout: 30000,
|
||||||
serverSelectionTimeout: mongoConfig.serverSelectionTimeout || 5000,
|
serverSelectionTimeout: 5000,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setMongoDBClient(mongoClient);
|
setMongoDBClient(mongoClient);
|
||||||
|
|
@ -92,17 +93,17 @@ async function initializeServices() {
|
||||||
|
|
||||||
// Initialize PostgreSQL client
|
// Initialize PostgreSQL client
|
||||||
logger.info('Connecting to PostgreSQL...');
|
logger.info('Connecting to PostgreSQL...');
|
||||||
const pgConfig = serviceConfig.database.postgres;
|
const pgConfig = databaseConfig.postgres;
|
||||||
postgresClient = await createAndConnectPostgreSQLClient({
|
postgresClient = await createAndConnectPostgreSQLClient({
|
||||||
host: pgConfig.host,
|
host: pgConfig.host,
|
||||||
port: pgConfig.port,
|
port: pgConfig.port,
|
||||||
database: pgConfig.database,
|
database: pgConfig.database,
|
||||||
username: pgConfig.username,
|
username: pgConfig.user,
|
||||||
password: pgConfig.password,
|
password: pgConfig.password,
|
||||||
poolSettings: {
|
poolSettings: {
|
||||||
min: 2,
|
min: 2,
|
||||||
max: pgConfig.maxConnections || 10,
|
max: pgConfig.poolSize || 10,
|
||||||
idleTimeoutMillis: 30000,
|
idleTimeoutMillis: pgConfig.idleTimeout || 30000,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
setPostgreSQLClient(postgresClient);
|
setPostgreSQLClient(postgresClient);
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,13 @@ import {
|
||||||
const logger = getLogger('exchange-service');
|
const logger = getLogger('exchange-service');
|
||||||
|
|
||||||
export class ExchangeService {
|
export class ExchangeService {
|
||||||
private postgresClient = getPostgreSQLClient();
|
private get postgresClient() {
|
||||||
private mongoClient = getMongoDBClient();
|
return getPostgreSQLClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
private get mongoClient() {
|
||||||
|
return getMongoDBClient();
|
||||||
|
}
|
||||||
|
|
||||||
// Exchanges
|
// Exchanges
|
||||||
async getAllExchanges(): Promise<ExchangeWithMappings[]> {
|
async getAllExchanges(): Promise<ExchangeWithMappings[]> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue