Swap tokens

This commit is contained in:
2025-07-06 14:00:44 +07:00
parent 8096db495a
commit c7dec76809
21 changed files with 1124 additions and 173 deletions

View File

@@ -113,6 +113,7 @@ declare module 'fastify' {
closeGmxPosition: typeof closeGmxPosition;
getGmxTrade: typeof getGmxTrade;
getGmxPositions: typeof getGmxPositions;
swapGmxTokens: typeof swapGmxTokens;
}
}

View File

@@ -101,6 +101,45 @@ const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
)
})
// Define route to swap tokens
fastify.post('/swap-tokens', {
schema: {
body: Type.Object({
account: Type.String(),
fromTicker: Type.String(),
toTicker: Type.String(),
amount: Type.Number(),
orderType: Type.Optional(Type.Union([Type.Literal('market'), Type.Literal('limit')])),
triggerRatio: Type.Optional(Type.Number()),
allowedSlippage: Type.Optional(Type.Number())
}),
response: {
200: Type.Object({
success: Type.Boolean(),
hash: Type.Optional(Type.String()),
message: Type.Optional(Type.String()),
error: Type.Optional(Type.String()),
errorType: Type.Optional(Type.String()),
suggestion: Type.Optional(Type.String())
})
}
}
}, async (request, reply) => {
const { account, fromTicker, toTicker, amount, orderType, triggerRatio, allowedSlippage } = request.body
// Call the swapGmxTokens method from the GMX plugin
return request.swapGmxTokens(
reply,
account,
fromTicker,
toTicker,
amount,
orderType || 'market',
triggerRatio,
allowedSlippage || 0.5
)
})
// Define route to get a trade
fastify.get('/trades', {
schema: {