Add endpoint for retrieving spot position history in GMX API. Enhance SpotBot to handle 404 errors gracefully when positions are not found in broker history, improving logging and user feedback for closed positions.

This commit is contained in:
2025-12-29 16:58:32 +07:00
parent ee8db1cdc8
commit 10691ab0b8
2 changed files with 37 additions and 0 deletions

View File

@@ -631,6 +631,7 @@ declare module 'fastify' {
swapGmxTokens: typeof swapGmxTokens; swapGmxTokens: typeof swapGmxTokens;
estimatePositionGasFee: typeof estimatePositionGasFee; estimatePositionGasFee: typeof estimatePositionGasFee;
getPositionHistory: typeof getPositionHistory; getPositionHistory: typeof getPositionHistory;
getSpotPositionHistory: typeof getSpotPositionHistory;
} }
} }

View File

@@ -234,6 +234,42 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
) )
}) })
// Define route to get spot position history
fastify.get('/spot-position-history', {
schema: {
querystring: Type.Object({
account: Type.String(),
pageIndex: Type.Optional(Type.Integer()),
pageSize: Type.Optional(Type.Integer()),
ticker: Type.Optional(Type.String()),
fromDateTime: Type.Optional(Type.String()),
toDateTime: Type.Optional(Type.String())
}),
response: {
200: Type.Object({
success: Type.Boolean(),
positions: Type.Optional(Type.Array(Type.Any())),
pageIndex: Type.Optional(Type.Integer()),
pageSize: Type.Optional(Type.Integer()),
count: Type.Optional(Type.Integer()),
error: Type.Optional(Type.String())
})
}
}
}, async (request, reply) => {
const { account, pageIndex, pageSize, ticker, fromDateTime, toDateTime } = request.query
return request.getSpotPositionHistory(
reply,
account,
pageIndex,
pageSize,
ticker,
fromDateTime,
toDateTime
)
})
// Define route to get gas fee estimation for opening a position // Define route to get gas fee estimation for opening a position
fastify.get('/gas-fee', { fastify.get('/gas-fee', {
schema: { schema: {