|
|
|
@ -57,6 +57,29 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
demoTrading: true,
|
|
|
|
demoTrading: true,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const orders = await client.getActiveOrders({
|
|
|
|
|
|
|
|
category: 'linear',
|
|
|
|
|
|
|
|
symbol,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const amount = orders.result.list.reduce(
|
|
|
|
|
|
|
|
(acc, curr) => acc + Number(curr.qty),
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (amount > 0) {
|
|
|
|
|
|
|
|
const order = await client.submitOrder({
|
|
|
|
|
|
|
|
category: 'linear',
|
|
|
|
|
|
|
|
symbol,
|
|
|
|
|
|
|
|
side,
|
|
|
|
|
|
|
|
orderType: 'Market',
|
|
|
|
|
|
|
|
qty: amount.toString(),
|
|
|
|
|
|
|
|
takeProfit,
|
|
|
|
|
|
|
|
stopLoss,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return new Response()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (form.data.type === 'Flat') {
|
|
|
|
if (form.data.type === 'Flat') {
|
|
|
|
qty = form.data.qty
|
|
|
|
qty = form.data.qty
|
|
|
|
takeProfit = form.data.takeProfit
|
|
|
|
takeProfit = form.data.takeProfit
|
|
|
|
@ -77,19 +100,18 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
Number(form.data.qtyPercent)) /
|
|
|
|
Number(form.data.qtyPercent)) /
|
|
|
|
100 /
|
|
|
|
100 /
|
|
|
|
Number(wallet.result.list[0].totalAvailableBalance)
|
|
|
|
Number(wallet.result.list[0].totalAvailableBalance)
|
|
|
|
).toFixed(2)
|
|
|
|
).toFixed(getDecimalPoint(symbol.slice(0, -4)))
|
|
|
|
takeProfit = (
|
|
|
|
takeProfit = (
|
|
|
|
Number(form.data.entryPrice) *
|
|
|
|
Number(form.data.entryPrice) *
|
|
|
|
(1 + Number(form.data.takeProfitPercent) / 100)
|
|
|
|
(1 + Number(form.data.takeProfitPercent) / 100)
|
|
|
|
).toFixed(2)
|
|
|
|
).toFixed(1)
|
|
|
|
stopLoss = (
|
|
|
|
stopLoss = (
|
|
|
|
Number(form.data.entryPrice) *
|
|
|
|
Number(form.data.entryPrice) *
|
|
|
|
(1 - Number(form.data.stopLossPercent) / 100)
|
|
|
|
(1 - Number(form.data.stopLossPercent) / 100)
|
|
|
|
).toFixed(2)
|
|
|
|
).toFixed(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log({ qty, takeProfit, stopLoss })
|
|
|
|
console.log({ qty, takeProfit, stopLoss })
|
|
|
|
|
|
|
|
|
|
|
|
const order = await client.submitOrder({
|
|
|
|
const order = await client.submitOrder({
|
|
|
|
category: 'linear',
|
|
|
|
category: 'linear',
|
|
|
|
symbol,
|
|
|
|
symbol,
|
|
|
|
@ -99,9 +121,16 @@ export const POST = async ({ locals, request }) => {
|
|
|
|
takeProfit,
|
|
|
|
takeProfit,
|
|
|
|
stopLoss,
|
|
|
|
stopLoss,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return new Response()
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Error', error)
|
|
|
|
console.log('Error', error)
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
return new Response()
|
|
|
|
return new Response()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getDecimalPoint = (symbol: string) => {
|
|
|
|
|
|
|
|
if (symbol === 'BTC') return 3
|
|
|
|
|
|
|
|
if (symbol === 'ETH') return 2
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|