running prettier for cleanup
This commit is contained in:
parent
fe7733aeb5
commit
d85cd58acd
151 changed files with 29158 additions and 27966 deletions
|
|
@ -1,97 +1,101 @@
|
|||
import { Hono } from 'hono';
|
||||
import { serve } from '@hono/node-server';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { config } from '@stock-bot/config';
|
||||
// import { BrokerInterface } from './broker/interface.ts';
|
||||
// import { OrderManager } from './execution/order-manager.ts';
|
||||
// import { RiskManager } from './execution/risk-manager.ts';
|
||||
|
||||
const app = new Hono();
|
||||
const logger = getLogger('execution-service');
|
||||
// Health check endpoint
|
||||
app.get('/health', (c) => {
|
||||
return c.json({
|
||||
status: 'healthy',
|
||||
service: 'execution-service',
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
});
|
||||
|
||||
// Order execution endpoints
|
||||
app.post('/orders/execute', async (c) => {
|
||||
try {
|
||||
const orderRequest = await c.req.json();
|
||||
logger.info('Received order execution request', orderRequest);
|
||||
|
||||
// TODO: Validate order and execute
|
||||
return c.json({
|
||||
orderId: `order_${Date.now()}`,
|
||||
status: 'pending',
|
||||
message: 'Order submitted for execution'
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Order execution failed', error);
|
||||
return c.json({ error: 'Order execution failed' }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/orders/:orderId/status', async (c) => {
|
||||
const orderId = c.req.param('orderId');
|
||||
|
||||
try {
|
||||
// TODO: Get order status from broker
|
||||
return c.json({
|
||||
orderId,
|
||||
status: 'filled',
|
||||
executedAt: new Date().toISOString()
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Failed to get order status', error);
|
||||
return c.json({ error: 'Failed to get order status' }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/orders/:orderId/cancel', async (c) => {
|
||||
const orderId = c.req.param('orderId');
|
||||
|
||||
try {
|
||||
// TODO: Cancel order with broker
|
||||
return c.json({
|
||||
orderId,
|
||||
status: 'cancelled',
|
||||
cancelledAt: new Date().toISOString()
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Failed to cancel order', error);
|
||||
return c.json({ error: 'Failed to cancel order' }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
// Risk management endpoints
|
||||
app.get('/risk/position/:symbol', async (c) => {
|
||||
const symbol = c.req.param('symbol');
|
||||
|
||||
try {
|
||||
// TODO: Get position risk metrics
|
||||
return c.json({
|
||||
symbol,
|
||||
position: 100,
|
||||
exposure: 10000,
|
||||
risk: 'low'
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Failed to get position risk', error);
|
||||
return c.json({ error: 'Failed to get position risk' }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
const port = config.EXECUTION_SERVICE_PORT || 3004;
|
||||
|
||||
logger.info(`Starting execution service on port ${port}`);
|
||||
|
||||
serve({
|
||||
fetch: app.fetch,
|
||||
port
|
||||
}, (info) => {
|
||||
logger.info(`Execution service is running on port ${info.port}`);
|
||||
});
|
||||
import { serve } from '@hono/node-server';
|
||||
import { Hono } from 'hono';
|
||||
import { config } from '@stock-bot/config';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
// import { BrokerInterface } from './broker/interface.ts';
|
||||
// import { OrderManager } from './execution/order-manager.ts';
|
||||
// import { RiskManager } from './execution/risk-manager.ts';
|
||||
|
||||
const app = new Hono();
|
||||
const logger = getLogger('execution-service');
|
||||
// Health check endpoint
|
||||
app.get('/health', c => {
|
||||
return c.json({
|
||||
status: 'healthy',
|
||||
service: 'execution-service',
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
});
|
||||
|
||||
// Order execution endpoints
|
||||
app.post('/orders/execute', async c => {
|
||||
try {
|
||||
const orderRequest = await c.req.json();
|
||||
logger.info('Received order execution request', orderRequest);
|
||||
|
||||
// TODO: Validate order and execute
|
||||
return c.json({
|
||||
orderId: `order_${Date.now()}`,
|
||||
status: 'pending',
|
||||
message: 'Order submitted for execution',
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Order execution failed', error);
|
||||
return c.json({ error: 'Order execution failed' }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/orders/:orderId/status', async c => {
|
||||
const orderId = c.req.param('orderId');
|
||||
|
||||
try {
|
||||
// TODO: Get order status from broker
|
||||
return c.json({
|
||||
orderId,
|
||||
status: 'filled',
|
||||
executedAt: new Date().toISOString(),
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Failed to get order status', error);
|
||||
return c.json({ error: 'Failed to get order status' }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/orders/:orderId/cancel', async c => {
|
||||
const orderId = c.req.param('orderId');
|
||||
|
||||
try {
|
||||
// TODO: Cancel order with broker
|
||||
return c.json({
|
||||
orderId,
|
||||
status: 'cancelled',
|
||||
cancelledAt: new Date().toISOString(),
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Failed to cancel order', error);
|
||||
return c.json({ error: 'Failed to cancel order' }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
// Risk management endpoints
|
||||
app.get('/risk/position/:symbol', async c => {
|
||||
const symbol = c.req.param('symbol');
|
||||
|
||||
try {
|
||||
// TODO: Get position risk metrics
|
||||
return c.json({
|
||||
symbol,
|
||||
position: 100,
|
||||
exposure: 10000,
|
||||
risk: 'low',
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Failed to get position risk', error);
|
||||
return c.json({ error: 'Failed to get position risk' }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
const port = config.EXECUTION_SERVICE_PORT || 3004;
|
||||
|
||||
logger.info(`Starting execution service on port ${port}`);
|
||||
|
||||
serve(
|
||||
{
|
||||
fetch: app.fetch,
|
||||
port,
|
||||
},
|
||||
info => {
|
||||
logger.info(`Execution service is running on port ${info.port}`);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue