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:
@@ -631,6 +631,7 @@ declare module 'fastify' {
|
||||
swapGmxTokens: typeof swapGmxTokens;
|
||||
estimatePositionGasFee: typeof estimatePositionGasFee;
|
||||
getPositionHistory: typeof getPositionHistory;
|
||||
getSpotPositionHistory: typeof getSpotPositionHistory;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
fastify.get('/gas-fee', {
|
||||
schema: {
|
||||
|
||||
Reference in New Issue
Block a user