Skip to content

Commit

Permalink
Merge remote-tracking branch 'veeno/feat/doc-improvement'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarnadas committed Dec 23, 2024
2 parents 54e33c4 + cd633fa commit 788b0f7
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 1 deletion.
22 changes: 22 additions & 0 deletions sdks/hooks/account/use-account.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,25 @@ const nextState = await account.setAddress("<address>", {
}
});
```

### Switch Chain

```tsx
const account = useAccountInstance();

const handleChainSelect = (id: string) => {
// Remember to also switch chain in your wallet provider (e.g., wagmi, web3-onboard)
account.switchChainId(id);
}

return (
{supportedChains
.filter(({ network }) => network === "mainnet")
.map(({ id, icon, label, chainId }) => (
<button key={id} onClick={handleChainSelect(id)}>
{label}
</button>
))
}
);
```
2 changes: 1 addition & 1 deletion sdks/hooks/api/use-ws.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Subscribing to the `trade` topic:
const ws = useWS();

useEffect(() => {
const unsubscripe = ws.subscribe(
const unsubscribe = ws.subscribe(
{
id: `${symbol}@trade`,
event: "subscribe",
Expand Down
12 changes: 12 additions & 0 deletions sdks/hooks/assets/use-holding-stream.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ Receive current user holdings and auto update via Websockets.
```ts
const { usdc } = useHoldingStream();
```

The USDC object contains:

```ts
{
frozen: 0,
holding: 100,
pending_short: 0,
token: "USDC",
updated_time: 1732754429399
}
```
13 changes: 13 additions & 0 deletions sdks/hooks/market-data/use-market-trade-stream.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ Subscribe to [trades](/sdks/tech-doc/interfaces/orderly_network_types.API.Trade)

- [Tech docs](/sdks/tech-doc/modules/orderly_network_hooks#usemkarettradestream)

### Example

```tsx
const { data, isLoading } = useMarketTradeStream(symbol);
```

The returned data is an array of objects containing the following fields:

```ts
{
"price": 95731.5,
"side": "SELL",
"size": 0.1,
"ts": 1732805310368
}
```
23 changes: 23 additions & 0 deletions sdks/hooks/market-data/use-markets-stream.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,26 @@ Subscribe to all [tickers](/sdks/tech-doc/interfaces/orderly_network_types.WSMes
```ts
const { data } = useMarketsStream();
```

The returned data is an array of objects containing the following fields:

```ts
{
"24h_amount": 48108.464865,
"24h_close": 0.04286,
"24h_high": 0.044604,
"24h_low": 0.042574,
"24h_open": 0.042944,
"24h_volume": 1096083,
"24h_volumn": 1096083,
"change": 0.00195,
"est_funding_rate": 0.00012004,
"index_price": 0.042851,
"last_funding_rate": 0.0002316,
"mark_price": 0.042877,
"next_funding_time": 1732809600000,
"open_interest": 571430,
"sum_unitary_funding": 0.00118,
"symbol": "PERP_1000BONK_USDC"
}
```
12 changes: 12 additions & 0 deletions sdks/hooks/referral/use-daily.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ Returns `perp_volume` based on start and end time. If not passed, defaults to la

- [Tech docs](/sdks/tech-doc/modules/orderly_network_hooks#usedaily)

### Example

```ts
const { data } = useDaily();
```

The returned data is an array of objects containing the following fields:

```ts
{
"broker_id": "veeno_dex",
"date": "2024-11-11",
"perp_volume": 500
}
```
31 changes: 31 additions & 0 deletions sdks/hooks/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,34 @@ export const App: FC<PropsWithChildren> = ({ children }) => {
);
};
```

## Wallet Integration with Orderly Provider

The Orderly Provider enables seamless integration with different blockchain wallets.
It supports both EVM-compatible chains and Solana through dedicated wallet adapters.
Here's how to set up the provider with both ecosystems:

```tsx
import type { FC, PropsWithChildren } from "react";
import { OrderlyConfigProvider } from "@orderly.network/hooks";
import { DefaultEVMWalletAdapter } from "@orderly.network/default-evm-adapter";
import { DefaultSolanaWalletAdapter } from "@orderly.network/default-solana-adapter";
import { EthersProvider } from "@orderly.network/web3-provider-ethers";

const brokerId = "<your id>";

export const App: FC<PropsWithChildren> = ({ children }) => {
return (
<OrderlyConfigProvider
brokerId={brokerId}
networkId="testnet"
walletAdapters={[
new DefaultEVMWalletAdapter(new EthersProvider()),
new DefaultSolanaWalletAdapter()
]}
>
{children}
</OrderlyConfigProvider>
);
};
```
29 changes: 29 additions & 0 deletions sdks/hooks/util/use-local-storage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,32 @@ return (
</>
);
```

### Using with different data types

```tsx
type ChartConfig = {
timeframe: string;
indicators: string[];
theme: "light" | "dark";
};

const [chartConfig, setChartConfig] = useLocalStorage<ChartConfig>("CHART_CONFIG", {
timeframe: "1h",
indicators: ["MA", "RSI"],
theme: "light"
});

const toggleTheme = () => {
setChartConfig((prev) => ({
...prev,
theme: prev.theme === "light" ? "dark" : "light"
}));
};

return (
<button onClick={toggleTheme}>
Switch to {chartConfig.theme === "light" ? "dark" : "light"} theme
</button>
);
```

0 comments on commit 788b0f7

Please sign in to comment.