HyperSolid is a cryptocurrency trading application developed with Flutter, providing spot and perpetual contract trading capabilities. This WebView JSSDK project enables third-party Web applications to interact with the HyperSolid App, achieving seamless Web-to-Native communication.
┌─────────────────────────────────────────────────────────────────┐
│ HyperSolid App (Flutter) │
├─────────────────────────────────────────────────────────────────┤
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ UI Layer │ │ Business Logic │ │ Data Layer │ │
│ │ │ │ │ │ │ │
│ │ • Home Page │ │ • Trade Service │ │ • API Service │ │
│ │ • Trade Page │ │ • Wallet Service│ │ • Local Storage │ │
│ │ • Portfolio │ │ • Order Service │ │ • WebSocket │ │
│ │ • Account │ │ • Price Service │ │ • Database │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ WebView Bridge Layer │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ Bridge Manager │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌────────┐ │ │
│ │ │ Wallet │ │ Navigation │ │ Order │ │ System │ │ │
│ │ │ Handler │ │ Handler │ │ Handler │ │Handler │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └────────┘ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌────────┐ │ │
│ │ │ Position │ │ Price │ │ Asset │ │ Fill │ │ │
│ │ │ Handler │ │ Handler │ │ Handler │ │Handler │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └────────┘ │ │
│ └─────────────────────────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ WebView Container │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ Web Application │ │
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
│ │ │ HyperSolid JSSDK │ │ │
│ │ │ │ │ │
│ │ │ • wallet API • position API • order API │ │ │
│ │ │ • trading API • price API • navigation API │ │ │
│ │ │ • asset API • fill API • system API │ │ │
│ │ └─────────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ │ HTML + CSS + JavaScript │ │
│ └─────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Provides wallet connection status query, address retrieval, and balance inquiry functions.
Main Features:
- Get wallet connection information
- Query wallet address
- Get account balance
- Check connection status
Usage Examples:
// Get wallet information
const { data: walletInfo } = await HyperSolidSDK.wallet.getInfo();
console.log("Wallet address:", walletInfo.address);
// Get balance
const { data: balance } = await HyperSolidSDK.wallet.getWalletPerpBalance();
console.log("Account balance:", balance);This is the core functionality of the SDK, providing complete trading order capabilities, supporting both spot and perpetual contract trading.
Main Features:
- Limit Order Trading: Specify price for buy/sell orders
- Market Order Trading: Execute immediately at current market price
- Percentage-based Orders: Automatically calculate order size based on available funds percentage
- Position Management: Support reduce-only mode
- Dual Market Support: Spot trading and perpetual contract trading
API Detailed Description:
// Limit Buy (Long)
await HyperSolidSDK.trading.limitBuy({
symbol: "BTC", // Trading pair symbol
price: 50000, // Limit price
size: 0.001, // Trading quantity
isSpot: false, // false=perpetual contract, true=spot
reduceOnly: false, // Reduce-only mode
});
// Limit Sell (Short)
await HyperSolidSDK.trading.limitSell({
symbol: "BTC",
price: 52000,
size: 0.001,
isSpot: false,
reduceOnly: false,
});// Market Buy (automatically get current price)
await HyperSolidSDK.trading.marketBuy({
symbol: "BTC",
size: 0.001,
isSpot: false,
reduceOnly: false,
});
// Market Sell
await HyperSolidSDK.trading.marketSell({
symbol: "BTC",
size: 0.001,
isSpot: false,
reduceOnly: false,
});// Use 25% of available funds for limit buy
await HyperSolidSDK.trading.limitBuyByPercentage({
symbol: "BTC",
price: 50000,
percentage: 0.25, // 25% of available funds
isSpot: false,
reduceOnly: false,
});
// Use 50% of position for market sell
await HyperSolidSDK.trading.marketSellByPercentage({
symbol: "BTC",
percentage: 0.5, // 50% of position
isSpot: false,
reduceOnly: true,
});Technical Advantages of Trading API:
- Smart Price Retrieval: Market orders automatically get latest price from server
- Fund Management: Percentage orders automatically calculate maximum tradable amount
- Risk Control: Support reduce-only mode to prevent over-leverage
- Dual Market Support: Unified interface for both spot and contract trading
- Error Handling: Comprehensive exception handling and user feedback
Provides real-time position query and management functions.
Main Features:
- Get all position list
- Query specific coin position
- Long/short position filtering
- Position summary statistics
Usage Examples:
// Get all positions
const { data: positions } = await HyperSolidSDK.position.getPositions();
// Get BTC position
const { data: btcPosition } = await HyperSolidSDK.position.getPosition("BTC");
// Get long positions
const longPositions = await HyperSolidSDK.position.getLongPositions();Provides query and management functions for open orders.
Main Features:
- Get all open orders
- Query orders by coin
- Classify buy/sell orders
- Order statistics
Provides query functions for trade execution records.
Main Features:
- Get all fill history
- Query fills by coin
- Fill history summary
Provides real-time price data query functions.
Main Features:
- Get current price
- Get trade details
- Support spot and contract prices
Provides user asset data query functions.
Main Features:
- Get user asset data
- Query maximum trade size limits
Provides page navigation and routing control functions.
Main Features:
- Basic page navigation (Home, Trade, Portfolio, Account)
- Trade page navigation (with parameters)
- Custom route navigation
- Back operations
Provides system-level function calls.
Main Features:
- Page refresh
- Version information query
- System information retrieval
- Connectivity testing
- Asynchronous Communication: Promise-based asynchronous API design
- Type Safety: Provides TypeScript type definitions
- Error Handling: Unified error handling mechanism
- Timeout Control: 10 second request timeout protection
- State Management: SDK ready state detection
- Compatibility: Supports modern browsers and WebView environments
<script src="./jssdk/hypersolid-sdk.js"></script>if (HyperSolidSDK.utils.isReady()) {
console.log("SDK is ready");
} else {
HyperSolidSDK.utils.onReady(() => {
console.log("SDK initialization completed");
});
}try {
const result = await HyperSolidSDK.wallet.getInfo();
console.log("Call successful:", result);
} catch (error) {
console.error("Call failed:", error.message);
}- All API calls are verified through Flutter side
- Support wallet connection status checking
- Provide comprehensive error handling mechanism
- Timeout protection prevents long waiting times
- Current Version: 1.0.0
- Compatibility: Supports Flutter WebView
- Update Date: 2025
This document is the technical specification for HyperSolid WebView JSSDK. For detailed API reference, please check the test examples in index.html.