API

Complete API documentation for the Based Terminal MiniApp SDK.

Table of Contents

  • Installation

  • Core SDK

  • React Integration

  • Types

  • Permissions

  • Events

  • Error Handling

Installation

npm install @basedone/miniapp-sdk

Core SDK

MiniAppSDK Class

The main client for interacting with the Based Terminal.

Constructor

import { MiniAppSDK } from '@basedone/miniapp-sdk';

const client = new MiniAppSDK(config: MiniAppConfig);

MiniAppConfig:

Example:

Connection Methods

connect()

Establishes connection to the terminal.

Example:

disconnect()

Closes the connection.

Example:

getConnectionState()

Returns current connection state.

Returns:

Permission Methods

requestPermissions()

Requests multiple permissions from the user.

Example:

hasPermission()

Checks if a specific permission is granted.

Example:

Trading Methods

placeOrder()

Places a single order.

SubmitOrderCommand:

Example:

placeOrders()

Places multiple orders in a batch (up to 50).

Example:

cancelOrder()

Cancels a single order.

Example:

cancelOrders()

Cancels multiple orders in a batch (up to 50).

Example:

getOrders()

Queries orders with optional filtering.

Example:

getPositions()

Retrieves current positions.

Example:

getAccount()

Retrieves account balance information.

Example:

getWalletAddress()

Retrieves the connected wallet address.

Example:

Market Data Methods

subscribeToMarkets()

Subscribes to market data for specified symbols.

Example:

subscribe()

Generic subscription method for various data types.

MiniAppSubscriptionType:

Example:

unsubscribe()

Unsubscribes from a data stream.

Command Execution

sendCommand()

Generic method to send any command.

Available Commands:

Example:

Event Methods

on()

Registers an event listener.

Event Types:

Example:

off()

Removes an event listener.

Example:

emit()

Emits an event (internal use).

Theme Management

applyTheme()

Applies the terminal's theme to your MiniApp.

Example:

getThemeManager()

Gets the theme manager instance.

Example:

Cleanup

destroy()

Cleans up the SDK instance and removes all listeners.

Example:

React Integration

MiniAppProvider

Context provider for React applications.

Props:

Example:

Hooks

useMiniApp()

Main hook for accessing the SDK client and state.

Example:

useCommand()

Hook for executing commands with loading state.

Example:

useMarketData()

Hook for subscribing to market data.

Example:

usePositions()

Hook for tracking positions.

Example:

useWalletAddress()

Hook for accessing wallet address.

Example:

useTheme()

Hook for theme management.

Example:

useEvent()

Hook for subscribing to events.

Example:

Types

Order Types

Response Types

Order Status Types (Discriminated Union)

Permissions

Permission Types

Events

See the Event Methods section for complete event documentation.

Error Handling

Error Types

Error Handling Pattern

Last updated