| /** | |
| * Controladores del modulo de posiciones (simulador virtual). | |
| * | |
| * Responsabilidades: | |
| * - open(req, res) β abre una posicion virtual en un mercado. | |
| * - list(req, res) β lista las posiciones del usuario autenticado. | |
| * - close(req, res) β cierra una posicion y calcula P&L final. | |
| * | |
| * Endpoints (bajo /api/v1/positions, protegidos por requireAuth): | |
| * POST / β abrir posicion. | |
| * GET / β listar posiciones (opcional ?status=open|closed). | |
| * DELETE /:id β cerrar posicion. | |
| */ | |
| import { ok, created, noContent } from '../utils/apiResponse.js'; | |
| import { positionsService } from './positions.service.js'; | |
| export const positionsController = { | |
| async open(req, res) { | |
| const position = await positionsService.open(req.user.id, req.body); | |
| created(res, position); | |
| }, | |
| async list(req, res) { | |
| const positions = await positionsService.list(req.user.id, req.query.status); | |
| ok(res, positions); | |
| }, | |
| async close(req, res) { | |
| const position = await positionsService.close(req.params.id, req.user.id); | |
| ok(res, position); | |
| }, | |
| async suggest(req, res) { | |
| const bankroll = req.query.bankroll ? parseFloat(req.query.bankroll) : 1000; | |
| const suggestion = await positionsService.suggest(req.params.marketId, bankroll); | |
| ok(res, suggestion); | |
| }, | |
| }; | |