add full amount order if has active order + add custom decimal points for certain coins

master
TZGyn 10 months ago
parent 70a1345901
commit 21eb346061
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

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

Loading…
Cancel
Save