add close position for compound

master
TZGyn 3 months ago
parent bc1a010943
commit 13b3ba6619

@ -70,12 +70,21 @@ export const POST = async ({ locals, request }) => {
hedge: z.enum(['true', 'false']).optional(), hedge: z.enum(['true', 'false']).optional(),
side: z.enum(['Buy', 'Sell']).optional(), side: z.enum(['Buy', 'Sell']).optional(),
}) })
const closePositionCompoundSchema = z.object({
type: z.literal('Close Position Compound'),
key: z.string(),
secret: z.string(),
symbol: z.string(),
hedge: z.enum(['true', 'false']).optional(),
side: z.enum(['Buy', 'Sell']).optional(),
})
const form = z const form = z
.union([ .union([
flatSchema, flatSchema,
percentSchema, percentSchema,
closePositionSchema, closePositionSchema,
compoundingSchema, compoundingSchema,
closePositionCompoundSchema,
]) ])
.safeParse(body) .safeParse(body)
@ -93,7 +102,10 @@ export const POST = async ({ locals, request }) => {
let side let side
let isLeverage let isLeverage
if (form.data.type === 'Close Position') { if (
form.data.type === 'Close Position' ||
form.data.type === 'Close Position Compound'
) {
isLeverage = false isLeverage = false
} else if (form.data.leverage) { } else if (form.data.leverage) {
isLeverage = true isLeverage = true
@ -174,7 +186,10 @@ export const POST = async ({ locals, request }) => {
).toFixed(decimalLength) ).toFixed(decimalLength)
} }
positionIdx = form.data.side === 'Buy' ? 1 : 2 positionIdx = form.data.side === 'Buy' ? 1 : 2
} else if (form.data.type === 'Close Position') { } else if (
form.data.type === 'Close Position' ||
form.data.type === 'Close Position Compound'
) {
const position = await client.getPositionInfo({ const position = await client.getPositionInfo({
category: 'linear', category: 'linear',
symbol: symbol, symbol: symbol,
@ -251,7 +266,7 @@ export const POST = async ({ locals, request }) => {
console.log('Order:', order) console.log('Order:', order)
if (form.data.type === 'Close Position') { if (form.data.type === 'Close Position Compound') {
console.log('Close Position, checking for compound...') console.log('Close Position, checking for compound...')
const wallet = await client.getTransferableAmount({ const wallet = await client.getTransferableAmount({

Loading…
Cancel
Save