-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
76 lines (63 loc) · 2.62 KB
/
index.html
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>
<head>
<title>查询Margin</title>
<meta charset='utf-8' />
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>
</head>
</html>
<body style="padding: 10px;">
<h1>查询Margin</h1>
<span style="margin-right: 10px;">请输入地址</span><input value="" id="address" style="width:400px;" />
<button id="query">查询</button>
<h5>查询结果</h5>
<p style="margin-top: 10px;font-size: 20px;" id="result"></p>
</body>
<style>
</style>
<script src="./jquery.min.js"></script>
<script src='./bignumber.js'></script>
<script src='./index.min.js'></script>
<script type='text/javascript'>
console.log(jssdk)
$(function () {
$('#query').unbind('click').click(async () => {
$("#result").html("")
try {
jssdk.initAddressInfo("dev_prod");
const connectInfo = jssdk.getCurrentAddressInfo().readonlyConnectInfo();
const account = $("#address").val().replace(/(^\s*)|(\s*$)/g, "");
const router = connectInfo.create(jssdk.Router);
const [routerResult] = await connectInfo.multiCall().call(
{
position: router.routerInstance.getPosition(connectInfo.addressInfo.WETH, connectInfo.addressInfo.USDC, account),
}
);
const position = routerResult.position;
const side = jssdk.TradeMath.side(position.quoteSize);
let margin;
if (side === jssdk.SideType.LONG) {
margin = new BigNumber(position.baseSize)
.minus(position.tradeSize)
.div(10 ** 18)
.toFixed();
} else {
margin = new BigNumber(position.baseSize)
.plus(position.tradeSize)
.div(10 ** 18)
.toFixed();
}
$("#result").html(`${account} <br/>Margin: <span style="color: red;">${margin}</span> ETH <br/>
<br/>
<br/>
tradeSize:${position.tradeSize} <br/>
baseSize:${position.baseSize} <br/>
quoteSize:${position.quoteSize} <br/>
`)
console.log(account, "\nMargin:", margin + " ETH");
} catch (e) {
$("#result").html("查询出现异常,请检查网络和输入情况")
}
})
});
</script>