Docs
Hooks
Withdraw

Withdrawal

@orderly.network/hooks provides the following hooks to facilitate withdrawals:

  • useWithdraw - Withdraw

Terminology

Max withdrawable amount

The maximum balance that can be withdrawn at this moment (without having to settle PnL).

maxAmount

Available Balance

The available balance of the account, which is equal to the amount that can be withdrawn after settling all oustanding unsettled PnL.

availableBalance

unsettledPnL

Amount of PnL that has not been settled into the account balance yet. Balance will be available to withdraw once PnL has been settled (if positive).

All of the above data can be retrieved through useWithdraw.

const { withdraw, isLoading, maxAmount, availableBalance, unsettledPnL } =
  useWithdraw();

Withdraw

useWithdraw()

import { useWithdraw } from "@orderly.network/hooks";
 
const { withdraw, isLoading } = useWithdraw();
 
const res = await withdraw();

Withdrawal status

Subscribe to the relevant websocket topic to get updates on the withdrawal status.

import { useWS } from "@orderly.network/hooks";
 
//...
 
export const Example = () => {
  const ws = useWS();
 
  useEffect(() => {
    const unsubscribe = ws.subscribe(
      {
        id: "wallet",
        event: "subscribe",
        topic: "wallet",
        ts: Date.now(),
      },
      {
        onMessage: (data: any) => {
          //
        },
      }
    );
 
    return () => {
      unsubscribe();
    };
  }, [ws]);
};