Move blockchain app READMEs to centralized documentation
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 10s
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
CLI Tests / test-cli (push) Failing after 4s
Documentation Validation / validate-docs (push) Successful in 8s
Documentation Validation / validate-policies-strict (push) Successful in 4s
Integration Tests / test-service-integration (push) Successful in 38s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 3s
Security Scanning / security-scan (push) Successful in 40s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 15s
Smart Contract Tests / lint-solidity (push) Successful in 8s
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 10s
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
CLI Tests / test-cli (push) Failing after 4s
Documentation Validation / validate-docs (push) Successful in 8s
Documentation Validation / validate-policies-strict (push) Successful in 4s
Integration Tests / test-service-integration (push) Successful in 38s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 3s
Security Scanning / security-scan (push) Successful in 40s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 15s
Smart Contract Tests / lint-solidity (push) Successful in 8s
- Relocate blockchain-event-bridge README content to docs/apps/blockchain/blockchain-event-bridge.md - Relocate blockchain-explorer README content to docs/apps/blockchain/blockchain-explorer.md - Replace app READMEs with redirect notices pointing to new documentation location - Consolidate documentation in central docs/ directory for better organization
This commit is contained in:
17
docs/apps/exchange/README.md
Normal file
17
docs/apps/exchange/README.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Exchange Applications
|
||||
|
||||
Exchange services and trading infrastructure.
|
||||
|
||||
## Applications
|
||||
|
||||
- [Exchange](exchange.md) - Cross-chain exchange and trading platform
|
||||
- [Exchange Integration](exchange-integration.md) - Exchange integration services
|
||||
- [Trading Engine](trading-engine.md) - Trading engine for order matching
|
||||
|
||||
## Features
|
||||
|
||||
- Cross-chain exchange
|
||||
- Order matching and execution
|
||||
- Price tickers
|
||||
- Health monitoring
|
||||
- Multi-chain support
|
||||
174
docs/apps/exchange/exchange-integration.md
Normal file
174
docs/apps/exchange/exchange-integration.md
Normal file
@@ -0,0 +1,174 @@
|
||||
# Exchange Integration
|
||||
|
||||
## Status
|
||||
✅ Operational
|
||||
|
||||
## Overview
|
||||
Integration service for connecting the exchange with external systems, blockchains, and data providers.
|
||||
|
||||
## Architecture
|
||||
|
||||
### Core Components
|
||||
- **Blockchain Connector**: Connects to blockchain RPC endpoints
|
||||
- **Data Feed Manager**: Manages external data feeds
|
||||
- **Webhook Handler**: Processes webhook notifications
|
||||
- **API Client**: Client for external exchange APIs
|
||||
- **Event Processor**: Processes integration events
|
||||
|
||||
## Quick Start (End Users)
|
||||
|
||||
### Prerequisites
|
||||
- Python 3.13+
|
||||
- Access to blockchain RPC endpoints
|
||||
- API keys for external exchanges
|
||||
|
||||
### Installation
|
||||
```bash
|
||||
cd /opt/aitbc/apps/exchange-integration
|
||||
.venv/bin/pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Configuration
|
||||
Set environment variables in `.env`:
|
||||
```bash
|
||||
BLOCKCHAIN_RPC_URL=http://localhost:8006
|
||||
EXTERNAL_EXCHANGE_API_KEY=your-api-key
|
||||
WEBHOOK_SECRET=your-webhook-secret
|
||||
```
|
||||
|
||||
### Running the Service
|
||||
```bash
|
||||
.venv/bin/python main.py
|
||||
```
|
||||
|
||||
## Developer Guide
|
||||
|
||||
### Development Setup
|
||||
1. Clone the repository
|
||||
2. Create virtual environment: `python -m venv .venv`
|
||||
3. Install dependencies: `pip install -r requirements.txt`
|
||||
4. Configure environment variables
|
||||
5. Run tests: `pytest tests/`
|
||||
|
||||
### Project Structure
|
||||
```
|
||||
exchange-integration/
|
||||
├── src/
|
||||
│ ├── blockchain_connector/ # Blockchain integration
|
||||
│ ├── data_feed_manager/ # Data feed management
|
||||
│ ├── webhook_handler/ # Webhook processing
|
||||
│ ├── api_client/ # External API client
|
||||
│ └── event_processor/ # Event processing
|
||||
├── tests/ # Test suite
|
||||
└── pyproject.toml # Project configuration
|
||||
```
|
||||
|
||||
### Testing
|
||||
```bash
|
||||
# Run all tests
|
||||
pytest tests/
|
||||
|
||||
# Run blockchain integration tests
|
||||
pytest tests/test_blockchain.py
|
||||
|
||||
# Run webhook tests
|
||||
pytest tests/test_webhook.py
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### Blockchain Integration
|
||||
|
||||
#### Get Blockchain Status
|
||||
```http
|
||||
GET /api/v1/integration/blockchain/status
|
||||
```
|
||||
|
||||
#### Sync Blockchain Data
|
||||
```http
|
||||
POST /api/v1/integration/blockchain/sync
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"chain_id": "ait-mainnet",
|
||||
"from_height": 1000,
|
||||
"to_height": 2000
|
||||
}
|
||||
```
|
||||
|
||||
### Data Feeds
|
||||
|
||||
#### Subscribe to Data Feed
|
||||
```http
|
||||
POST /api/v1/integration/feeds/subscribe
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"feed_type": "price|volume|orders",
|
||||
"symbols": ["BTC_AIT", "ETH_AIT"]
|
||||
}
|
||||
```
|
||||
|
||||
#### Get Feed Data
|
||||
```http
|
||||
GET /api/v1/integration/feeds/{feed_id}/data
|
||||
```
|
||||
|
||||
### Webhooks
|
||||
|
||||
#### Register Webhook
|
||||
```http
|
||||
POST /api/v1/integration/webhooks
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"url": "https://example.com/webhook",
|
||||
"events": ["order_filled", "price_update"],
|
||||
"secret": "your-secret"
|
||||
}
|
||||
```
|
||||
|
||||
#### Process Webhook
|
||||
```http
|
||||
POST /api/v1/integration/webhooks/process
|
||||
Content-Type: application/json
|
||||
X-Webhook-Secret: your-secret
|
||||
|
||||
{
|
||||
"event": "order_filled",
|
||||
"data": {}
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
- `BLOCKCHAIN_RPC_URL`: Blockchain RPC endpoint
|
||||
- `EXTERNAL_EXCHANGE_API_KEY`: API key for external exchanges
|
||||
- `WEBHOOK_SECRET`: Secret for webhook validation
|
||||
- `SYNC_INTERVAL`: Interval for blockchain sync (default: 60s)
|
||||
- `MAX_RETRIES`: Maximum retry attempts for failed requests
|
||||
- `TIMEOUT`: Request timeout in seconds
|
||||
|
||||
### Integration Settings
|
||||
- **Supported Chains**: List of supported blockchain networks
|
||||
- **Data Feed Providers**: External data feed providers
|
||||
- **Webhook Endpoints**: Configurable webhook endpoints
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Blockchain sync failed**: Check RPC endpoint connectivity and authentication.
|
||||
|
||||
**Data feed not updating**: Verify API key and data feed configuration.
|
||||
|
||||
**Webhook not triggered**: Check webhook URL and secret configuration.
|
||||
|
||||
**API rate limiting**: Implement retry logic with exponential backoff.
|
||||
|
||||
## Security Notes
|
||||
|
||||
- Validate webhook signatures
|
||||
- Use HTTPS for all external connections
|
||||
- Rotate API keys regularly
|
||||
- Implement rate limiting for external API calls
|
||||
- Monitor for suspicious activity
|
||||
221
docs/apps/exchange/exchange.md
Normal file
221
docs/apps/exchange/exchange.md
Normal file
@@ -0,0 +1,221 @@
|
||||
# Exchange
|
||||
|
||||
## Status
|
||||
✅ Operational
|
||||
|
||||
## Overview
|
||||
Cross-chain exchange and trading platform supporting multiple blockchain networks with real-time price tracking and order matching.
|
||||
|
||||
## Architecture
|
||||
|
||||
### Core Components
|
||||
- **Order Book**: Central order book for all trading pairs
|
||||
- **Matching Engine**: Real-time order matching and execution
|
||||
- **Price Ticker**: Real-time price updates and market data
|
||||
- **Cross-Chain Bridge**: Bridge for cross-chain asset transfers
|
||||
- **Health Monitor**: System health monitoring and alerting
|
||||
- **API Server**: RESTful API for exchange operations
|
||||
|
||||
### Supported Features
|
||||
- Multiple trading pairs
|
||||
- Cross-chain asset transfers
|
||||
- Real-time price updates
|
||||
- Order management (limit, market, stop orders)
|
||||
- Health monitoring
|
||||
- Multi-chain support
|
||||
|
||||
## Quick Start (End Users)
|
||||
|
||||
### Prerequisites
|
||||
- Python 3.13+
|
||||
- PostgreSQL database
|
||||
- Redis for caching
|
||||
- Access to blockchain RPC endpoints
|
||||
|
||||
### Installation
|
||||
```bash
|
||||
cd /opt/aitbc/apps/exchange
|
||||
.venv/bin/pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Configuration
|
||||
Set environment variables in `.env`:
|
||||
```bash
|
||||
DATABASE_URL=postgresql://user:pass@localhost/exchange
|
||||
REDIS_URL=redis://localhost:6379
|
||||
BLOCKCHAIN_RPC_URL=http://localhost:8006
|
||||
CROSS_CHAIN_ENABLED=true
|
||||
```
|
||||
|
||||
### Running the Service
|
||||
```bash
|
||||
# Start the exchange server
|
||||
python server.py
|
||||
|
||||
# Or use the production launcher
|
||||
bash deploy_real_exchange.sh
|
||||
```
|
||||
|
||||
### Web Interface
|
||||
Open `index.html` in a browser to access the web interface.
|
||||
|
||||
## Developer Guide
|
||||
|
||||
### Development Setup
|
||||
1. Clone the repository
|
||||
2. Create virtual environment: `python -m venv .venv`
|
||||
3. Install dependencies: `pip install -r requirements.txt`
|
||||
4. Set up database: See database.py
|
||||
5. Configure environment variables
|
||||
6. Run tests: `pytest tests/`
|
||||
|
||||
### Project Structure
|
||||
```
|
||||
exchange/
|
||||
├── server.py # Main server
|
||||
├── exchange_api.py # Exchange API endpoints
|
||||
├── multichain_exchange_api.py # Multi-chain API
|
||||
├── simple_exchange_api.py # Simple exchange API
|
||||
├── cross_chain_exchange.py # Cross-chain exchange logic
|
||||
├── real_exchange_integration.py # Real exchange integration
|
||||
├── models.py # Database models
|
||||
├── database.py # Database connection
|
||||
├── health_monitor.py # Health monitoring
|
||||
├── index.html # Web interface
|
||||
├── styles.css # Web styles
|
||||
├── update_price_ticker.js # Price ticker update script
|
||||
└── scripts/ # Utility scripts
|
||||
```
|
||||
|
||||
### Testing
|
||||
```bash
|
||||
# Run all tests
|
||||
pytest tests/
|
||||
|
||||
# Run API tests
|
||||
pytest tests/test_api.py
|
||||
|
||||
# Run cross-chain tests
|
||||
pytest tests/test_cross_chain.py
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### Market Data
|
||||
|
||||
#### Get Order Book
|
||||
```http
|
||||
GET /api/v1/orderbook?pair=BTC_AIT
|
||||
```
|
||||
|
||||
#### Get Price Ticker
|
||||
```http
|
||||
GET /api/v1/ticker?pair=BTC_AIT
|
||||
```
|
||||
|
||||
#### Get Market Summary
|
||||
```http
|
||||
GET /api/v1/market/summary
|
||||
```
|
||||
|
||||
### Orders
|
||||
|
||||
#### Place Order
|
||||
```http
|
||||
POST /api/v1/orders
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"pair": "BTC_AIT",
|
||||
"side": "buy|sell",
|
||||
"type": "limit|market|stop",
|
||||
"amount": 100,
|
||||
"price": 1.0,
|
||||
"user_id": "string"
|
||||
}
|
||||
```
|
||||
|
||||
#### Get Order Status
|
||||
```http
|
||||
GET /api/v1/orders/{order_id}
|
||||
```
|
||||
|
||||
#### Cancel Order
|
||||
```http
|
||||
DELETE /api/v1/orders/{order_id}
|
||||
```
|
||||
|
||||
#### Get User Orders
|
||||
```http
|
||||
GET /api/v1/orders?user_id=string&status=open
|
||||
```
|
||||
|
||||
### Cross-Chain
|
||||
|
||||
#### Initiate Cross-Chain Transfer
|
||||
```http
|
||||
POST /api/v1/crosschain/transfer
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"from_chain": "ait-mainnet",
|
||||
"to_chain": "btc-mainnet",
|
||||
"asset": "BTC",
|
||||
"amount": 100,
|
||||
"recipient": "address"
|
||||
}
|
||||
```
|
||||
|
||||
#### Get Transfer Status
|
||||
```http
|
||||
GET /api/v1/crosschain/transfers/{transfer_id}
|
||||
```
|
||||
|
||||
### Health
|
||||
|
||||
#### Get Health Status
|
||||
```http
|
||||
GET /health
|
||||
```
|
||||
|
||||
#### Get System Metrics
|
||||
```http
|
||||
GET /metrics
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
- `DATABASE_URL`: PostgreSQL connection string
|
||||
- `REDIS_URL`: Redis connection string
|
||||
- `BLOCKCHAIN_RPC_URL`: Blockchain RPC endpoint
|
||||
- `CROSS_CHAIN_ENABLED`: Enable cross-chain transfers
|
||||
- `MAX_ORDER_SIZE`: Maximum order size
|
||||
- `MIN_ORDER_SIZE`: Minimum order size
|
||||
- `TRADING_FEE_PERCENTAGE`: Trading fee percentage
|
||||
- `ORDER_TIMEOUT`: Order timeout in seconds
|
||||
|
||||
### Trading Parameters
|
||||
- **Order Types**: limit, market, stop orders
|
||||
- **Order Sides**: buy, sell
|
||||
- **Trading Pairs**: Configurable trading pairs
|
||||
- **Fee Structure**: Percentage-based trading fees
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Order not matched**: Check order book depth and price settings.
|
||||
|
||||
**Cross-chain transfer failed**: Verify blockchain connectivity and bridge status.
|
||||
|
||||
**Price ticker not updating**: Check WebSocket connection and data feed.
|
||||
|
||||
**Database connection errors**: Verify DATABASE_URL and database server status.
|
||||
|
||||
## Security Notes
|
||||
|
||||
- Use API keys for authentication
|
||||
- Implement rate limiting for API endpoints
|
||||
- Validate all order parameters
|
||||
- Encrypt sensitive data at rest
|
||||
- Monitor for suspicious trading patterns
|
||||
- Regularly audit order history
|
||||
199
docs/apps/exchange/trading-engine.md
Normal file
199
docs/apps/exchange/trading-engine.md
Normal file
@@ -0,0 +1,199 @@
|
||||
# Trading Engine
|
||||
|
||||
## Status
|
||||
✅ Operational
|
||||
|
||||
## Overview
|
||||
High-performance trading engine for order matching, execution, and trade settlement with support for multiple order types and trading strategies.
|
||||
|
||||
## Architecture
|
||||
|
||||
### Core Components
|
||||
- **Order Matching Engine**: Real-time order matching algorithm
|
||||
- **Trade Executor**: Executes matched trades
|
||||
- **Risk Manager**: Risk assessment and position management
|
||||
- **Settlement Engine**: Trade settlement and clearing
|
||||
- **Order Book Manager**: Manages order book state
|
||||
- **Price Engine**: Calculates fair market prices
|
||||
|
||||
## Quick Start (End Users)
|
||||
|
||||
### Prerequisites
|
||||
- Python 3.13+
|
||||
- PostgreSQL database
|
||||
- Redis for caching
|
||||
- Access to exchange APIs
|
||||
|
||||
### Installation
|
||||
```bash
|
||||
cd /opt/aitbc/apps/trading-engine
|
||||
.venv/bin/pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Configuration
|
||||
Set environment variables in `.env`:
|
||||
```bash
|
||||
DATABASE_URL=postgresql://user:pass@localhost/trading
|
||||
REDIS_URL=redis://localhost:6379
|
||||
EXCHANGE_API_KEY=your-api-key
|
||||
RISK_LIMITS_ENABLED=true
|
||||
```
|
||||
|
||||
### Running the Service
|
||||
```bash
|
||||
.venv/bin/python main.py
|
||||
```
|
||||
|
||||
## Developer Guide
|
||||
|
||||
### Development Setup
|
||||
1. Clone the repository
|
||||
2. Create virtual environment: `python -m venv .venv`
|
||||
3. Install dependencies: `pip install -r requirements.txt`
|
||||
4. Set up database
|
||||
5. Configure environment variables
|
||||
6. Run tests: `pytest tests/`
|
||||
|
||||
### Project Structure
|
||||
```
|
||||
trading-engine/
|
||||
├── src/
|
||||
│ ├── matching_engine/ # Order matching logic
|
||||
│ ├── trade_executor/ # Trade execution
|
||||
│ ├── risk_manager/ # Risk management
|
||||
│ ├── settlement_engine/ # Trade settlement
|
||||
│ ├── order_book/ # Order book management
|
||||
│ └── price_engine/ # Price calculation
|
||||
├── tests/ # Test suite
|
||||
└── pyproject.toml # Project configuration
|
||||
```
|
||||
|
||||
### Testing
|
||||
```bash
|
||||
# Run all tests
|
||||
pytest tests/
|
||||
|
||||
# Run matching engine tests
|
||||
pytest tests/test_matching.py
|
||||
|
||||
# Run risk manager tests
|
||||
pytest tests/test_risk.py
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### Order Management
|
||||
|
||||
#### Submit Order
|
||||
```http
|
||||
POST /api/v1/trading/orders
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"user_id": "string",
|
||||
"symbol": "BTC_AIT",
|
||||
"side": "buy|sell",
|
||||
"type": "limit|market|stop",
|
||||
"quantity": 100,
|
||||
"price": 1.0,
|
||||
"stop_price": 1.1
|
||||
}
|
||||
```
|
||||
|
||||
#### Cancel Order
|
||||
```http
|
||||
DELETE /api/v1/trading/orders/{order_id}
|
||||
```
|
||||
|
||||
#### Get Order Status
|
||||
```http
|
||||
GET /api/v1/trading/orders/{order_id}
|
||||
```
|
||||
|
||||
### Trade Execution
|
||||
|
||||
#### Get Trade History
|
||||
```http
|
||||
GET /api/v1/trading/trades?symbol=BTC_AIT&limit=100
|
||||
```
|
||||
|
||||
#### Get User Trades
|
||||
```http
|
||||
GET /api/v1/trading/users/{user_id}/trades
|
||||
```
|
||||
|
||||
### Risk Management
|
||||
|
||||
#### Check Risk Limits
|
||||
```http
|
||||
POST /api/v1/trading/risk/check
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"user_id": "string",
|
||||
"order": {}
|
||||
}
|
||||
```
|
||||
|
||||
#### Get User Risk Profile
|
||||
```http
|
||||
GET /api/v1/trading/users/{user_id}/risk-profile
|
||||
```
|
||||
|
||||
### Settlement
|
||||
|
||||
#### Get Settlement Status
|
||||
```http
|
||||
GET /api/v1/trading/settlement/{trade_id}
|
||||
```
|
||||
|
||||
#### Trigger Settlement
|
||||
```http
|
||||
POST /api/v1/trading/settlement/trigger
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"trade_ids": ["trade1", "trade2"]
|
||||
}
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Environment Variables
|
||||
- `DATABASE_URL`: PostgreSQL connection string
|
||||
- `REDIS_URL`: Redis connection string
|
||||
- `EXCHANGE_API_KEY`: Exchange API key
|
||||
- `RISK_LIMITS_ENABLED`: Enable risk management
|
||||
- `MAX_POSITION_SIZE`: Maximum position size
|
||||
- `MARGIN_REQUIREMENT`: Margin requirement percentage
|
||||
- `LIQUIDATION_THRESHOLD`: Liquidation threshold
|
||||
|
||||
### Order Types
|
||||
- **Limit Order**: Execute at specified price or better
|
||||
- **Market Order**: Execute immediately at market price
|
||||
- **Stop Order**: Trigger when price reaches stop price
|
||||
- **Stop-Limit**: Limit order triggered by stop price
|
||||
|
||||
### Risk Parameters
|
||||
- **Position Limits**: Maximum position sizes
|
||||
- **Margin Requirements**: Required margin for leverage
|
||||
- **Liquidation Threshold**: Price at which positions are liquidated
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Order not matched**: Check order book depth and price settings.
|
||||
|
||||
**Trade execution failed**: Verify exchange connectivity and balance.
|
||||
|
||||
**Risk check failed**: Review user risk profile and position limits.
|
||||
|
||||
**Settlement delayed**: Check blockchain network status and gas fees.
|
||||
|
||||
## Security Notes
|
||||
|
||||
- Implement order validation
|
||||
- Use rate limiting for order submission
|
||||
- Monitor for wash trading
|
||||
- Validate user authentication
|
||||
- Implement position limits
|
||||
- Regularly audit trade history
|
||||
Reference in New Issue
Block a user