update webhook

master
TZGyn 10 months ago
parent 649fdfcab7
commit 2d92c0d88f
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -3,10 +3,18 @@ import { RestClientV5 } from 'bybit-api'
import { z } from 'zod'
export const POST = async ({ locals, request }) => {
const type = request.headers.get('Content-Type')
console.log('type', type)
const text = await request.text()
console.log('text', text)
const body = JSON.parse(text)
console.log('text', body)
const flatSchema = z.object({
type: z.literal('Flat'),
key: z.string(),
@ -40,44 +48,49 @@ export const POST = async ({ locals, request }) => {
const { key, secret, side, symbol } = form.data
let qty
let takeProfit
let stopLoss
try {
let qty
let takeProfit
let stopLoss
if (form.data.type === 'Flat') {
qty = form.data.qty
takeProfit = form.data.takeProfit
stopLoss = form.data.stopLoss
} else {
qty = (
(Number(form.data.entryPrice) * Number(form.data.qtyPercent)) /
100
).toString()
takeProfit = (
Number(form.data.entryPrice) *
(1 + Number(form.data.takeProfitPercent) / 100)
).toString()
stopLoss = (
Number(form.data.entryPrice) *
(1 - Number(form.data.stopLossPercent) / 100)
).toString()
}
if (form.data.type === 'Flat') {
qty = form.data.qty
takeProfit = form.data.takeProfit
stopLoss = form.data.stopLoss
} else {
qty = (
(Number(form.data.entryPrice) *
Number(form.data.qtyPercent)) /
100
).toString()
takeProfit = (
Number(form.data.entryPrice) *
(1 + Number(form.data.takeProfitPercent) / 100)
).toString()
stopLoss = (
Number(form.data.entryPrice) *
(1 - Number(form.data.stopLossPercent) / 100)
).toString()
}
const client = new RestClientV5({
key: key,
secret: secret,
demoTrading: true,
})
await client.submitOrder({
category: 'linear',
symbol,
side,
orderType: 'Market',
qty,
takeProfit,
stopLoss,
})
const client = new RestClientV5({
key: key,
secret: secret,
demoTrading: true,
})
return new Response()
await client.submitOrder({
category: 'linear',
symbol,
side,
orderType: 'Market',
qty,
takeProfit,
stopLoss,
})
} catch (error) {
console.log('Error', error)
} finally {
return new Response()
}
}

Loading…
Cancel
Save