From b0fcbca26675fddedff68821fc6aa707d0cfb235 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Mon, 17 Mar 2025 21:22:53 +0800 Subject: [PATCH] add hedge --- src/routes/webhook/tradingview/+server.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/routes/webhook/tradingview/+server.ts b/src/routes/webhook/tradingview/+server.ts index dac3289..bbfacf3 100644 --- a/src/routes/webhook/tradingview/+server.ts +++ b/src/routes/webhook/tradingview/+server.ts @@ -22,6 +22,7 @@ export const POST = async ({ locals, request }) => { leverage: z.string().optional(), takeProfit: z.string().optional(), stopLoss: z.string().optional(), + hedge: z.enum(['true', 'false']).optional(), }) const percentSchema = z.object({ type: z.literal('Percent'), @@ -35,6 +36,7 @@ export const POST = async ({ locals, request }) => { leverage: z.string().default('1'), takeProfitPercent: z.string().optional(), stopLossPercent: z.string().optional(), + hedge: z.enum(['true', 'false']).optional(), // tpslDecimalPoint: z.string().default('1'), }) const closePositionSchema = z.object({ @@ -42,6 +44,7 @@ export const POST = async ({ locals, request }) => { key: z.string(), secret: z.string(), symbol: z.string(), + hedge: z.enum(['true', 'false']).optional(), }) const form = z .union([flatSchema, percentSchema, closePositionSchema]) @@ -52,7 +55,7 @@ export const POST = async ({ locals, request }) => { return json({}, { status: 400 }) } - const { key, secret, symbol } = form.data + const { key, secret, symbol, hedge } = form.data try { let qty @@ -75,6 +78,13 @@ export const POST = async ({ locals, request }) => { demoTrading: true, }) + if (hedge && hedge === 'true') { + client.switchPositionMode({ + category: 'linear', + mode: 3, + }) + } + if (form.data.type === 'Flat') { qty = ( Number(form.data.qty) * Number(form.data.leverage || '1')