Swap tokens
This commit is contained in:
@@ -113,6 +113,7 @@ declare module 'fastify' {
|
||||
closeGmxPosition: typeof closeGmxPosition;
|
||||
getGmxTrade: typeof getGmxTrade;
|
||||
getGmxPositions: typeof getGmxPositions;
|
||||
swapGmxTokens: typeof swapGmxTokens;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user