@liberfi.io/ui-perpetuals 0.1.49 → 0.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # @liberfi.io/ui-perpetuals
2
+
3
+ `@liberfi.io/ui-perpetuals` provides perpetual trading UI widgets, container hooks, and typed client contracts for the Liberfi React SDK. It is designed for host apps that want ready-to-use perpetual modules (order book, trades, place order, positions, orders, history) while still controlling networking, side effects, and provider wiring.
4
+
5
+ ## Design Philosophy
6
+
7
+ - Keep data logic and presentation separated (`*.script.tsx` + `*.ui.tsx` + `*.widget.tsx`).
8
+ - Keep client integration explicit via `PerpetualsProvider` and `usePerpetualsClient`.
9
+ - Prefer typed hooks over ad-hoc data fetching to keep cache keys and API calls consistent.
10
+ - Expose building blocks (UI + hooks + types) so consumers can compose custom flows.
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pnpm add @liberfi.io/ui-perpetuals
16
+ ```
17
+
18
+ Required peer dependencies:
19
+
20
+ - `react`
21
+ - `react-dom`
22
+ - `@tanstack/react-query`
23
+ - `react-hook-form`
24
+
25
+ ## API Reference
26
+
27
+ ### Components
28
+
29
+ - `CoinInfoWidget(props: CoinInfoWidgetProps)`
30
+ - `CoinInfoUI(props: CoinInfoUIProps)`
31
+ - `CoinInfoSkeletonsUI()`
32
+ - `CoinInfoNotFoundUI()`
33
+ - `SearchCoinsWidget(props: SearchCoinsWidgetProps)`
34
+ - `SearchCoinsUI(props: SearchCoinsUIProps)`
35
+ - `OrderBookWidget(props: OrderBookWidgetProps)`
36
+ - `OrderBookUI(props: OrderBookUIProps)`
37
+ - `TradesWidget(props: TradesWidgetProps)`
38
+ - `TradesUI(props: TradesUIProps)`
39
+ - `PlaceOrderFormWidget(props: PlaceOrderFormWidgetProps)`
40
+ - `PlaceOrderFormUI(props: PlaceOrderFormUIProps)` (uses `react-hook-form` `UseFormReturn`)
41
+ - `PositionsWidget(props: PositionsWidgetProps)`
42
+ - `PositionsUI(props: PositionsUIProps)`
43
+ - `PositionsSkeleton()`
44
+ - `PositionsEmpty()`
45
+ - `OpenOrdersWidget(props: OpenOrdersWidgetProps)`
46
+ - `OpenOrdersUI(props: OpenOrdersUIProps)`
47
+ - `OpenOrdersSkeleton()`
48
+ - `OpenOrdersEmpty()`
49
+ - `TradeHistoryWidget(props: TradeHistoryWidgetProps)`
50
+ - `TradeHistoryUI(props: TradeHistoryUIProps)`
51
+ - `TradeHistorySkeleton()`
52
+ - `TradeHistoryEmpty()`
53
+ - `PerpetualsProvider(props: PerpetualsProviderProps)`
54
+
55
+ ### Hooks
56
+
57
+ - Context hook:
58
+ - `usePerpetualsClient()`
59
+ - Query hooks:
60
+ - `useCoinsQuery`, `useMarketQuery`, `useMarketsQuery`, `useKlinesQuery`
61
+ - `useOrderBookQuery`, `useRecentTradesQuery`
62
+ - `usePositionsQuery`, `useOrdersQuery`, `useTradesQuery`
63
+ - Mutation hooks:
64
+ - `useCreateOrderMutation`, `useCancelOrderMutation`
65
+ - Subscription hooks:
66
+ - `useMarketDataSubscription`, `useCandlesSubscription`, `useUserDataSubscription`
67
+ - Component script hooks:
68
+ - `useCoinInfo`, `useSearchCoinsScript`, `useOrderBookScript`, `useTradesScript`
69
+ - `usePlaceOrderFormScript`, `usePositionsScript`, `useOpenOrdersScript`, `useTradeHistoryScript`
70
+ - Also exported helpers from hook modules:
71
+ - Query keys and fetchers such as `coinsQueryKey`/`fetchCoins`, `marketQueryKey`/`fetchMarket`, `ordersQueryKey`/`fetchOrders`, etc.
72
+ - Trade operation helpers: `createOrder`, `cancelOrder`.
73
+
74
+ ### Functions / Utilities
75
+
76
+ - `HyperliquidPerpetualsClient` class implementing `IPerpetualsClient`.
77
+ - `usePerpetualsClient()` as the context accessor utility.
78
+
79
+ ### Types & Enums
80
+
81
+ - Client-related:
82
+ - `IPerpetualsClient`, `HyperliquidClientConfig`, `HyperliquidEnvironment`, `HyperliquidApiError`
83
+ - `PerpetualsContextValue`, `PerpetualsProviderProps`
84
+ - Domain enums/types:
85
+ - `Symbol`, `TradingProvider`, `OrderSide`, `OrderType`, `OrderStatus`, `KlineInterval`, `TradeSide`
86
+ - Domain entities:
87
+ - `Coin`, `MarketData`, `Kline`, `OrderBookLevel`, `OrderBook`, `Trade`, `Account`
88
+ - `Position`, `Order`, `TradeHistory`
89
+ - Request/response contracts:
90
+ - `PlaceOrderParams`, `CancelOrderParams`, `GetPositionsParams`, `GetOpenOrdersParams`, `GetTradesParams`
91
+ - `PlaceOrderResult`, `CancelOrderResult`, `GetPositionsResult`, `GetOpenOrdersResult`, `GetTradesResult`
92
+ - UI and script props/result types:
93
+ - All `*Props`, `Use*Params`, `Use*Result` types re-exported by each component/hook index.
94
+
95
+ ### Constants
96
+
97
+ - `version` (package version string).
98
+
99
+ ## Usage Examples
100
+
101
+ ```tsx
102
+ import {
103
+ HyperliquidPerpetualsClient,
104
+ PerpetualsProvider,
105
+ PlaceOrderFormWidget,
106
+ OrderBookWidget,
107
+ TradesWidget,
108
+ } from "@liberfi.io/ui-perpetuals";
109
+
110
+ const client = new HyperliquidPerpetualsClient({ environment: "testnet" });
111
+
112
+ export function PerpsPanel() {
113
+ return (
114
+ <PerpetualsProvider client={client}>
115
+ <OrderBookWidget symbol="BTC-USDC" />
116
+ <TradesWidget symbol="BTC-USDC" />
117
+ <PlaceOrderFormWidget symbol="BTC-USDC" userAddress="0x..." />
118
+ </PerpetualsProvider>
119
+ );
120
+ }
121
+ ```
122
+
123
+ ```tsx
124
+ import { useForm } from "react-hook-form";
125
+ import {
126
+ PlaceOrderFormUI,
127
+ type PlaceOrderFormData,
128
+ } from "@liberfi.io/ui-perpetuals";
129
+
130
+ const methods = useForm<PlaceOrderFormData>({
131
+ defaultValues: {
132
+ amount: 0,
133
+ leverage: 1,
134
+ takeProfitPercent: 0,
135
+ stopLossPercent: 0,
136
+ },
137
+ });
138
+
139
+ // Pass methods directly to PlaceOrderFormUI if you build your own container.
140
+ ```
141
+
142
+ ## Future Improvements
143
+
144
+ - Add integration tests for order submit/cancel and subscription lifecycle.
145
+ - Add i18n wiring for all user-facing strings in `ui-perpetuals` components.
146
+ - Replace placeholder account/margin values in place-order script with real account sources.