add hedge mode

master
TZGyn 9 months ago
parent b0fcbca266
commit 589de51dc7
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -85,6 +85,7 @@ export const POST = async ({ locals, request }) => {
})
}
let positionIdx: 0 | 1 | 2 = 0
if (form.data.type === 'Flat') {
qty = (
Number(form.data.qty) * Number(form.data.leverage || '1')
@ -92,6 +93,7 @@ export const POST = async ({ locals, request }) => {
takeProfit = form.data.takeProfit
stopLoss = form.data.stopLoss
side = form.data.side
positionIdx = form.data.side === 'Buy' ? 1 : 2
} else if (form.data.type === 'Percent') {
const wallet = await client.getWalletBalance({
accountType: 'UNIFIED',
@ -131,6 +133,7 @@ export const POST = async ({ locals, request }) => {
(1 - Number(form.data.stopLossPercent) / 100)
).toFixed(decimalLength)
side = form.data.side
positionIdx = form.data.side === 'Buy' ? 1 : 2
} else {
const position = await client.getPositionInfo({
category: 'linear',
@ -139,6 +142,9 @@ export const POST = async ({ locals, request }) => {
console.log('closing')
console.log(position.result.list)
if (hedge === 'true') {
return new Response()
}
if (position.result.list.length <= 0) {
return new Response()
@ -163,6 +169,7 @@ export const POST = async ({ locals, request }) => {
takeProfit: side === 'Buy' ? takeProfit : stopLoss,
stopLoss: side === 'Buy' ? stopLoss : takeProfit,
isLeverage: isLeverage ? 1 : 0,
positionIdx,
})
console.log('Order:', order)

Loading…
Cancel
Save