@binance/types
v1.0.11
Published
Shared types for Binance connectors
Downloads
248
Maintainers
Readme
Binance TypeScript Types
@binance/types is a TypeScript type definition package for Binance modular connectors. It centralizes shared interfaces, types, and error classes, ensuring consistency across all Binance Connectors.
This package is designed to be used with the modular Binance connectors.
Table of Contents
Features
- Centralized Type Definitions for Binance REST/WebSocket APIs
- Error Classes for standardized exception handling
- Shared Configuration Interfaces used across all Binance Connectors
- Lightweight & Tree-Shakeable – excludes runtime values when possible
- Fully Compatible with TypeScript for strong type safety
Installation
To use this package, install it via npm:
npm install @binance/typesUsage
This package provides types and error classes to be used within Binance Connectors.
Example: Importing Common Types
import type { ConfigurationRestAPI } from '@binance/types';
const config: ConfigurationRestAPI = {
apiKey: 'your-api-key',
apiSecret: 'your-api-secret',
};Example: Handling Errors Consistently
import { ConnectorClientError, UnauthorizedError } from '@binance/types';
try {
// Some API call
} catch (err) {
if (err instanceof ConnectorClientError) {
console.error('Client error occurred:', err);
} else if (err instanceof UnauthorizedError) {
console.error('Invalid API credentials:', err);
} else {
console.error('Unexpected error:', err);
}
}Available Types
API Response Types
RestApiResponse<T>– Standardized REST API response structureWebsocketApiResponse<T>– WebSocket response format
Configuration Types
ConfigurationRestAPI– Configuration structure for REST API clientsConfigurationWebsocketAPI– Configuration for WebSocket API clientsConfigurationWebsocketStreams– Config for managing WebSocket streams
Rate Limit Types
RestApiRateLimitWebsocketApiRateLimit
Error Handling
The package includes predefined error classes to simplify error handling across Binance SDKs.
| Error Class | Description |
| ---------------------- | --------------------------------- |
| ConnectorClientError | Generic client error |
| RequiredError | Missing required parameter |
| UnauthorizedError | Invalid or missing API key |
| ForbiddenError | Access denied |
| TooManyRequestsError | Rate limit exceeded |
| RateLimitBanError | Banned due to excessive API calls |
| ServerError | Internal Binance server error |
| NetworkError | Network connectivity issue |
| NotFoundError | Requested resource not found |
| BadRequestError | Malformed request |
Example: Catching API Errors
import { RequiredError, NotFoundError } from '@binance/types';
try {
// API call
} catch (err) {
if (err instanceof RequiredError) {
console.error('Missing required parameters:', err);
} else if (err instanceof NotFoundError) {
console.error('Requested resource does not exist:', err);
}
}Contributing
Contributions are welcome!
- Open a GitHub issue before making changes.
- Discuss proposed changes with maintainers.
- Follow the existing TypeScript structure.
License
This project is licensed under the MIT License - see the LICENSE file for details.
