TypeScript SDK for Coins API - Spot Trading, Wallet, Convert, Fiat, P2P Transfer and Invoice Payment functionality.
npm install coins-js-api- TypeScript Support: Full TypeScript support with type definitions
- Comprehensive API Coverage: Supports all Coins API endpoints
- Modern Async/Await: Uses modern JavaScript async/await syntax
- Secure Authentication: Built-in HMAC SHA256 signature generation
- Easy to Use: Simple and intuitive API design
import { CoinsApiClient, CoinsApiConfig } from 'coins-js-api';
// Create configuration
const config = CoinsApiConfig.builder()
.setApiKey('your-api-key')
.setSecretKey('your-secret-key')
.build();
// Or use direct instantiation
const config = new CoinsApiConfig({
apiKey: 'your-api-key',
secretKey: 'your-secret-key',
baseUrl: 'https://api.coins.ph', // optional
recvWindow: 5000, // optional
});
// Create client
const client = new CoinsApiClient(config);
// Use the API
async function example() {
try {
// Get account information
const account = await client.wallet().getAccount();
console.log('Account:', account);
// Create a new order
const order = await client.spotTrading().newOrder({
symbol: 'BTCUSDT',
side: 'BUY',
type: 'LIMIT',
timeInForce: 'GTC',
quantity: '0.001',
price: '50000',
});
console.log('Order:', order);
// Get convert quote
const quote = await client.convert().getQuote({
fromCoin: 'BTC',
toCoin: 'USDT',
fromAmount: '0.001',
});
console.log('Quote:', quote);
} catch (error) {
console.error('Error:', error);
}
}
example();// Get trading fees
const fees = await client.spotTrading().getTradeFee({ symbol: 'BTCUSDT' });
// Get trade history
const trades = await client.spotTrading().getMyTrades({
symbol: 'BTCUSDT',
limit: 10,
});
// Get open orders
const openOrders = await client.spotTrading().getOpenOrders({ symbol: 'BTCUSDT' });
// Cancel order
const cancelled = await client.spotTrading().cancelOrder({ orderId: 12345 });
// Cancel all orders
const cancelledAll = await client.spotTrading().cancelAllOrders({ symbol: 'BTCUSDT' });// Get account info
const account = await client.wallet().getAccount();
// Get deposit address
const address = await client.wallet().getDepositAddress({
coin: 'BTC',
network: 'BTC',
});
// Get deposit history
const deposits = await client.wallet().getDepositHistory('BTC');
// Apply for withdrawal
const withdrawal = await client.wallet().applyWithdraw({
coin: 'BTC',
address: 'your-btc-address',
amount: '0.001',
network: 'BTC',
});
// Get transaction history
const history = await client.wallet().getTransactionHistory({
tokenId: 'BTC',
pageNum: 1,
pageSize: 10,
});// Get conversion quote
const quote = await client.convert().getQuote({
fromCoin: 'BTC',
toCoin: 'USDT',
fromAmount: '0.001',
});
// Accept quote
const result = await client.convert().acceptQuote({
quoteId: quote.quoteId,
});
// Get order history
const orders = await client.convert().getOrderHistory();// Get channel configuration
const config = await client.fiat().getChannelConfig({
fiatCurrency: 'PHP',
transactionType: 'BUY',
});
// Cash out
const cashout = await client.fiat().cashOut({
fiatCurrency: 'PHP',
cryptoCurrency: 'BTC',
amount: '1000',
paymentMethod: 'BANK_TRANSFER',
});
// Generate QR code
const qrCode = await client.fiat().generateQrCode({
coin: 'BTC',
amount: '0.001',
description: 'Payment for order #123',
});// Transfer to another user
const transfer = await client.p2pTransfer().transfer({
coin: 'BTC',
amount: '0.001',
toEmail: 'user@example.com',
});
// Get transfer history
const transfers = await client.p2pTransfer().getTransfers();// Create payment request
const payment = await client.payment().createPaymentRequest({
currency: 'PHP',
amount: '1000',
description: 'Payment for service',
redirectUrl: 'https://example.com/callback',
});
// Get payment request
const paymentDetails = await client.payment().getPaymentRequest({
id: payment.paymentRequest.id,
});
// List payment requests
const payments = await client.payment().listPaymentRequests(1, 10);import { CoinsApiException } from 'coins-js-api';
try {
const result = await client.spotTrading().newOrder({
symbol: 'BTCUSDT',
side: 'BUY',
type: 'LIMIT',
quantity: '0.001',
price: '50000',
});
} catch (error) {
if (error instanceof CoinsApiException) {
console.error('API Error Code:', error.getCode());
console.error('API Error Message:', error.message);
} else {
console.error('Unknown Error:', error);
}
}const config = new CoinsApiConfig({
apiKey: 'your-api-key', // Required: Your API key
secretKey: 'your-secret-key', // Required: Your secret key
baseUrl: 'https://api.coins.ph', // Optional: API base URL (default: https://api.coins.ph)
recvWindow: 5000, // Optional: Request validity window in ms (default: 5000)
});This library is written in TypeScript and provides full type definitions for all API requests and responses.
import {
NewOrderRequest,
NewOrderResponse,
OrderResponse,
TradeVo,
// ... and many more types
} from 'coins-js-api';# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev
# Run linter
npm run lint
# Format code
npm run formatMIT
For issues and questions, please visit the GitHub repository.