aster-ts-trading
v1.0.0
Published
TypeScript SDK for Aster REST and WebSocket trading APIs
Readme
aster-ts-trading
TypeScript SDK for Aster REST and WebSocket APIs.
Install
npm install aster-ts-tradingWhat This Library Includes
AsterClient: REST client for account, orders, transfers, withdraws, and Aster Code (builder/signer) endpoints.AsterWebSocketClient: reconnecting WebSocket client with subscribe/unsubscribe helpers.- Typed request/response interfaces and signing utilities.
Quick Start
import { AsterClient } from 'aster-ts-trading';
const client = new AsterClient({
apiKey: process.env.ASTER_API_KEY,
apiSecret: process.env.ASTER_API_SECRET,
});
const account = await client.getAccount();
console.log(account);WebSocket Usage
import { AsterWebSocketClient } from 'aster-ts-trading';
const ws = new AsterWebSocketClient('wss://fstream.asterdex.com/stream');
ws.connect();
ws.on('open', () => ws.subscribe(['btcusdt@aggTrade', 'btcusdt@bookTicker']));
ws.on('message', (msg) => console.log(msg));Funding Endpoints
import { AsterClient } from 'aster-ts-trading';
const client = new AsterClient({
apiKey: process.env.ASTER_API_KEY,
apiSecret: process.env.ASTER_API_SECRET,
});
const withdrawAssets = await client.getWithdrawAssets({
chainIds: '56',
accountType: 'spot',
networks: 'EVM',
});
const fee = await client.estimateWithdrawFee({
chainId: 56,
network: 'EVM',
currency: 'USDT',
accountType: 'spot',
});Aster Code (Builder/Signer) Flow
Use /fapi/v3/* EIP-712 endpoints for builder fee flow.
import { Wallet } from 'ethers';
import { AsterClient } from 'aster-ts-trading';
const client = new AsterClient({
baseUrl: 'https://fapi.asterdex.com',
asterChain: 'Mainnet',
signatureChainId: 56,
asterCodeMainDomainChainId: 56,
asterCodeMessageDomainChainId: 1666,
defaultBuilder: process.env.BUILDER_ADDRESS,
defaultBuilderFeeRate: '0.0001',
});
const mainWallet = new Wallet(process.env.MAIN_PRIVATE_KEY!);
const signerWallet = new Wallet(process.env.SIGNER_PRIVATE_KEY!);
await client.approveBuilder(
{
user: process.env.USER_ADDRESS!,
builder: process.env.BUILDER_ADDRESS!,
maxFeeRate: '0.0001',
},
mainWallet,
);
await client.placeBuilderOrder(
{
user: process.env.USER_ADDRESS!,
signer: signerWallet.address,
symbol: 'BTCUSDT',
type: 'LIMIT',
side: 'BUY',
quantity: '0.01',
price: '50000',
timeInForce: 'GTC',
},
signerWallet,
);Utility Helpers
The library exports helpers from utils:
createAsterWithdrawNonce()buildAsterWithdrawTypedData(...)signAsterWithdrawTypedData(...)createAsterCodeNonce()signAsterCodeMainTypedData(...)signAsterCodeMessageTypedData(...)
Development
npm run typecheck
npm run build