trading-platform-frontend-v2/src/modules/investment/services/investment.api.ts
rckrdmrd 737303d177 Migración desde trading-platform/apps/frontend - Estándar multi-repo v2
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 08:32:49 -06:00

99 lines
3.0 KiB
TypeScript

/**
* Investment API Service
*/
import { api } from '@/services/api';
import type {
AgentConfig,
AllocationWithAgent,
AllocationTransaction,
AllocationSummary,
AgentPerformance,
CreateAllocationInput,
FundAllocationInput,
WithdrawInput,
} from '../types';
const INVESTMENT_BASE_URL = import.meta.env.VITE_INVESTMENT_SERVICE_URL || 'http://localhost:3093';
export const investmentApi = {
// Get all agents
async getAgents(): Promise<AgentConfig[]> {
const { data } = await api.get(`${INVESTMENT_BASE_URL}/api/v1/agents`);
return data.data;
},
// Get single agent
async getAgent(agentType: string): Promise<AgentConfig> {
const { data } = await api.get(`${INVESTMENT_BASE_URL}/api/v1/agents/${agentType}`);
return data.data;
},
// Get agent performance
async getAgentPerformance(agentType: string, periodDays = 30): Promise<AgentPerformance> {
const { data } = await api.get(`${INVESTMENT_BASE_URL}/api/v1/agents/${agentType}/performance`, {
params: { periodDays },
});
return data.data;
},
// Get user allocations
async getUserAllocations(): Promise<AllocationWithAgent[]> {
const { data } = await api.get(`${INVESTMENT_BASE_URL}/api/v1/users/me/allocations`);
return data.data;
},
// Get single allocation
async getAllocation(allocationId: string): Promise<AllocationWithAgent> {
const { data } = await api.get(`${INVESTMENT_BASE_URL}/api/v1/allocations/${allocationId}`);
return data.data;
},
// Get allocation transactions
async getAllocationTransactions(allocationId: string): Promise<AllocationTransaction[]> {
const { data } = await api.get(
`${INVESTMENT_BASE_URL}/api/v1/allocations/${allocationId}/transactions`
);
return data.data;
},
// Get user investment summary
async getSummary(): Promise<AllocationSummary> {
const { data } = await api.get(`${INVESTMENT_BASE_URL}/api/v1/users/me/investment-summary`);
return data.data;
},
// Create allocation
async createAllocation(input: CreateAllocationInput): Promise<AllocationWithAgent> {
const { data } = await api.post(`${INVESTMENT_BASE_URL}/api/v1/allocations`, input);
return data.data;
},
// Fund allocation
async fundAllocation(input: FundAllocationInput): Promise<AllocationWithAgent> {
const { data } = await api.post(
`${INVESTMENT_BASE_URL}/api/v1/allocations/${input.allocationId}/fund`,
{ amount: input.amount }
);
return data.data;
},
// Withdraw from allocation
async withdraw(input: WithdrawInput): Promise<AllocationWithAgent> {
const { data } = await api.post(
`${INVESTMENT_BASE_URL}/api/v1/allocations/${input.allocationId}/withdraw`,
{ amount: input.amount }
);
return data.data;
},
// Update allocation status
async updateStatus(allocationId: string, status: string, reason?: string): Promise<AllocationWithAgent> {
const { data } = await api.patch(
`${INVESTMENT_BASE_URL}/api/v1/allocations/${allocationId}/status`,
{ status, reason }
);
return data.data;
},
};