Build trading interfaces using pre-built React components - OrderEntry, Positions, TradingPage, WalletConnect, Sheets, Tables
本技能涵盖使用 @orderly.network/react 中 Orderly 预构建的 React 组件构建交易界面。
bash
npm install @orderly.network/react @orderly.network/hooks @orderly.network/types
使用所需的提供器包裹您的应用:
typescript
import {
OrderlyAppProvider,
TradingPageProvider,
SymbolProvider,
WalletConnector
} from @orderly.network/react;
import { QueryClient, QueryClientProvider } from @tanstack/react-query;
const queryClient = new QueryClient();
function App() {
return (
chainFilter={[42161, 421614]}
>
);
}
typescript
import { OrderEntry, OrderEntryProvider } from @orderly.network/ui-order-entry;
import { useOrderEntry } from @orderly.network/hooks;
function OrderEntryContainer() {
const { onSubmit } = useOrderEntry();
const handleSubmit = async (params: any) => {
try {
await onSubmit(params);
console.log(订单已提交);
} catch (e) {
console.error(订单失败, e);
}
};
return (
export function OrderEntryWidget() {
return (
);
}
typescript
interface OrderEntryProps {
onSubmit?: (params: OrderParams) => Promise
defaultTab?: limit | market;
hideMarket?: boolean;
hideLimit?: boolean;
showLeverage?: boolean;
className?: string;
}
持仓组件
typescript
import { Positions } from @orderly.network/ui-positions;
export function PositionsWidget() {
const handleSymbolClick = (symbol: string) => {
console.log(导航到:, symbol);
};
return (
typescript
interface PositionsProps {
filter?: {
symbol?: string;
side?: BUY | SELL;
};
onSymbolClick?: (symbol: string) => void;
showPagination?: boolean;
pageSize?: number;
className?: string;
}
typescript
import { Orderbook, OrderbookProvider } from @orderly.network/ui-orderbook;
export function OrderbookWidget({ symbol }: { symbol: string }) {
return (
showTotal={true} // 显示总量列
onItemClick={(price, side) => {
console.log(价格被点击:, price, side);
}}
/>
);
}
typescript
import { WalletConnect } from @orderly.network/react;
export function Header() {
return (
);
}
typescript
import { useAccount, useWalletConnector } from @orderly.network/hooks;
export function CustomWalletButton() {
const { account, state } = useAccount();
const wallet = useWalletConnector();
if (state.status !== connected) {
return (
);
}
return (
typescript
import { TradingView } from @orderly.network/ui-chart;
export function ChartWidget({ symbol }: { symbol: string }) {
return (
typescript
import { LightweightChart } from @orderly.network/ui-chart;
export function SimpleChart({ symbol }: { symbol: string }) {
return (
typescript
import { Table } from @orderly.network/ui;
type TradeRow = {
id: string;
price: number;
size: number;
time: string;
side: BUY | SELL;
};
export function TradesTable({ data }: { data: TradeRow[] }) {
return (