A comprehensive automated Bitcoin purchasing service that integrates Plaid for bank account management and Cybrid for cryptocurrency trading. This service allows users to set up recurring purchases of Bitcoin using their connected bank accounts.
- Automated BTC Purchases: Set up recurring purchases with configurable frequency
- Plaid Integration: Secure bank account connection and balance monitoring
- Cybrid Trading: Professional-grade cryptocurrency trading execution
- Cron Scheduling: Flexible scheduling using cron expressions
- Real-time Monitoring: Track purchase history and statistics
- RESTful API: Complete API for integration and management
- Balance Validation: Automatic fund availability checking before purchases
- Error Handling: Comprehensive error handling and logging
- Purchase History: Complete audit trail of all transactions
- Configurable Amounts: Adjustable purchase amounts and frequency
- Manual Purchases: One-time purchase execution capability
- Health Monitoring: Service health checks and status endpoints
src/
βββ config.ts # Configuration management
βββ types.ts # TypeScript interfaces
βββ index.ts # Application entry point
βββ app.ts # Express server setup
βββ services/
βββ plaidService.ts # Plaid API integration
βββ cybridService.ts # Cybrid trading API
βββ recurringPurchaseService.ts # Core business logic
- Node.js 18+
- npm or yarn
- Plaid API credentials (sandbox or production)
- Cybrid API credentials (sandbox or production)
-
Clone the repository
git clone <repository-url> cd plaid-cybrid
-
Install dependencies
npm install
-
Set up environment variables Create a
.envfile in the root directory:# Plaid Configuration PLAID_CLIENT_ID=your_plaid_client_id PLAID_SECRET=your_plaid_secret PLAID_ENVIRONMENT=sandbox PLAID_INSTITUTION_ID=ins_109508 # Cybrid Configuration CYBRID_CLIENT_ID=your_cybrid_client_id CYBRID_CLIENT_SECRET=your_cybrid_client_secret CYBRID_BASE_URL=https://bank.sandbox.cybrid.app/api CYBRID_AUTH_URL=https://id.sandbox.cybrid.app/oauth/token # Trading Configuration PURCHASE_AMOUNT=50 PURCHASE_FREQUENCY=0 9 * * * MAX_PURCHASE_AMOUNT=1000 MIN_ACCOUNT_BALANCE=100 # Server Configuration PORT=3000 CORS_ORIGINS=http://localhost:3000,http://localhost:3001 # Logging LOG_LEVEL=info ENABLE_FILE_LOGGING=false
-
Build the project
npm run build
-
Start the service
npm start
# Development mode
npm run dev
# Production mode
npm run build
npm startGET /health# Create sandbox user
POST /api/plaid/create-user
# Get account balance
GET /api/plaid/balance/:accessToken# Authenticate
POST /api/cybrid/authenticate
# Create customer
POST /api/cybrid/customer
Body: { "firstName": "John", "lastName": "Doe" }
# Create bank
POST /api/cybrid/bank
Body: { "customerGuid": "customer_guid" }# Start recurring purchases
POST /api/recurring/start
# Stop recurring purchases
POST /api/recurring/stop
# Get status
GET /api/recurring/status
# Get purchase history
GET /api/recurring/history
# Get statistics
GET /api/recurring/stats
# Update purchase amount
PUT /api/recurring/amount
Body: { "amount": 100 }
# Update frequency
PUT /api/recurring/frequency
Body: { "cronExpression": "0 9 * * *" }# Execute manual purchase
POST /api/purchase/manual
Body: {
"amount": 100,
"customerGuid": "customer_guid",
"bankGuid": "bank_guid"
}- Daily at 9 AM:
0 9 * * * - Every Monday at 10 AM:
0 10 * * 1 - Every hour:
0 * * * * - Every 15 minutes:
*/15 * * * *
PURCHASE_AMOUNT: Default amount for each purchase (USD)PURCHASE_FREQUENCY: Cron expression for purchase frequencyMAX_PURCHASE_AMOUNT: Maximum allowed purchase amountMIN_ACCOUNT_BALANCE: Minimum required account balance
PORT: Server port numberCORS_ORIGINS: Allowed CORS origins (comma-separated)
The service provides comprehensive statistics including:
- Total number of purchases
- Total amount spent
- Total BTC acquired
- Success rate
- Last purchase timestamp
- Service status endpoint
- Error logging
- Performance metrics
- Environment variable configuration
- CORS protection
- Input validation
- Error handling without sensitive data exposure
- Secure API key management
The service is configured for sandbox testing by default:
- Plaid sandbox for bank simulation
- Cybrid sandbox for trading simulation
- Safe testing environment
For production use:
- Update environment variables to production endpoints
- Ensure proper SSL/TLS configuration
- Set up monitoring and alerting
- Configure proper logging levels
The service provides comprehensive logging:
- Request/response logging
- Error tracking
- Purchase execution logs
- Service status updates
- Graceful error handling
- Detailed error messages
- Fallback mechanisms
- Service recovery
-
Authentication Errors
- Verify API credentials
- Check environment variables
- Ensure proper scopes
-
Purchase Failures
- Verify account balance
- Check trading limits
- Review error logs
-
Service Not Starting
- Check port availability
- Verify dependencies
- Review configuration
- Database integration for persistent storage
- Webhook notifications
- Advanced trading strategies
- Multi-currency support
- User authentication and authorization
- Dashboard interface
- Mobile app support
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the ISC License.
This software is for educational and development purposes. Use at your own risk. Always test thoroughly in sandbox environments before using with real funds.
For support and questions:
- Create an issue in the repository
- Review the documentation
- Check the logs for error details
Happy Trading! ππ