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 { page } from '$app/state'
import { import {
CoinsIcon, CoinsIcon,
DownloadIcon,
HistoryIcon, HistoryIcon,
HomeIcon, HomeIcon,
SquareTerminal, SquareTerminal,
@ -23,6 +24,12 @@
icon: HomeIcon, icon: HomeIcon,
isActive: page.url.pathname === `/dashboard/crypto-data`, isActive: page.url.pathname === `/dashboard/crypto-data`,
}, },
{
title: 'Download',
url: `/dashboard/download`,
icon: DownloadIcon,
isActive: page.url.pathname === `/dashboard/download`,
},
{ {
title: 'Arbitrage', title: 'Arbitrage',
url: `/dashboard/swap`, 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 side = form.data.side
positionIdx = form.data.side === 'Buy' ? 1 : 2 positionIdx = form.data.side === 'Buy' ? 1 : 2
} else if (form.data.type === 'Percent') { } else if (form.data.type === 'Percent') {
side = form.data.side
const wallet = await client.getWalletBalance({ const wallet = await client.getWalletBalance({
accountType: 'UNIFIED', accountType: 'UNIFIED',
coin: 'USDT', coin: 'USDT',
@ -127,15 +128,25 @@ export const POST = async ({ locals, request }) => {
Number(form.data.leverage || '1'))) / Number(form.data.leverage || '1'))) /
Number(form.data.entryPrice) Number(form.data.entryPrice)
).toFixed(Number(form.data.qtyDecimalPoint)) ).toFixed(Number(form.data.qtyDecimalPoint))
takeProfit = ( if (side === 'Buy') {
Number(form.data.entryPrice) * takeProfit = (
(1 + Number(form.data.takeProfitPercent) / 100) Number(form.data.entryPrice) *
).toFixed(decimalLength) (1 + Number(form.data.takeProfitPercent) / 100)
stopLoss = ( ).toFixed(decimalLength)
Number(form.data.entryPrice) * stopLoss = (
(1 - Number(form.data.stopLossPercent) / 100) Number(form.data.entryPrice) *
).toFixed(decimalLength) (1 - Number(form.data.stopLossPercent) / 100)
side = form.data.side ).toFixed(decimalLength)
} 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 positionIdx = form.data.side === 'Buy' ? 1 : 2
} else { } else {
const position = await client.getPositionInfo({ const position = await client.getPositionInfo({
@ -189,8 +200,8 @@ export const POST = async ({ locals, request }) => {
side, side,
orderType: 'Market', orderType: 'Market',
qty, qty,
takeProfit: side === 'Buy' ? takeProfit : stopLoss, takeProfit: takeProfit,
stopLoss: side === 'Buy' ? stopLoss : takeProfit, stopLoss: stopLoss,
isLeverage: isLeverage ? 1 : 0, isLeverage: isLeverage ? 1 : 0,
positionIdx: hedge !== undefined ? positionIdx : undefined, positionIdx: hedge !== undefined ? positionIdx : undefined,
}) })

Loading…
Cancel
Save