add download csv page + update tp/sl calculation

master
TZGyn 6 months ago
parent 8db2167a22
commit 145c4d51d6

@ -4,6 +4,7 @@
import { page } from '$app/state'
import {
CoinsIcon,
DownloadIcon,
HistoryIcon,
HomeIcon,
SquareTerminal,
@ -23,6 +24,12 @@
icon: HomeIcon,
isActive: page.url.pathname === `/dashboard/crypto-data`,
},
{
title: 'Download',
url: `/dashboard/download`,
icon: DownloadIcon,
isActive: page.url.pathname === `/dashboard/download`,
},
{
title: 'Arbitrage',
url: `/dashboard/swap`,

@ -0,0 +1,7 @@
<script lang="ts">
import { Button } from '$lib/components/ui/button'
</script>
<Button href="http://localhost:3000/bybit.csv" download>
Download
</Button>

@ -98,6 +98,7 @@ export const POST = async ({ locals, request }) => {
side = form.data.side
positionIdx = form.data.side === 'Buy' ? 1 : 2
} else if (form.data.type === 'Percent') {
side = form.data.side
const wallet = await client.getWalletBalance({
accountType: 'UNIFIED',
coin: 'USDT',
@ -127,6 +128,7 @@ export const POST = async ({ locals, request }) => {
Number(form.data.leverage || '1'))) /
Number(form.data.entryPrice)
).toFixed(Number(form.data.qtyDecimalPoint))
if (side === 'Buy') {
takeProfit = (
Number(form.data.entryPrice) *
(1 + Number(form.data.takeProfitPercent) / 100)
@ -135,7 +137,16 @@ export const POST = async ({ locals, request }) => {
Number(form.data.entryPrice) *
(1 - Number(form.data.stopLossPercent) / 100)
).toFixed(decimalLength)
side = form.data.side
} else {
takeProfit = (
Number(form.data.entryPrice) *
(1 - Number(form.data.takeProfitPercent) / 100)
).toFixed(decimalLength)
stopLoss = (
Number(form.data.entryPrice) *
(1 + Number(form.data.stopLossPercent) / 100)
).toFixed(decimalLength)
}
positionIdx = form.data.side === 'Buy' ? 1 : 2
} else {
const position = await client.getPositionInfo({
@ -189,8 +200,8 @@ export const POST = async ({ locals, request }) => {
side,
orderType: 'Market',
qty,
takeProfit: side === 'Buy' ? takeProfit : stopLoss,
stopLoss: side === 'Buy' ? stopLoss : takeProfit,
takeProfit: takeProfit,
stopLoss: stopLoss,
isLeverage: isLeverage ? 1 : 0,
positionIdx: hedge !== undefined ? positionIdx : undefined,
})

Loading…
Cancel
Save