A robust API for managing automated crypto trading operations with Binance integration.
- User Authentication and Authorization
- Real-time Binance Data Integration
- Historical market data fetching with customizable intervals
- OHLCV (Open, High, Low, Close, Volume) data storage
- Additional market metrics (quote volumes, trade counts)
- Automatic data persistence for analysis
- Paper Trading Support
- Performance Logging
- Trading Crew Management
- Data Sourcing and Analysis
- Python 3.9 or higher
- Poetry for dependency management
- SQLite (default) or PostgreSQL
- Binance API credentials (for live trading)
- Clone the repository:
git clone https://github.com/yourusername/crypto-trading-system.git
cd crypto-trading-system- Install dependencies using Poetry:
poetry install- Set up environment variables:
cp example.env .envEdit .env with your configuration values.
Required environment variables:
# Database
DATABASE_URL=sqlite:///./crypto_trading.db
# Authentication
SECRET_KEY=your-secret-key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Binance API (Required for market data)
BINANCE_API_KEY=your-binance-us-api-key
BINANCE_API_SECRET=your-binance-us-api-secretNote: This system uses the Binance.US API endpoint. Make sure to obtain API credentials from Binance.US if you're in the United States.
- Initialize the database:
poetry run alembic upgrade headThis will create all necessary database tables.
For future database changes:
# After modifying SQLAlchemy models, generate a new migration
poetry run alembic revision --autogenerate -m "Description of changes"
# Apply the migration
poetry run alembic upgrade head- Start the server:
poetry run uvicorn main:app --reload- Access the API documentation at
http://localhost:8000/docs
-
POST /auth/register- Register a new user{ "username": "string", "password": "string" } -
POST /auth/login- Login and get access token{ "username": "string", "password": "string" }
GET /trading/crews- List all trading crewsPOST /trading/crews- Create a new trading crewGET /trading/paper- Get paper trading statusPOST /trading/paper/start- Start paper trading
GET /data/source- Get available data sourcesPOST /data/source- Add a new data sourceGET /logs- Get trading logsPOST /logs- Create a new log entry
The system fetches and stores market data with the following features:
- Customizable time intervals (1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d)
- Historical data retrieval with specified date ranges
- Automatic data persistence for each trading crew
- Comprehensive market metrics including:
- OHLCV (Open, High, Low, Close, Volume)
- Quote asset volume
- Number of trades
- Taker buy volumes (base and quote)
Example API usage:
# Fetch market data for a trading crew
response = client.post("/data-sourcing/fetch", json={
"crew_id": 1,
"start_time": 1625097600000, # Unix timestamp in milliseconds
"end_time": 1625184000000,
"intervals": ["1h", "4h"]
})Run the test suite:
poetry run pytestFor test coverage:
poetry run pytest --cov- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.