-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsimplepanel.html
79 lines (68 loc) · 2.46 KB
/
simplepanel.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
77
78
79
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/json2/20121008/json2.min.js"></script>
<script type="application/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://developer.oanda.com/oandajs/oanda.js"></script>
<script type="text/javascript">
$(function() {
OANDA.auth.token = "<<TOKEN>>";
OANDA.auth.enabled = true;
var accountId = <<accountid>>;
var selectSymbol = $("#selectSymbol");
var oldBid = null;
//reset the display when the symbol is changed
selectSymbol.change(function() {
$("#bid").text("");
$("#ask").text("");
oldBid = null;
});
var sessionToken = null;
//called every second to refresh the display
function getCurrentRates() {
OANDA.rate.quote([$("#selectSymbol").val()], function(rateQuoteResponse) {
var priceInfo = rateQuoteResponse.prices[0];
//change the divs' background colour if the rates have changed. TODO: some jQuery animation would be nice:)
if(oldBid && priceInfo.bid < oldBid) {
$("#quote-panel").css("background-color", "#dd0000");
} else if(oldBid && priceInfo.bid > oldBid) {
$("#quote-panel").css("background-color", "#00dd00");
} else {
$("#quote-panel").css("background-color", "#ffffff");
}
oldBid = priceInfo.bid;
//update the displayed rates
$("#bid").text(priceInfo.bid);
$("#ask").text(priceInfo.ask);
});
}
//get the symbol list
OANDA.rate.instruments(accountId, ['pip', 'precision', 'marginRate'],function(listSymbolsResponse) {
//add the symbols to our drop down
for(var cur in listSymbolsResponse.instruments) {
var symbolName = listSymbolsResponse.instruments[cur].instrument;
selectSymbol.append("<option value='" + symbolName + "'>" + symbolName + "</option>");
}
//select EUR/USD by default
selectSymbol.find("[value=EUR_USD]").attr("selected", "selected");
setInterval(getCurrentRates, 1000);
});
});
</script>
</head>
<body>
<form>
<select id="selectSymbol">
</select>
</form>
<div id='quote-panel'>
<div>
<span>BID: </span>
<span id="bid"></span>
</div>
<div>
<span>ASK: </span>
<span id="ask"></span>
</div>
</div>
</body>
</html>