0.0.10 • Published 7 months ago
@flashnet/js-sdk v0.0.10
FlashNet JavaScript SDK
A JavaScript SDK for interacting with the FlashNet trading platform, optimized for use with Bun runtime.
Prerequisites
- Bun runtime installed
- FlashNet API credentials (API key and secret)
- FlashNet mnemonic
Installation
bun installConfiguration
Create a .env file in the root directory with the following variables:
FLASHNET_BASE_URL=your_base_url
FLASHNET_WS_URL=your_websocket_url
FLASHNET_MNEMONIC=your_mnemonic
FLASHNET_API_KEY=your_api_key
FLASHNET_API_SECRET=your_api_secretFeatures
The SDK provides several clients for different aspects of the FlashNet platform:
AuthClient: Authentication and session managementTradingClient: Order execution and managementMarketsClient: Market data and metadataWebSocketClient: Real-time market data and order updates
Supported Operations
- Market data retrieval (orderbook, trades, etc.)
- Order management (submit, cancel, query)
- Real-time WebSocket subscriptions
- Authentication and session handling
- Market metadata synchronization
Usage
Basic Example
import { TradingClient } from './src/client/trading';
import { AuthClient } from './src/client/auth';
import { MarketsClient } from './src/client/markets';
import { WebSocketClient } from './src/client/ws';
// Initialize configuration
const config = {
baseUrl: process.env.FLASHNET_BASE_URL,
wsUrl: process.env.FLASHNET_WS_URL,
mnemonic: process.env.FLASHNET_MNEMONIC,
apiKey: process.env.FLASHNET_API_KEY,
apiSecret: process.env.FLASHNET_API_SECRET
};
// Initialize clients
const authClient = new AuthClient("REGTEST", config.baseUrl);
await authClient.initialize(config.mnemonic);
const marketsClient = new MarketsClient(authClient, config.baseUrl);
await marketsClient.initializeMetadata();
const wsClient = new WebSocketClient(authClient, config.wsUrl, null);
const tradingClient = new TradingClient(authClient, marketsClient, wsClient, config.baseUrl);
// Example: Get orderbook
const orderbook = await tradingClient.getOrderbook("BTC-USDB");
console.log("Orderbook:", orderbook);
// Example: Submit order
const order = {
side: OrderSide.Bid,
baseAsset: "BTC",
quoteAsset: "USDB",
quantity: "0.1",
price: "40000",
type: OrderType.Limit
};
const result = await tradingClient.submitOrder(order);Check the examples directory for more detailed usage examples.
Running Examples
bun run examples/example.tsDependencies
Core dependencies:
@flashnet/node-sdk: Core FlashNet SDK@flashnet/spark-wallet-sdk: Wallet integrationws: WebSocket client for real-time dataaxios: HTTP client for REST API calls
Development dependencies:
typescript: Type definitions and compilation@types/ws: TypeScript definitions for WebSocketbun-types: Type definitions for Bun runtime
Development
The project is structured as follows:
flashnet-js/
├── src/
│ ├── client/ # Client implementations
│ ├── types/ # TypeScript type definitions
│ └── utils/ # Utility functions
├── examples/ # Usage examples
├── tsconfig.json # TypeScript configuration
└── package.json # Project configurationLicense
MIT License. See LICENSE file for details.