A modular Go-based trading platform API with JWT authentication and KYC-first wallet-based authentication, designed for frontend integration.
- 🔐 JWT-based authentication (wallet-based sign-in; KYC required for live trading)
- 👤 User management with profiles
- 💰 Trading accounts and transactions
- 📊 Profit statistics and analytics
- ⚙️ User settings and preferences
- 🔄 Leverage management
- 📈 Trading pairs management
- 🛡️ CORS support for frontend integration
- 🚦 Rate limiting
- 📝 Comprehensive API documentation
Trader/
├── api/ # API routes and middleware
│ ├── middleware.go # CORS, rate limiting, error handling
│ ├── routes.go # All API endpoints
│ └── go.mod
├── database/ # Database connection and utilities
│ ├── database.go # DB connection, validation helpers
│ └── go.mod
├── models/ # Data models
│ ├── user.go # User and authentication models
│ ├── trading.go # Trading-related models
│ └── go.mod
├── users/ # User authentication and management
│ ├── auth.go # JWT & wallet authentication logic
│ ├── handlers.go # User-related HTTP handlers
│ └── go.mod
├── main.go # Application entry point
├── config.go # Configuration management
├── go.mod # Main module dependencies
├── go.work # Go workspace configuration
└── API_DOCUMENTATION.md # Complete API documentation
- Go 1.21 or higher
- MySQL 5.7 or higher
- Git
-
Clone the repository:
git clone <repository-url> cd Trader
-
Install dependencies:
go mod download
-
Set up MySQL database:
- Create a MySQL database named
task
- Update database credentials in
.env
file (see Configuration section)
- Create a MySQL database named
-
Environment Configuration: Create a
.env
file in the root directory:# Database Configuration DB_HOST=localhost DB_PORT=3306 DB_USER=colls DB_PASSWORD=1234 DB_NAME=task # JWT Configuration JWT_SECRET=your-super-secret-jwt-key-change-this-in-production # Server Configuration PORT=8080 GIN_MODE=debug # CORS Origins (comma-separated) CORS_ORIGINS=http://localhost:3000,http://localhost:3001
-
Build the application:
go build -o trader .
-
Run the application:
./trader
Or run directly with Go:
go run .
-
The API will be available at:
http://localhost:8080
POST /api/v1/auth/wallet/challenge
- Request wallet sign-in challengePOST /api/v1/auth/wallet/verify
- Verify signature and get tokensPOST /api/v1/auth/token/refresh
- Refresh access tokenPOST /api/v1/auth/logout
- Logout sessionPOST /api/v1/kyc/submit
- Submit KYC documents (multipart) [pending]GET /api/v1/kyc/status
- Get current KYC status [pending]GET /api/v1/kyc/history
- Get KYC submission history [pending]
GET /api/v1/user/profile
- Get user profilePUT /api/v1/user/profile
- Update user profileGET /api/v1/user/platform-activities
- Get platform activities
GET /api/v1/trading/accounts
- Get user accountsGET /api/v1/trading/orders
- Get user ordersPOST /api/v1/trading/orders
- Create new orderGET /api/v1/trading/profit-statistics
- Get profit statistics
GET /api/v1/market/trading-pairs
- Get available trading pairsGET /api/v1/market/price-data/{pair_id}
- Get price data [pending]GET /api/v1/market/overview
- Get market overview [pending]
GET /api/v1/wallet/balances
- Get wallet balancesGET /api/v1/wallet/get-wallets
- Get wallet addressesPOST /api/v1/wallet/deposit
- Deposit to wallet
GET /api/v1/settings/
- Get user settingsPUT /api/v1/settings/
- Update user settings
GET /api/v1/leverage/
- Get current leveragePUT /api/v1/leverage/
- Update leverage
GET /health
- API health status
The API uses JWT tokens for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
The API is designed for easy frontend integration:
- CORS enabled for common development ports
- RESTful endpoints with consistent JSON responses
- JWT authentication for secure user sessions
- Comprehensive error handling with meaningful error messages
- Rate limiting to prevent abuse
The application automatically creates the following tables:
users
- User accounts and profilestransactions
- Trading transactionsaccounts
- User trading accountstrading_pairs
- Available trading pairsprofit_statistics
- Trading performance metricsplatform_activities
- User activity logssettings
- User preferences and settings
- Define models in the
models/
package - Create handlers in the appropriate module (e.g.,
users/
,api/
) - Add routes in
api/routes.go
- Update API documentation
# Run tests
go test ./...
# Run with coverage
go test -cover ./...
- Follow Go conventions and best practices
- Use meaningful variable and function names
- Add comments for public functions
- Handle errors appropriately
-
Set production environment variables:
- Use strong JWT secret
- Configure production database
- Set appropriate CORS origins
- Enable production Gin mode
-
Security considerations:
- Use HTTPS in production
- Implement proper logging
- Set up monitoring
- Regular security updates
Complete API documentation is available in API_DOCUMENTATION.md
with:
- Detailed endpoint descriptions
- Request/response examples
- Error handling information
- Authentication requirements
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
[Add your license information here]