Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/components/BalanceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const toThreePrecision = (value: string | number) => {

export default function BalanceTable(props: { data: any }) {
const validateData = (data: any) => {
if (!data || typeof data !== 'object') return {};
if (!data || typeof data !== "object") return {};

const maker = data.balances?.maker || {};
const taker = data.balances?.taker || {};

return {
Leverex: maker,
Bitfinex: taker
Bitfinex: taker,
};
};

Expand Down Expand Up @@ -51,14 +51,20 @@ export default function BalanceTable(props: { data: any }) {
</tr>
</thead>
<tbody>
{BitfinexState.balances?.margin && (
<tr>
<td>{toThreePrecision(BitfinexState.balances.margin.TESTUSDTF0?.total || 0)}</td>
<td>{toThreePrecision(BitfinexState.balances.margin.TESTUSDTF0?.free || 0)}</td>
<td>{toThreePrecision(BitfinexState.balances.margin.TESTUSDTF0?.reserved || 0)}</td>
<td>{JSON.stringify(BitfinexState.ccy)}</td>
</tr>
)}
{BitfinexState.balances &&
Object.keys(BitfinexState.balances.margin).map(
(key: string, index: React.Key | null | undefined) => {
const balance = BitfinexState.balances.margin[key];
return (
<tr key={index}>
<td>{toThreePrecision(balance?.total || 0)}</td>
<td>{toThreePrecision(balance?.free || 0)}</td>
<td>{toThreePrecision(balance?.reserved || 0)}</td>
<td>{key}</td>
</tr>
);
}
)}
</tbody>
</table>
</div>
Expand All @@ -77,7 +83,9 @@ export default function BalanceTable(props: { data: any }) {
</thead>
<tbody>
<tr>
<td>{new Date(LeverexState._timestamp || '').toUTCString()}</td>
<td>
{new Date(LeverexState._timestamp || "").toUTCString()}
</td>
<td>{toThreePrecision(LeverexState.balances?.USDT || 0)}</td>
<td>{toThreePrecision(LeverexState.balances?.USDP || 0)}</td>
<td>{LeverexState.ccy}</td>
Expand All @@ -90,4 +98,3 @@ export default function BalanceTable(props: { data: any }) {
</>
);
}

27 changes: 15 additions & 12 deletions src/components/PositionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ export default function PositionTable(props: { data: any }) {
);

const lOrder = React.useCallback(() => {
return Bitfinex.positions[Bitfinex.product][
Object.getOwnPropertyNames(Bitfinex.positions[Bitfinex.product])[0]
].position;
const positions = Bitfinex.positions[Bitfinex.product];
return (
positions?.[
Object.getOwnPropertyNames(Bitfinex.positions[Bitfinex.product])[0]
].position ?? []
);
}, [Bitfinex]);

const bOrder = React.useCallback(
() => ({
sessionIM: "",
...Leverex.orderData.orders[
...Leverex.orderData?.orders[
Object.getOwnPropertyNames(Leverex.orderData.orders)[0]
],
}),
Expand Down Expand Up @@ -67,14 +70,14 @@ export default function PositionTable(props: { data: any }) {
<td>{Bitfinex.netExposure}</td>
<td>{Bitfinex.openPrice}</td>
<td>{Bitfinex.product}</td>
<td>{lOrder().symbol}</td>
<td>{lOrder().base_price}</td>
<td>{lOrder().amount}</td>
<td>{lOrder().margin_funding}</td>
<td>{toThreePrecision(lOrder().profit_loss)}</td>
<td>{toThreePrecision(lOrder().liquidation_price)}</td>
<td>{toThreePrecision(lOrder().leverage)}</td>
<td>{toThreePrecision(lOrder().collateral)}</td>
<td>{lOrder().symbol ?? ""}</td>
<td>{lOrder().base_price ?? ""}</td>
<td>{lOrder().amount ?? ""}</td>
<td>{lOrder().margin_funding} ?? ''</td>
<td>{toThreePrecision(lOrder().profit_loss ?? "")}</td>
<td>{toThreePrecision(lOrder().liquidation_price ?? "")}</td>
<td>{toThreePrecision(lOrder().leverage ?? "")}</td>
<td>{toThreePrecision(lOrder().collateral ?? "")}</td>
</tr>
</tbody>
</table>
Expand Down