|
|
|
@ -45,6 +45,7 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
secret: z.string(),
|
|
|
|
secret: z.string(),
|
|
|
|
symbol: z.string(),
|
|
|
|
symbol: z.string(),
|
|
|
|
hedge: z.enum(['true', 'false']).optional(),
|
|
|
|
hedge: z.enum(['true', 'false']).optional(),
|
|
|
|
|
|
|
|
side: z.enum(['Buy', 'Sell']).optional(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
const form = z
|
|
|
|
const form = z
|
|
|
|
.union([flatSchema, percentSchema, closePositionSchema])
|
|
|
|
.union([flatSchema, percentSchema, closePositionSchema])
|
|
|
|
@ -143,20 +144,40 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
console.log('closing')
|
|
|
|
console.log('closing')
|
|
|
|
console.log(position.result.list)
|
|
|
|
console.log(position.result.list)
|
|
|
|
if (hedge === 'true') {
|
|
|
|
if (hedge === 'true') {
|
|
|
|
return new Response()
|
|
|
|
const closeSide = form.data.side
|
|
|
|
|
|
|
|
if (closeSide === undefined) {
|
|
|
|
|
|
|
|
return new Response()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (position.result.list.length <= 0) {
|
|
|
|
|
|
|
|
return new Response()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const order = position.result.list.find(
|
|
|
|
|
|
|
|
(result) => result.side === closeSide,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!order) {
|
|
|
|
|
|
|
|
return new Response()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
side =
|
|
|
|
|
|
|
|
order.side === 'Buy' ? ('Sell' as const) : ('Buy' as const)
|
|
|
|
|
|
|
|
qty = order.size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
positionIdx = order.side === 'Buy' ? 1 : 2
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (position.result.list.length <= 0) {
|
|
|
|
|
|
|
|
return new Response()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (position.result.list[0].side === 'None')
|
|
|
|
|
|
|
|
return new Response()
|
|
|
|
|
|
|
|
side =
|
|
|
|
|
|
|
|
position.result.list[0].side === 'Buy'
|
|
|
|
|
|
|
|
? ('Sell' as const)
|
|
|
|
|
|
|
|
: ('Buy' as const)
|
|
|
|
|
|
|
|
qty = position.result.list[0].size
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (position.result.list.length <= 0) {
|
|
|
|
|
|
|
|
return new Response()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (position.result.list[0].side === 'None')
|
|
|
|
|
|
|
|
return new Response()
|
|
|
|
|
|
|
|
side =
|
|
|
|
|
|
|
|
position.result.list[0].side === 'Buy'
|
|
|
|
|
|
|
|
? ('Sell' as const)
|
|
|
|
|
|
|
|
: ('Buy' as const)
|
|
|
|
|
|
|
|
qty = position.result.list[0].size
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log({ qty, takeProfit, stopLoss })
|
|
|
|
console.log({ qty, takeProfit, stopLoss })
|
|
|
|
|