# 🔐 Configuration Wallet pour ApolloX V2 On-Chain

## 🎯 Architecture V2

**ApolloX V2 = Futures On-Chain sur BSC**
- Pas d'API keys comme Binance
- Utilise un wallet BSC (MetaMask, etc.)
- Transactions signées on-chain
- Gas fees en BNB

## 📋 Ce Dont Tu as Besoin

### 1. Wallet BSC avec Fonds

**Créer un nouveau wallet (recommandé pour bot):**
```bash
python3 -c "
from eth_account import Account
import secrets

# Générer nouvelle clé privée
private_key = '0x' + secrets.token_hex(32)
account = Account.from_key(private_key)

print('✅ Nouveau wallet généré:')
print(f'   Address: {account.address}')
print(f'   Private Key: {private_key}')
print()
print('⚠️  SAUVEGARDE LA PRIVATE KEY EN LIEU SÛR!')
print('   Si perdue = perte des fonds!')
"
```

**OU utiliser wallet existant:**
- MetaMask: Exporter la private key
- Trust Wallet: Settings → Wallets → Backup

### 2. Déposer les Fonds

**Sur l'adresse du wallet:**

**A) USDT (BEP-20) pour trading**
- Minimum: $100-200 pour tests
- Acheter sur Binance → Withdraw vers wallet
- Network: **BSC (BEP-20)**
- Contrat USDT BSC: `0x55d398326f99059fF775485246999027B3197955`

**B) BNB pour gas fees**
- Minimum: 0.01-0.02 BNB (~$5-10)
- Chaque trade coûte ~0.001-0.002 BNB de gas
- 50-100 trades possibles avec 0.01 BNB

### 3. Vérifier les Fonds

```bash
python3 -c "
from apollox_v2_client import ApolloXV2Client

# Remplacer par ta private key
private_key = '0x...'
client = ApolloXV2Client(private_key=private_key)

print(f'Wallet: {client.account.address}')
print(f'BNB balance: {client.get_balance():.4f} BNB')
print(f'USDT balance: {client.get_usdt_balance():.2f} USDT')
"
```

## 🔒 Sécurité de la Private Key

### Option 1: Fichier .env (Recommandé)

**Créer `.env`:**
```bash
# .env
WALLET_PRIVATE_KEY=0xvotre_cle_privee_ici
```

**Ajouter au .gitignore:**
```bash
echo ".env" >> .gitignore
```

**Charger dans le code:**
```python
from dotenv import load_dotenv
import os

load_dotenv()
private_key = os.getenv('WALLET_PRIVATE_KEY')
client = ApolloXV2Client(private_key=private_key)
```

**Installer dotenv:**
```bash
pip install python-dotenv
```

### Option 2: Variable d'environnement

```bash
export WALLET_PRIVATE_KEY=0xvotre_cle_privee
```

**Dans le code:**
```python
import os
private_key = os.getenv('WALLET_PRIVATE_KEY')
```

### Option 3: Fichier chiffré (Production)

**Chiffrer la clé:**
```python
from cryptography.fernet import Fernet

# Générer clé de chiffrement
key = Fernet.generate_key()
print(f"Clé de chiffrement: {key.decode()}")

# Chiffrer private key
cipher = Fernet(key)
private_key = "0x..."
encrypted = cipher.encrypt(private_key.encode())

with open('.wallet.enc', 'wb') as f:
    f.write(encrypted)
```

**Déchiffrer:**
```python
from cryptography.fernet import Fernet

key = b"votre_cle_de_chiffrement"
cipher = Fernet(key)

with open('.wallet.enc', 'rb') as f:
    encrypted = f.read()

private_key = cipher.decrypt(encrypted).decode()
```

## ⚠️ RÈGLES DE SÉCURITÉ ABSOLUES

1. ❌ **JAMAIS** commit la private key dans git
2. ❌ **JAMAIS** partager la private key
3. ❌ **JAMAIS** laisser la private key en clair dans le code
4. ✅ **TOUJOURS** utiliser .env ou chiffrement
5. ✅ **TOUJOURS** avoir un wallet séparé pour le bot
6. ✅ **TOUJOURS** limiter les fonds sur le wallet du bot

## 🧪 Test de Connection

```bash
python3 -c "
from apollox_v2_client import ApolloXV2Client
from dotenv import load_dotenv
import os

load_dotenv()
private_key = os.getenv('WALLET_PRIVATE_KEY')

if not private_key:
    print('❌ WALLET_PRIVATE_KEY non définie dans .env')
    exit(1)

client = ApolloXV2Client(private_key=private_key)

print('='*60)
print('✅ WALLET CONFIGURÉ')
print('='*60)
print(f'Address: {client.account.address}')
print(f'BNB: {client.get_balance():.4f}')
print(f'USDT: {client.get_usdt_balance():.2f}')
print()

# Vérifier minimums
bnb = client.get_balance()
usdt = client.get_usdt_balance()

if bnb < 0.01:
    print('⚠️  BNB insuffisant pour gas (min 0.01 BNB)')
if usdt < 50:
    print('⚠️  USDT insuffisant pour trading (min $50)')

if bnb >= 0.01 and usdt >= 50:
    print('✅ Prêt pour trading!')
"
```

## 📊 Structure des Fonds Recommandée

**Pour tests micro ($100 total):**
- USDT: $95
- BNB: $5 (0.01 BNB)

**Pour tests standard ($500 total):**
- USDT: $490
- BNB: $10 (0.02 BNB)

**Pour production ($1000+ total):**
- USDT: 98%
- BNB: 2%

## 🔄 Rotation des Wallets

**Bonne pratique:**
1. Wallet #1: Tests initiaux ($100)
2. Wallet #2: Validation stratégie ($500)
3. Wallet #3: Production ($1000+)

→ Si un wallet compromis, les autres sont saufs

## 🆘 En Cas de Problème

**Wallet compromis:**
1. Transférer IMMÉDIATEMENT tous les fonds vers nouveau wallet
2. Révoquer toutes les approvals de tokens
3. Générer nouveau wallet
4. Ne JAMAIS réutiliser le wallet compromis

**Fonds bloqués:**
- Vérifier sur BSCScan: https://bscscan.com/address/VOTRE_ADDRESS
- Vérifier les transactions pendantes
- Augmenter gas price si stuck

---

## ✅ Checklist Avant de Trader

- [ ] Wallet BSC créé/exporté
- [ ] Private key sauvegardée en lieu sûr
- [ ] .env configuré avec WALLET_PRIVATE_KEY
- [ ] .env dans .gitignore
- [ ] USDT déposé (min $50)
- [ ] BNB déposé (min 0.01)
- [ ] Test de connection réussi
- [ ] Balances vérifiées

**Une fois tout OK → Prêt pour le trading V10 on-chain! 🚀**
