-
Notifications
You must be signed in to change notification settings - Fork 4
/
mod.test.ts
40 lines (37 loc) · 991 Bytes
/
mod.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import { Position, PnL, TargetPrice, Liquidation } from "./mod.ts";
Deno.test("PnL", () => {
const pnl = new PnL({
position: Position.Short,
leverage: 1,
entry: "9500",
exit: "9602.58",
quantity: "5.12",
});
assertEquals(pnl.result.initialMargin.valueOf(), 48640);
assertEquals(pnl.result.profit.valueOf(), -525.2096);
assertEquals(pnl.result.returnOnEquity.mul(100).toFixed(4), "-1.0798"); // %
});
Deno.test("TargetPrice", () => {
assertEquals(
new TargetPrice({
position: Position.Short,
leverage: 92,
entry: "9500",
returnOnEquity: "0.25",
}).result.toFixed(2),
"9474.18",
);
});
Deno.test("Liquidation", () => {
assertEquals(
new Liquidation({
position: Position.Long,
entry: "9500",
quantity: "5.12",
wallet: "2000",
minMaintainMargin: "0.005", // 0.5%
}).result.toFixed(2),
"9111.33",
);
});