You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
935 B
TypeScript

import { db } from '$lib/db/index.js'
import { json } from '@sveltejs/kit'
import { RestClientV5 } from 'bybit-api'
import { z } from 'zod'
export const POST = async ({ locals, request }) => {
const body = await request.json()
const form = z
.object({
key: z.string(),
secret: z.string(),
symbol: z.string(),
side: z.enum(['Buy', 'Sell']),
qty: z.string(),
takeProfit: z.string(),
stopLoss: z.string(),
})
.safeParse(body)
if (!form.success) return json({}, { status: 400 })
// const apiKey = 'wrc1w54Zp5JAfXLxY2'
// const apiSecret = 'tY7oYPhwSE1gabFS4PmxtmbDOhkYWvPh0khf'
const { key, secret, side, symbol, qty, stopLoss, takeProfit } =
form.data
const client = new RestClientV5({
key: key,
secret: secret,
demoTrading: true,
})
await client.submitOrder({
category: 'linear',
symbol,
side,
orderType: 'Market',
qty,
takeProfit,
stopLoss,
})
return new Response()
}