|
|
|
@ -22,6 +22,7 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
leverage: z.string().optional(),
|
|
|
|
leverage: z.string().optional(),
|
|
|
|
takeProfit: z.string().optional(),
|
|
|
|
takeProfit: z.string().optional(),
|
|
|
|
stopLoss: z.string().optional(),
|
|
|
|
stopLoss: z.string().optional(),
|
|
|
|
|
|
|
|
hedge: z.enum(['true', 'false']).optional(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
const percentSchema = z.object({
|
|
|
|
const percentSchema = z.object({
|
|
|
|
type: z.literal('Percent'),
|
|
|
|
type: z.literal('Percent'),
|
|
|
|
@ -35,6 +36,7 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
leverage: z.string().default('1'),
|
|
|
|
leverage: z.string().default('1'),
|
|
|
|
takeProfitPercent: z.string().optional(),
|
|
|
|
takeProfitPercent: z.string().optional(),
|
|
|
|
stopLossPercent: z.string().optional(),
|
|
|
|
stopLossPercent: z.string().optional(),
|
|
|
|
|
|
|
|
hedge: z.enum(['true', 'false']).optional(),
|
|
|
|
// tpslDecimalPoint: z.string().default('1'),
|
|
|
|
// tpslDecimalPoint: z.string().default('1'),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
const closePositionSchema = z.object({
|
|
|
|
const closePositionSchema = z.object({
|
|
|
|
@ -42,6 +44,7 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
key: z.string(),
|
|
|
|
key: z.string(),
|
|
|
|
secret: z.string(),
|
|
|
|
secret: z.string(),
|
|
|
|
symbol: z.string(),
|
|
|
|
symbol: z.string(),
|
|
|
|
|
|
|
|
hedge: z.enum(['true', 'false']).optional(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
const form = z
|
|
|
|
const form = z
|
|
|
|
.union([flatSchema, percentSchema, closePositionSchema])
|
|
|
|
.union([flatSchema, percentSchema, closePositionSchema])
|
|
|
|
@ -52,7 +55,7 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
return json({}, { status: 400 })
|
|
|
|
return json({}, { status: 400 })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const { key, secret, symbol } = form.data
|
|
|
|
const { key, secret, symbol, hedge } = form.data
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
let qty
|
|
|
|
let qty
|
|
|
|
@ -75,6 +78,13 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
demoTrading: true,
|
|
|
|
demoTrading: true,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hedge && hedge === 'true') {
|
|
|
|
|
|
|
|
client.switchPositionMode({
|
|
|
|
|
|
|
|
category: 'linear',
|
|
|
|
|
|
|
|
mode: 3,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (form.data.type === 'Flat') {
|
|
|
|
if (form.data.type === 'Flat') {
|
|
|
|
qty = (
|
|
|
|
qty = (
|
|
|
|
Number(form.data.qty) * Number(form.data.leverage || '1')
|
|
|
|
Number(form.data.qty) * Number(form.data.leverage || '1')
|
|
|
|
|