Skip to content

Commit dd80d51

Browse files
committed
show all positions and orders
1 parent f831269 commit dd80d51

File tree

8 files changed

+36
-39
lines changed

8 files changed

+36
-39
lines changed

app/components/ClosePosition.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ type Inputs = {
1818
};
1919

2020
export const ClosePosition: FC<{
21-
symbol: string;
2221
position: API.PositionExt;
2322
refresh: import('swr/_internal').KeyedMutator<API.PositionInfo>;
2423
setOpen: Dispatch<SetStateAction<boolean>>;
25-
}> = ({ symbol, position, refresh, setOpen }) => {
24+
}> = ({ position, refresh, setOpen }) => {
2625
const [loading, setLoading] = useState(false);
2726

2827
const symbolsInfo = useSymbolsInfo();
@@ -36,7 +35,7 @@ export const ClosePosition: FC<{
3635
});
3736
const { onSubmit, helper } = useOrderEntry(
3837
{
39-
symbol,
38+
symbol: position.symbol,
4039
side: OrderSide.BUY,
4140
order_type: OrderType.MARKET
4241
},
@@ -56,7 +55,7 @@ export const ClosePosition: FC<{
5655
message: 'Closing position...'
5756
});
5857
try {
59-
await onSubmit(getInput(data, symbol));
58+
await onSubmit(getInput(data, position.symbol));
6059
update({
6160
eventCode: 'closePositionSuccess',
6261
type: 'success',
@@ -78,8 +77,8 @@ export const ClosePosition: FC<{
7877
}
7978
};
8079

81-
const symbolInfo = symbolsInfo[symbol]();
82-
const [_, base] = symbol.split('_');
80+
const symbolInfo = symbolsInfo[position.symbol]();
81+
const [_, base] = position.symbol.split('_');
8382
const [baseDecimals] = getDecimalsFromTick(symbolInfo);
8483

8584
return (
@@ -97,7 +96,7 @@ export const ClosePosition: FC<{
9796
rules={{
9897
validate: {
9998
custom: async (_, data) => {
100-
const errors = await getValidationErrors(data, symbol, helper.validator);
99+
const errors = await getValidationErrors(data, position.symbol, helper.validator);
101100
return errors?.order_quantity != null ? errors.order_quantity.message : true;
102101
}
103102
}

app/components/OrderTabs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export const OrderTabs: FC<{ symbol: string }> = ({ symbol }) => {
1212
</Tabs.List>
1313

1414
<Tabs.Content value="positions">
15-
<Positions symbol={symbol} />
15+
<Positions symbol={symbol} showAll={true} />
1616
</Tabs.Content>
1717
<Tabs.Content value="pending">
18-
<PendingOrders symbol={symbol} />
18+
<PendingOrders symbol={symbol} showAll={true} />
1919
</Tabs.Content>
2020
</Tabs.Root>
2121
);

app/components/PendingOrder.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import { baseFormatter, usdFormatter } from '~/utils';
1010

1111
export const PendingOrder: FC<{
1212
order: { isAlgoOrder: false; order: API.Order } | { isAlgoOrder: true; order: API.AlgoOrder };
13-
symbol: string;
1413
cancelOrder: ReturnType<typeof useOrderStream>[1]['cancelOrder'];
1514
cancelAlgoOrder: ReturnType<typeof useOrderStream>[1]['cancelAlgoOrder'];
16-
}> = ({ order, symbol, cancelOrder, cancelAlgoOrder }) => {
15+
}> = ({ order, cancelOrder, cancelAlgoOrder }) => {
1716
const [loading, setLoading] = useState(false);
1817
const [open, setOpen] = useState(false);
1918
const [_0, customNotification] = useNotifications();
@@ -72,9 +71,9 @@ export const PendingOrder: FC<{
7271
});
7372
try {
7473
if (order.isAlgoOrder) {
75-
await cancelAlgoOrder(order.order.algo_order_id, symbol);
74+
await cancelAlgoOrder(order.order.algo_order_id, order.order.symbol);
7675
} else {
77-
await cancelOrder(order.order.order_id, symbol);
76+
await cancelOrder(order.order.order_id, order.order.symbol);
7877
}
7978
update({
8079
eventCode: 'cancelOrderSuccess',

app/components/PendingOrders.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import { FC } from 'react';
55

66
import { Spinner, PendingOrder } from '.';
77

8-
export const PendingOrders: FC<{ symbol: string }> = ({ symbol }) => {
8+
export const PendingOrders: FC<{ symbol: string; showAll?: boolean }> = ({
9+
symbol,
10+
showAll = true
11+
}) => {
912
const [ordersUntyped, { cancelOrder, cancelAlgoOrder, isLoading }] = useOrderStream({
10-
symbol,
13+
symbol: showAll ? undefined : symbol,
1114
status: OrderStatus.INCOMPLETE
1215
});
1316
const orders = ordersUntyped as (API.Order | API.AlgoOrder)[];
@@ -48,7 +51,6 @@ export const PendingOrders: FC<{ symbol: string }> = ({ symbol }) => {
4851
<PendingOrder
4952
key={order.isAlgoOrder ? order.order.algo_order_id : order.order.order_id}
5053
order={order}
51-
symbol={symbol}
5254
cancelOrder={cancelOrder}
5355
cancelAlgoOrder={cancelAlgoOrder}
5456
/>

app/components/Positions.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ import { Spinner, UpdatePosition } from '.';
77

88
import { baseFormatter, usdFormatter } from '~/utils';
99

10-
export const Positions: FC<{ symbol: string }> = ({ symbol }) => {
11-
const [positions, _info, { refresh, isLoading }] = usePositionStream();
10+
export const Positions: FC<{ symbol: string; showAll?: boolean }> = ({
11+
symbol,
12+
showAll = true
13+
}) => {
14+
const [positions, _info, { refresh, isLoading }] = usePositionStream(
15+
showAll ? undefined : symbol
16+
);
1217
const { state } = useAccount();
1318

1419
if (state.status <= AccountStatusEnum.NotSignedIn) {
@@ -48,7 +53,7 @@ export const Positions: FC<{ symbol: string }> = ({ symbol }) => {
4853
<Badge color="red">Short</Badge>
4954
)}
5055
</Table.Cell>
51-
<Table.Cell>{baseFormatter.format(position.position_qty)}</Table.Cell>
56+
<Table.Cell>{baseFormatter.format(Math.abs(position.position_qty))}</Table.Cell>
5257
<Table.Cell>{usdFormatter.format(position.average_open_price)}</Table.Cell>
5358
<Table.Cell>{usdFormatter.format(position.mark_price)}</Table.Cell>
5459
<Table.Cell>
@@ -59,7 +64,7 @@ export const Positions: FC<{ symbol: string }> = ({ symbol }) => {
5964
{position.est_liq_price ? usdFormatter.format(position.est_liq_price) : '-'}
6065
</Table.Cell>
6166
<Table.Cell>
62-
<UpdatePosition symbol={symbol} position={position} refresh={refresh} />
67+
<UpdatePosition position={position} refresh={refresh} />
6368
</Table.Cell>
6469
</Table.Row>
6570
);

app/components/StopOrder.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ type Inputs = {
2020
};
2121

2222
export const StopOrder: FC<{
23-
symbol: string;
2423
position: API.PositionExt;
2524
refresh: import('swr/_internal').KeyedMutator<API.PositionInfo>;
2625
setOpen: Dispatch<SetStateAction<boolean>>;
27-
}> = ({ symbol, position, refresh, setOpen }) => {
26+
}> = ({ position, refresh, setOpen }) => {
2827
const [loading, setLoading] = useState(false);
2928

3029
const symbolsInfo = useSymbolsInfo();
@@ -39,7 +38,7 @@ export const StopOrder: FC<{
3938
});
4039
const { onSubmit, helper } = useOrderEntry(
4140
{
42-
symbol,
41+
symbol: position.symbol,
4342
side: OrderSide.BUY,
4443
order_type: OrderType.STOP_MARKET
4544
},
@@ -87,8 +86,8 @@ export const StopOrder: FC<{
8786
markPrice: Number(watch('trigger_price') ?? 0)
8887
});
8988

90-
const symbolInfo = symbolsInfo[symbol]();
91-
const [_, base, quote] = symbol.split('_');
89+
const symbolInfo = symbolsInfo[position.symbol]();
90+
const [_, base, quote] = position.symbol.split('_');
9291
const [baseDecimals, quoteDecimals] = getDecimalsFromTick(symbolInfo);
9392

9493
return (

app/components/TpSlOrder.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ type Inputs = {
1717
};
1818

1919
export const TpSlOrder: FC<{
20-
symbol: string;
2120
position: API.PositionExt;
2221
refresh: import('swr/_internal').KeyedMutator<API.PositionInfo>;
2322
setOpen: Dispatch<SetStateAction<boolean>>;
24-
}> = ({ symbol, position, refresh, setOpen }) => {
23+
}> = ({ position, refresh, setOpen }) => {
2524
const [loading, setLoading] = useState(false);
2625

2726
const symbolsInfo = useSymbolsInfo();
@@ -95,8 +94,8 @@ export const TpSlOrder: FC<{
9594
// markPrice: Number(watch('trigger_price') ?? 0)
9695
// });
9796

98-
const symbolInfo = symbolsInfo[symbol]();
99-
const [_, base, quote] = symbol.split('_');
97+
const symbolInfo = symbolsInfo[position.symbol]();
98+
const [_, base, quote] = position.symbol.split('_');
10099
const [baseDecimals, quoteDecimals] = getDecimalsFromTick(symbolInfo);
101100

102101
return (

app/components/UpdatePosition.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ import { TpSlOrder } from './TpSlOrder';
99
import { baseFormatter, usdFormatter } from '~/utils';
1010

1111
export const UpdatePosition: FC<{
12-
symbol: string;
1312
position: API.PositionExt;
1413
refresh: import('swr/_internal').KeyedMutator<API.PositionInfo>;
15-
}> = ({ symbol, position, refresh }) => {
14+
}> = ({ position, refresh }) => {
1615
const [open, setOpen] = useState(false);
1716

1817
const renderPositionValue = (header: string, value: string) => (
@@ -69,18 +68,13 @@ export const UpdatePosition: FC<{
6968
</Tabs.List>
7069

7170
<Tabs.Content value="close" className="mt-3">
72-
<ClosePosition
73-
symbol={symbol}
74-
position={position}
75-
refresh={refresh}
76-
setOpen={setOpen}
77-
/>
71+
<ClosePosition position={position} refresh={refresh} setOpen={setOpen} />
7872
</Tabs.Content>
7973
<Tabs.Content value="stop" className="mt-3">
80-
<StopOrder symbol={symbol} position={position} refresh={refresh} setOpen={setOpen} />
74+
<StopOrder position={position} refresh={refresh} setOpen={setOpen} />
8175
</Tabs.Content>
8276
<Tabs.Content value="tp_sl" className="mt-3">
83-
<TpSlOrder symbol={symbol} position={position} refresh={refresh} setOpen={setOpen} />
77+
<TpSlOrder position={position} refresh={refresh} setOpen={setOpen} />
8478
</Tabs.Content>
8579
</Tabs.Root>
8680
</Dialog.Content>

0 commit comments

Comments
 (0)