0.0.10 • Published 11 months ago

@flashnet/js-sdk v0.0.10

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

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 install

Configuration

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_secret

Features

The SDK provides several clients for different aspects of the FlashNet platform:

  • AuthClient: Authentication and session management
  • TradingClient: Order execution and management
  • MarketsClient: Market data and metadata
  • WebSocketClient: 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.ts

Dependencies

Core dependencies:

  • @flashnet/node-sdk: Core FlashNet SDK
  • @flashnet/spark-wallet-sdk: Wallet integration
  • ws: WebSocket client for real-time data
  • axios: HTTP client for REST API calls

Development dependencies:

  • typescript: Type definitions and compilation
  • @types/ws: TypeScript definitions for WebSocket
  • bun-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 configuration

License

MIT License. See LICENSE file for details.

0.0.10

11 months ago

0.0.9

11 months ago

0.0.8

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

1 year ago