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