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