Importer des trades
Endpoint pour importer des trades dans votre compte InsighTrades.
Endpoint
POST /trades/importAuthentification
Requiert un header X-API-Key avec votre clé API valide.
http
X-API-Key: ik_live_votre_clé_api_iciCorps de la requête
json
{
"trades": [
{
"brokerTradeId": "string", // Requis
"symbol": "string", // Requis
"action": "BUY" | "SELL", // Requis
"openPrice": number, // Requis
"closePrice": number, // Requis
"lotSize": number, // Requis
"openTime": "string", // Requis (ISO 8601)
"closeTime": "string", // Requis (ISO 8601)
"profit": number, // Requis
"commission": number, // Optionnel
"swap": number, // Optionnel
"comment": "string" // Optionnel
}
]
}Champs détaillés
| Champ | Type | Requis | Description |
|---|---|---|---|
brokerTradeId | string | ✅ | ID unique du trade chez votre broker |
symbol | string | ✅ | Symbole de l'instrument (ex: EURUSD, XAUUSD) |
action | string | ✅ | Type d'ordre: BUY ou SELL |
openPrice | number | ✅ | Prix d'entrée |
closePrice | number | ✅ | Prix de sortie |
lotSize | number | ✅ | Taille de la position |
openTime | string | ✅ | Date/heure d'ouverture au format ISO 8601 |
closeTime | string | ✅ | Date/heure de fermeture au format ISO 8601 |
profit | number | ✅ | Profit ou perte du trade |
commission | number | ❌ | Frais de commission |
swap | number | ❌ | Frais de swap/overnight |
comment | string | ❌ | Commentaire ou note |
Réponse
Succès (200 OK)
json
{
"imported": 5,
"failed": 0
}Erreur d'authentification (401 Unauthorized)
json
{
"error": "Invalid API key",
"statusCode": 401
}Erreur de validation (400 Bad Request)
json
{
"error": "Validation failed",
"statusCode": 400,
"message": [
"trades.0.symbol should not be empty",
"trades.0.openPrice must be a number"
]
}Exemples
Importer un seul trade
javascript
const response = await fetch('https://api.insightrades.com/trades/import', {
method: 'POST',
headers: {
'X-API-Key': 'ik_live_abc123...',
'Content-Type': 'application/json'
},
body: JSON.stringify({
trades: [{
brokerTradeId: 'MT5-67890',
symbol: 'EURUSD',
action: 'BUY',
openPrice: 1.0950,
closePrice: 1.0975,
lotSize: 0.5,
openTime: '2024-01-20T09:30:00Z',
closeTime: '2024-01-20T14:45:00Z',
profit: 125.0,
commission: 3.5,
swap: -0.8
}]
})
});Importer plusieurs trades
javascript
const trades = [
{
brokerTradeId: 'MT5-67890',
symbol: 'EURUSD',
action: 'BUY',
openPrice: 1.0950,
closePrice: 1.0975,
lotSize: 0.5,
openTime: '2024-01-20T09:30:00Z',
closeTime: '2024-01-20T14:45:00Z',
profit: 125.0
},
{
brokerTradeId: 'MT5-67891',
symbol: 'XAUUSD',
action: 'SELL',
openPrice: 2050.30,
closePrice: 2048.50,
lotSize: 0.1,
openTime: '2024-01-20T10:00:00Z',
closeTime: '2024-01-20T11:30:00Z',
profit: 18.0
}
];
const response = await fetch('https://api.insightrades.com/trades/import', {
method: 'POST',
headers: {
'X-API-Key': 'ik_live_abc123...',
'Content-Type': 'application/json'
},
body: JSON.stringify({ trades })
});Limites
- Taux de requêtes : 100 requêtes par minute
- Nombre de trades : Maximum 100 trades par requête
- Taille de la requête : Maximum 1 MB
Conseil
Pour des imports en masse, divisez vos trades en lots de 100 maximum.
Gestion des doublons
Les trades sont identifiés de manière unique par brokerTradeId. Si vous envoyez un trade avec un brokerTradeId déjà existant, il sera ignoré (pas d'erreur, simplement non importé).
