UNPKG

ibkr-api-sdk

Version:

A Node.js SDK for Interactive Brokers API

179 lines (152 loc) 5.01 kB
# IBKR API SDK ![NPM Version](https://img.shields.io/npm/v/ibkr-api-sdk) ![License](https://img.shields.io/github/license/your-repo/ibkr-api-sdk) ![Node.js](https://img.shields.io/node/v/ibkr-api-sdk) ## **Introduction** The **IBKR API SDK** provides a simple way to integrate with **Interactive Brokers (IBKR) API** for account management and ACH transfers. This SDK helps developers interact with IBKR's API for: ✅ **Account Creation** ✅ **KYC Submission** ✅ **Account Status Check** ✅ **Add Bank Accounts** ✅ **Delete Bank Accounts** ✅ **ACH Fund Transfers** --- ## **📦 Installation** To install the package via **NPM**, run: ```sh npm install ibkr-api-sdk Or using Yarn: yarn add ibkr-api-sdk 🔧 Configuration Before using the SDK, set up your environment variables in a .env file: IBKR_BASE_URL=https://localhost:5000/v1/api IBKR_API_KEY=your_api_key IBKR_ACCOUNT_ID=your_account_id 🚀 Usage Import the SDK and start making API calls. 1️⃣ Create an IBKR Account const Ibkr = require("ibkr-api-sdk"); async function createAccount() { try { const response = await Ibkr.createAccount({ firstName: "John", lastName: "Doe", email: "john.doe@example.com" }); console.log("Account Created:", response); } catch (error) { console.error("Error:", error.message); } } createAccount(); 2️⃣ Submit KYC async function submitKYC() { try { const response = await Ibkr.submitKYC({ userId: "U1234567", documentType: "passport", documentNumber: "123456789", issueDate: "2023-01-01", expiryDate: "2033-01-01" }); console.log("KYC Submitted:", response); } catch (error) { console.error("Error:", error.message); } } submitKYC(); 3️⃣ Get Account Status async function checkAccountStatus() { try { const response = await Ibkr.getAccountStatus(); console.log("Account Status:", response); } catch (error) { console.error("Error:", error.message); } } checkAccountStatus(); 4️⃣ Add a Bank Account async function addBankAccount() { try { const response = await Ibkr.addBank({ bankName: "Bank of America", accountNumber: "123456789", routingNumber: "987654321", accountType: "checking" }); console.log("Bank Account Added:", response); } catch (error) { console.error("Error:", error.message); } } addBankAccount(); 5️⃣ Delete a Bank Account async function deleteBankAccount() { try { const response = await Ibkr.deleteBank("bank123"); console.log("Bank Account Deleted:", response); } catch (error) { console.error("Error:", error.message); } } deleteBankAccount(); 6️⃣ Perform an ACH Transfer async function performACHTransfer() { try { const response = await Ibkr.achTransfer({ amount: 1000, currency: "USD", recipientAccount: "recipient123" }); console.log("ACH Transfer Successful:", response); } catch (error) { console.error("Error:", error.message); } } performACHTransfer(); 🛠 API Methods Method Description Parameters createAccount(data) Create a new IBKR account { firstName, lastName, email } submitKYC(data) Submit KYC for verification { userId, documentType, documentNumber, issueDate, expiryDate } getAccountStatus() Retrieve IBKR account status N/A addBank(data) Add a bank account { bankName, accountNumber, routingNumber, accountType } deleteBank(bankId) Remove a bank account bankId achTransfer(data) Perform an ACH fund transfer { amount, currency, recipientAccount } 📌 Environment Variables Variable Name Description IBKR_BASE_URL The IBKR API base URL (e.g., https://localhost:5000/v1/api) IBKR_API_KEY Your IBKR API Key IBKR_ACCOUNT_ID Your IBKR Account ID 📖 IBKR API Documentation Refer to the official IBKR API Documentation for more details: 🔗 IBKR API Docs 🔍 Troubleshooting ❓ "Unauthorized" Error Check if IBKR Gateway/TWS is running. Ensure API key is correct and permissions are enabled. ❓ "Invalid Account" Error Verify your IBKR_ACCOUNT_ID is correct. ❓ Connection Refused Restart IBKR Gateway: killall ibgateway ./ibgateway 📄 License This project is licensed under the MIT License. 👨‍💻 Contributors Your Name - Developer Contributors Welcome! If you'd like to improve this package, feel free to submit a PR! ⭐ Support & Contributions 💡 Found a bug? Have a feature request? Submit an issue or PR on GitHub. ✅ If you find this package useful, please star this repository! 🌟 --- ## **📌 How to Use It?** 1. Copy this **`README.md`** and place it inside your **NPM package root folder**. 2. After publishing, it will appear as the **package documentation** on **npmjs.com**. --- ## **🚀 Next Steps** - ✅ **README.md completed** - ✅ **NPM package structure & implementation done** - 🔒 **OAuth Authentication (Optional, for better security)** - ✅ **Testing with Jest** (if needed) Would you like **unit tests** or **OAuth authentication** next? 🚀