Complete trading workflows for Orderly Network DEX applications, from wallet connection through order execution, position management, and withdrawal.
在Orderly Network DEX应用中实现完整交易工作流的全面指南,涵盖从钱包连接到订单执行和仓位管理的全过程。
本技能涵盖端到端交易工作流:
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ 连接钱包 │────▶│ 充值资金 │────▶│ 执行交易 │
│ │ │ │ │ (订单) │
└──────────────┘ └──────────────┘ └──────────────┘
│
▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ 提现资金 │◀────│ 平仓操作 │◀────│ 监控仓位 │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
tsx
import { useAccount, AccountStatusEnum } from @orderly.network/hooks;
function TradingGuard({ children }) {
const { state, createAccount, createOrderlyKey } = useAccount();
switch (state.status) {
case AccountStatusEnum.NotConnected:
return
case AccountStatusEnum.Connected:
return (
创建您的Orderly账户以开始交易
case AccountStatusEnum.NotSignedIn:
return (
通过创建交易密钥启用交易功能
case AccountStatusEnum.SignedIn:
return children;
}
}
tsx
import { AuthGuard } from @orderly.network/ui-connector;
function TradingPage() {
return (
);
}
tsx
import { useDeposit } from @orderly.network/hooks;
function DepositForm() {
const { deposit, balance, allowance, approve, isNativeToken, quantity, setQuantity, depositFee } =
useDeposit({
address: 0xUSDC_ADDRESS,
decimals: 6,
srcChainId: 42161,
srcToken: USDC,
});
const handleDeposit = async () => {
try {
// 检查并在需要时授权
if (!isNativeToken && allowance < quantity) {
await approve();
}
// 执行充值
const result = await deposit();
toast.success(充值成功!);
} catch (error) {
toast.error(error.message);
}
};
return (
tsx
import { DepositForm } from @orderly.network/ui-transfer;
function DepositPage() {
return (
toast.success(充值成功!);
}}
/>
);
}
tsx
import { useCollateral } from @orderly.network/hooks;
function AccountBalance() {
const { totalCollateral, freeCollateral, totalValue, availableBalance, unsettledPnL } =
useCollateral({ dp: 2 });
return (
);
}
tsx
import { useMutation } from @orderly.network/hooks;
import { OrderType, OrderSide } from @orderly.network/types;
function MarketOrderButton({ symbol, side, quantity }) {
const [submitOrder] = useMutation(/v1/order);
const placeMarketOrder = async () => {
const order = {
symbol,
side,
order_type: OrderType.MARKET,
order_quantity: quantity,
};
try {
const result = await submitOrder(order);
if (result.success) {
toast.success(订单已提交:${result.data.order_id});
}
} catch (error) {
toast.error(error.message);
}
};
return (
);
}
tsx
function LimitOrderForm({ symbol }) {
const [submitOrder] = useMutation(/v1/order);
const [price, setPrice] = useState();
const [quantity, setQuantity] = useState();
const [side, setSide] = useState(OrderSide.BUY);
const placeLimitOrder = async () => {
const order = {
symbol,
side,
order_type: OrderType.LIMIT,
order_price: parseFloat(price),
order_quantity: parseFloat(quantity),
};
const result = await submitOrder(order);
if (result.success) {
toast.success(限价单已提交!);
}
};
return (
tsx
import { useOrderEntry } from @orderly.network/hooks;
import { OrderSide, OrderType } from @orderly.network/types;
function OrderEntryForm({ symbol }) {
const { formattedOrder, submit, maxQty, freeCollateral, errors, setValues } =
useOrderEntry(symbol);
useEffect(() => {
setValues({
side: OrderSide.BUY,
order_type: OrderType.LIMIT,
});
}, []);
const handleSubmit = async () => {
if (Object.keys(errors).length > 0) {
toast.error(请修正验证错误);
return;
}
try {
await submit();
toast.success(订单已提交!);
} catch (error) {
toast.error(error.message);
}
};
return (
tsx
import { useOrderStream } from @orderly.network/hooks;
function ActiveOrders({ symbol }) {
const [orders, { refresh }] = useOrderStream({
symbol,
status: OPEN,
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 orderly-sdk-trading-workflows-1776193107 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 orderly-sdk-trading-workflows-1776193107 技能
skillhub install orderly-sdk-trading-workflows-1776193107
文件大小: 4.86 KB | 发布时间: 2026-4-15 13:10