@kofeinstyle/tradernet-sdk
v0.0.1-beta.8
Published
Tradernet API typescript client
Maintainers
Readme
Tradernet SDK
A comprehensive TypeScript/JavaScript client library for the Tradernet trading platform API.
Docs - https://tradernet.ua/tradernet-api
Features
- 💼 Report Data - Data array on trades for the requested report period
- 📝 User Cash flow - Obtaining data on the client's cash flow
- 📊 Market Data - Real-time and historical market data (🔮 Coming Soon)
- 💼 Portfolio - Portfolio and position tracking (🔮 Coming Soon)
- 🔌 WebSocket - Real-time data streaming with auto-reconnection (🔮 Coming Soon)
- 📝 TypeScript - Full TypeScript support with comprehensive types
- 🧪 Tested - Comprehensive test suite with Jest
- 🔄 Retry Logic - Automatic retry with exponential backoff
- 📦 Lightweight - Zero external dependencies
Installation
npm install @kofeinstyle/tradernet-sdkQuick Start
import { TradernetApiClient } from '@kofeinstyle/tradernet-sdk';
// Initialize client
const client = new TradernetApiClient({
apiKey: 'testApiKey',
apiSecret: 'testApiSecret',
});Get report data
const result = await client.getBrokerReport({dateFrom: '2025-01-01', dateTo: '2025-21-31'});
console.log('Report data:', result.data);Get user cash flow data
const filter = [{ field: 'type_code', operator: 'eq', value: 'dividend'}]
const result = await client.getUserCashFlows({take: 100, skip: 0, filter: filter});
console.log('Cashflow data:', result.data.cashflow);API Methods
Reports
getBrokerReport(dateRange, attempt)- Getting the broker's report by date rangegetUserCashFlows(params)- Getting the user's cash flow by filter. (Like tax, dividend, etc)
Market Data (🚧 Planned for Future Versions)
getTicker(symbol)- Get ticker data for a symbolgetTickers(symbols)- Get ticker data for multiple symbolsgetQuote(symbol)- Get bid/ask quote datagetCandles(symbol, interval, limit)- Get historical candle data
Portfolio (🚧 Planned for Future Versions)
getPortfolio()- Get portfolio summarygetPositions()- Get all positionsgetPosition(symbol)- Get position for a symbolgetAccountInfo()- Get account informationgetBalance()- Get account balance
WebSocket (🚧 Planned for Future Versions)
connectWebSocket()- Connect to real-time data streamdisconnectWebSocket()- Disconnect from WebSocketsubscribeToTickers(symbols)- Subscribe to ticker updatessubscribeToQuotes(symbols)- Subscribe to quote updatessubscribeToOrders()- Subscribe to order updatessubscribeToPortfolio()- Subscribe to portfolio updatesunsubscribe(channels, symbols)- Unsubscribe from channels
Error Handling
All API methods return an ApiResponse object with success/error information:
const result = await client.getBrokerTrades({dateFrom: '2021-01-01', dateTo: '2021-21-31'});
if (result.success) {
console.log('Report data:', result.data);
} else {
console.error('Error:', result.error);
}Configuration
TradernetConfig
baseUrl- API base URL (default: 'https://tradernet.com/api')timeout- Request timeout in milliseconds (default: 30000)retries- Number of retry attempts (default: 3)
Events (🚧 Planned for Future Versions)
The client emits the following events:
ticker- Real-time ticker updatesquote- Real-time quote updatesorder- Order status updatesportfolio- Portfolio updatesws_connected- WebSocket connectedws_disconnected- WebSocket disconnectedws_authenticated- WebSocket authenticatederror- Error events
WebSocketConfig (🚧 Planned for Future Versions)
url- WebSocket URL (default: 'wss://ws.tradernet.com')reconnectInterval- Reconnection interval in ms (default: 5000)maxReconnectAttempts- Max reconnection attempts (default: 10)pingInterval- Ping interval in ms (default: 30000)
Development
# Install dependencies
npm install
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Build TypeScript
npm run build
# Build in watch mode
npm run build:watch
Contributing
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
License
This project is licensed under the MIT License.
Support
For support, please open an issue on GitHub or contact the maintainers.
Note: This SDK is designed to work with the Tradernet trading platform. Make sure you have valid API credentials and understand the risks involved in automated trading.
