add leverage

master
TZGyn 10 months ago
parent 94d7e88d99
commit 0622b50518
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -29,6 +29,7 @@
type: 'Flat', type: 'Flat',
...$formData, ...$formData,
qty: $formData.qty.toString(), qty: $formData.qty.toString(),
leverage: $formData.leverage.toString(),
takeProfit: $formData.takeProfit.toString(), takeProfit: $formData.takeProfit.toString(),
stopLoss: $formData.stopLoss.toString(), stopLoss: $formData.stopLoss.toString(),
}, },
@ -54,6 +55,7 @@
...$percentFormData, ...$percentFormData,
entryPrice: '{trigger_entry_value}', entryPrice: '{trigger_entry_value}',
qtyPercent: $percentFormData.qtyPercent.toString(), qtyPercent: $percentFormData.qtyPercent.toString(),
leverage: $percentFormData.leverage.toString(),
takeProfitPercent: takeProfitPercent:
$percentFormData.takeProfitPercent.toString(), $percentFormData.takeProfitPercent.toString(),
stopLossPercent: stopLossPercent:
@ -169,6 +171,19 @@
<Form.Description>Quantity</Form.Description> <Form.Description>Quantity</Form.Description>
<Form.FieldErrors /> <Form.FieldErrors />
</Form.Field> </Form.Field>
<Form.Field {form} name="leverage">
<Form.Control>
{#snippet children({ props })}
<Form.Label>Leverage</Form.Label>
<Input
type="number"
{...props}
bind:value={$formData.leverage} />
{/snippet}
</Form.Control>
<Form.Description>Leverage</Form.Description>
<Form.FieldErrors />
</Form.Field>
<Form.Field {form} name="takeProfit"> <Form.Field {form} name="takeProfit">
<Form.Control> <Form.Control>
{#snippet children({ props })} {#snippet children({ props })}
@ -203,6 +218,7 @@
type: 'Flat', type: 'Flat',
...$formData, ...$formData,
qty: $formData.qty.toString(), qty: $formData.qty.toString(),
leverage: $formData.leverage.toString(),
takeProfit: $formData.takeProfit.toString(), takeProfit: $formData.takeProfit.toString(),
stopLoss: $formData.stopLoss.toString(), stopLoss: $formData.stopLoss.toString(),
}} /> }} />
@ -286,6 +302,19 @@
max={100} max={100}
step={0.1} /> step={0.1} />
</Form.Field> </Form.Field>
<Form.Field {form} name="leverage">
<Form.Control>
{#snippet children({ props })}
<Form.Label>Leverage</Form.Label>
<Input
type="number"
{...props}
bind:value={$percentFormData.leverage} />
{/snippet}
</Form.Control>
<Form.Description>Leverage</Form.Description>
<Form.FieldErrors />
</Form.Field>
<Form.Field form={percentForm} name="takeProfitPercent"> <Form.Field form={percentForm} name="takeProfitPercent">
<Form.Control> <Form.Control>
{#snippet children({ props })} {#snippet children({ props })}
@ -333,6 +362,7 @@
...$percentFormData, ...$percentFormData,
entryPrice: '{trigger_entry_value}', entryPrice: '{trigger_entry_value}',
qtyPercent: $percentFormData.qtyPercent.toString(), qtyPercent: $percentFormData.qtyPercent.toString(),
leverage: $percentFormData.leverage.toString(),
takeProfitPercent: takeProfitPercent:
$percentFormData.takeProfitPercent.toString(), $percentFormData.takeProfitPercent.toString(),
stopLossPercent: stopLossPercent:
@ -384,7 +414,6 @@
json={{ json={{
type: 'Close Position', type: 'Close Position',
...$closePositionFormData, ...$closePositionFormData,
entryPrice: '{trigger_entry_value}',
}} /> }} />
</Tabs.Content> </Tabs.Content>
</Tabs.Root> </Tabs.Root>

@ -10,6 +10,7 @@ export const formSchema = z.object({
symbol: z.string(), symbol: z.string(),
side: z.enum(['Buy', 'Sell']), side: z.enum(['Buy', 'Sell']),
qty: z.number(), qty: z.number(),
leverage: z.number().default(100),
takeProfit: z.number(), takeProfit: z.number(),
stopLoss: z.number(), stopLoss: z.number(),
}) })
@ -20,6 +21,7 @@ export const percentSchema = z.object({
symbol: z.string(), symbol: z.string(),
side: z.enum(['Buy', 'Sell']), side: z.enum(['Buy', 'Sell']),
qtyPercent: z.number(), qtyPercent: z.number(),
leverage: z.number().default(100),
takeProfitPercent: z.number(), takeProfitPercent: z.number(),
stopLossPercent: z.number(), stopLossPercent: z.number(),
}) })

@ -20,6 +20,7 @@ export const POST = async ({ locals, request }) => {
symbol: z.string(), symbol: z.string(),
side: z.enum(['Buy', 'Sell']), side: z.enum(['Buy', 'Sell']),
qty: z.string(), qty: z.string(),
leverage: z.string().default('1'),
takeProfit: z.string().optional(), takeProfit: z.string().optional(),
stopLoss: z.string().optional(), stopLoss: z.string().optional(),
}) })
@ -31,6 +32,7 @@ export const POST = async ({ locals, request }) => {
side: z.enum(['Buy', 'Sell']), side: z.enum(['Buy', 'Sell']),
entryPrice: z.string(), entryPrice: z.string(),
qtyPercent: z.string(), qtyPercent: z.string(),
leverage: z.string().default('1'),
takeProfitPercent: z.string().optional(), takeProfitPercent: z.string().optional(),
stopLossPercent: z.string().optional(), stopLossPercent: z.string().optional(),
}) })
@ -64,7 +66,9 @@ export const POST = async ({ locals, request }) => {
}) })
if (form.data.type === 'Flat') { if (form.data.type === 'Flat') {
qty = form.data.qty qty = (
Number(form.data.qty) * Number(form.data.leverage)
).toFixed(getDecimalPoint(symbol.slice(0, -4)))
takeProfit = form.data.takeProfit takeProfit = form.data.takeProfit
stopLoss = form.data.stopLoss stopLoss = form.data.stopLoss
side = form.data.side side = form.data.side
@ -89,7 +93,8 @@ export const POST = async ({ locals, request }) => {
qty = ( qty = (
(Number(wallet.result.list[0].totalAvailableBalance) * (Number(wallet.result.list[0].totalAvailableBalance) *
(Number(form.data.qtyPercent) / 100)) / ((Number(form.data.qtyPercent) / 100) *
Number(form.data.leverage))) /
Number(form.data.entryPrice) Number(form.data.entryPrice)
).toFixed(getDecimalPoint(symbol.slice(0, -4))) ).toFixed(getDecimalPoint(symbol.slice(0, -4)))
takeProfit = ( takeProfit = (

Loading…
Cancel
Save