Complete mapping of Risk Metrics Spec to MetaAPI endpoints and fields
readDealsByTimeRange()
// Get current balance const accountInfo = await connection.readAccountInformation(); const currentBalance = accountInfo.balance;
// Get current equity (NAV) const equity = accountInfo.equity;
contractValuePerPoint = tickValue / tickSizereadSymbolSpecification(symbol).tickValue and .tickSize
// Calculate contract value per point const spec = await connection.readSymbolSpecification(symbol); const contractValuePerPoint = spec.tickValue / spec.tickSize; // Calculate risk per position const priceDistance = Math.abs(position.openPrice - (position.stopLoss || 0)); const riskPerPosition = priceDistance * contractValuePerPoint * position.volume;
const accountInfo = await connection.readAccountInformation(); const balance = accountInfo.balance;
const accountInfo = await connection.readAccountInformation(); const equity = accountInfo.equity; // Floating P/L can be calculated: const floatingPL = accountInfo.equity - accountInfo.balance;
closeTime to get month-to-date deals only.
// Get deals from start of month
const now = new Date();
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1, 0, 0, 0, 0);
const deals = await connection.readDealsByTimeRange(
startOfMonth.toISOString(),
now.toISOString()
);
// Calculate realized loss MTD
const realizedLossMtd = deals
.filter(deal => deal.pl < 0)
.reduce((sum, deal) => sum + Math.abs(deal.pl), 0);
const positions = await connection.readPositions(); const activeOrders = positions.length;
// Get all deals, sorted by close time (most recent first)
const deals = await connection.readDealsByTimeRange(
startDate.toISOString(),
endDate.toISOString()
);
// Calculate consecutive losing trades
let consecutiveLosingTrades = 0;
for (let i = deals.length - 1; i >= 0; i--) {
const deal = deals[i];
// Ignore tiny volume
if (deal.volume <= 0.01) continue;
if (deal.pl < 0) {
consecutiveLosingTrades++;
} else if (deal.pl > 0) {
// Winning trade resets counter
break;
}
}
| Metric | Status | MetaAPI Endpoint | Notes |
|---|---|---|---|
| startOfMonthBalance | MISSING | - | Store at month start or reconstruct from deals |
| peakBalance / peakNav | MISSING | - | Track and update when new peak reached |
| startingCapital | MISSING | - | Store when first deployed |
| balance | AVAILABLE | readAccountInformation() | accountInformation.balance |
| equity | AVAILABLE | readAccountInformation() | accountInformation.equity |
| floatingPL | AVAILABLE | readAccountInformation() | equity - balance |
| positions (openPrice, stopLoss, volume) | AVAILABLE | readPositions() | positions[].openPrice, .stopLoss, .volume |
| deals (pl, closeTime, volume) | AVAILABLE | readDealsByTimeRange() | deals[].pl, .closeTime, .volume |
| symbolSpec (tickValue, tickSize) | AVAILABLE | readSymbolSpecification(symbol) | spec.tickValue, spec.tickSize |
| MDL_RATE, MML_RATE, DD_RATE | MISSING | - | Configuration values - store in DB/config |