Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add return data type & fix some exemple issue #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions sdks/hooks/assets/use-chain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,53 @@ Receive chain information for a given token.
```ts
const { chains, isLoading } = useChain("USDC");
```

### Return Type

```typescript
interface ChainResponse {
chain_details: Array<{
chain_id: string;
chain_name: string;
contract_address: string;
cross_chain_withdrawal_fee: number;
decimals: number;
display_name: string;
withdrawal_fee: number;
}>;
decimals: number;
minimum_withdraw_amount: number;
token: string;
token_hash: string;
}
```

### Usage

```typescript
import { useChain } from "@orderly.network/hooks";

function ChainInfo() {
const { data } = useChain("USDC");

return (
<div>
{data.chain_details.map((chain) => (
<div key={chain.chain_id}>
<div>Network: {chain.chain_name}</div>
<div>Contract: {chain.contract_address}</div>
<div>Withdrawal Fee: {chain.withdrawal_fee} USDC</div>
</div>
))}
</div>
);
}
```

### Features

- Supports multiple chains
- Chain-specific contract addresses
- Withdrawal fee information
- Token decimals and minimums
- Cross-chain transfer details
56 changes: 56 additions & 0 deletions sdks/hooks/funding/use-funding-rate.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,59 @@ Receive funding rate for given symbol.
```ts
const fundingRate = useFundingRate("PERP_ETH_USDC");
```

## Return Type

```typescript
interface FundingRateData {
// Time remaining until next funding in format "HH:MM:SS"
countDown: string;

// Estimated funding rate for next period
est_funding_rate: string;

// Timestamp when estimated rate was calculated
est_funding_rate_timestamp: number;

// Last funding rate that was charged/paid
last_funding_rate: number;

// Timestamp of last funding rate
last_funding_rate_timestamp: number;

// Timestamp of next funding event
next_funding_time: number;

// Cumulative funding since position opened
sum_unitary_funding: number;

// Trading pair symbol
symbol: string;
}
```

## Usage

```typescript
import { useFundingRate } from "@orderly.network/hooks";

function FundingRateDisplay() {
const fundingRate = useFundingRate("PERP_ETH_USDC");

return (
<div>
<div>Next Funding: {fundingRate.countDown}</div>
<div>Est. Rate: {fundingRate.est_funding_rate}</div>
<div>Last Rate: {fundingRate.last_funding_rate}</div>
</div>
);
}
```

## Funding Rate Details

- Funding occurs every 8 hours
- Rates are displayed in percentage format
- Positive rates mean longs pay shorts
- Negative rates mean shorts pay longs
- Timestamps are in Unix milliseconds
19 changes: 18 additions & 1 deletion sdks/hooks/market-data/use-index-price.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,22 @@ Receive index price for given symbol and auto update via Websockets.
### Example

```ts
const indexPrice: number = useIndexPrice("PERP_ETH_USDC");
import { useIndexPrice } from "@orderly.network/hooks";

const { data: indexPrice } = useIndexPrice("PERP_ETH_USDC");
```

### Return Type

```typescript
interface IndexPriceResponse {
data: number; // Current index price in USDC
}
```

### Features

- WebSocket updates
- USDC denominated
- Used for funding calculations
- Reflects spot market price
29 changes: 28 additions & 1 deletion sdks/hooks/market-data/use-mark-price.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,32 @@ Receive mark price for given symbol and auto update via Websockets.
### Example

```ts
const markPrice: number = useMarkPrice("PERP_ETH_USDC");
const markPrice = useMarkPrice("PERP_ETH_USDC");
```

### Return Type

```typescript
interface MarkPriceResponse {
data: number; // Current mark price in USDC
}
```

### Usage

```typescript
import { useMarkPrice } from "@orderly.network/hooks";

function PriceDisplay() {
const { data: price } = useMarkPrice("PERP_ETH_USDC");

return <div>ETH Price: ${price}</div>;
}
```

### Features

- Real-time updates via WebSocket
- Price in USDC terms
- Auto-reconnect on disconnect
- Efficient single pair subscription
41 changes: 41 additions & 0 deletions sdks/hooks/market-data/use-mark-prices-stream.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,44 @@ Get list of all mark prices in a `symbol` -> `price` map.
```ts
const { data: markPrices }: { data: Record<string, number> } = useMarkPricesStream();
```

### Return

```typescript
PERP_1000APU_USDC: 0.448
PERP_1000BONK_USDC: 0.030194
PERP_1000FLOKI_USDC: 0.137867
PERP_1000PEPE_USDC: 0.015262
PERP_1000SHIB_USDC: 0.019946
PERP_1000000MOG_USDC: 1.5348
...
```

### Usage

```typescript
import { useMarkPricesStream } from "@orderly.network/hooks";

function PricesDisplay() {
const { data: markPrices } = useMarkPricesStream();

return (
<div>
{Object.entries(markPrices).map(([symbol, price]) => (
<div key={symbol}>
{symbol}: ${price}
</div>
))}
</div>
);
}
```

### Features

- Real-time WebSocket stream
- Provides mark prices for all perpetual trading pairs
- Price updates on each tick
- Prices in USDC terms
- Common pairs include BTC, ETH, SOL and other major assets
- Also includes pairs with 1000x or 1000000x multipliers for low-value tokens
65 changes: 46 additions & 19 deletions sdks/hooks/market-data/use-ticker-stream.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,52 @@ This hooks streams [market information](/sdks/tech-doc/interfaces/orderly_networ

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

### Example
## Usage

```tsx
const marketInfo = useTickerStream("PERP_BTC_USDC");

return (
<>
<div className="flex flex-col">
<div className="color-gray">Mark</div>
<div>{stream.mark_price}</div>
</div>
<div className="flex flex-col">
<div className="color-gray">Index</div>
<div>{stream.index_price}</div>
</div>
<div className="flex flex-col">
<div className="color-gray">24h volume</div>
<div>{stream["24h_amount"]}</div>
</div>
</>
);
import { useTickerStream } from "@orderly.network/hooks";

function MarketInfo() {
const marketInfo = useTickerStream("PERP_BTC_USDC");

return (
<>
<div>Mark Price: ${marketInfo.mark_price}</div>
<div>24h Change: {marketInfo["24h_change"]}%</div>
<div>24h Volume: ${marketInfo["24h_amount"]}</div>
</>
);
}
```

### Return Type

```typescript
interface TickerStreamResponse {
"24h_amount": number; // 24h trading volume in USDC
"24h_change": number; // Price change in last 24h
"24h_close": number; // Latest price in 24h period
"24h_high": number; // Highest price in 24h
"24h_low": number; // Lowest price in 24h
"24h_open": number; // Opening price 24h ago
"24h_volume": number; // Trading volume in base currency
change: number; // Price change percentage
est_funding_rate: number; // Estimated next funding rate
index_price: number; // Current index price
last_funding_rate: number; // Last paid funding rate
mark_price: number; // Current mark price
next_funding_time: number; // Next funding timestamp
open_interest: number; // Total open interest
sum_unitary_funding: number; // Cumulative funding
symbol: string; // Trading pair symbol
}
```

### Features

- Real-time WebSocket updates
- Comprehensive market data
- Price metrics and changes
- Volume information
- Funding rate details
- Open interest tracking