function cfdPnL(dir, entry, current, amount, lev) {
    var d = dir === "buy" ? current - entry : entry - current;
    return (d / entry) * amount * lev;
}

console.log("CFD Buy: Entry 100, Current 110, Amount 100, Lev 10");
console.log("PnL:", cfdPnL("buy", 100, 110, 100, 10));

console.log("CFD Buy: Entry 100, Current 90, Amount 100, Lev 10");
console.log("PnL:", cfdPnL("buy", 100, 90, 100, 10)); // Should be -100 (100% loss)
