forked from NightTrader/nighttrader.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OTC.htm
206 lines (203 loc) · 8.78 KB
/
OTC.htm
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<meta charset="UTF-8" />
<html>
<body>
NightTrader OTC Sell calculator
<select id="coin">
<option>Sell Bitcoin</option>
<option>Sell Ethereum</option>
</select>
<br>
<div id="selldiv"></div>
<div id="sellQR"></div>
<div id="timerdiv"></div>
<tr>
<td colspan="2"><input class="textBox" id="sellamount" type="text" maxlength="30" required/></td>
</tr>
<select id="conversion">
<option>USD</option>
<option>Pesos</option>
<option>Coins</option>
</select>
<input type="button" value="Sell $" onclick="calculatePrice()">
<input type="button" value="Email" onclick="email()">
<input type="button" value="Clear" onclick="clearit()">
<tr>
<br>Dollar to peso exchange rate(buying dollars):<br>
<td colspan="2"><input class="textBox" id="exchangerate" type="text" maxlength="50" required/></td>
</tr>
<tr>
<br>Email Receipt(optional):<br>
<td colspan="2"><input class="textBox" id="emailreceipt" type="text" maxlength="50" required/></td>
</tr>
<tr>
<br>Casa de cambio Email:<br>
<td colspan="2"><input class="textBox" id="emailcasa" type="text" maxlength="50" style="width: 300px;" required/></td>
</tr>
</body>
<div id="hiddendiv">
<tr>
<br>Custom bid price(to confirm calculation):<br>
<td colspan="2"><input class="textBox" id="custombid" type="text" maxlength="50" required/></td>
</tr>
</div>
<script>
function hide (elements) {
document.getElementById('custombid').value="";
elements = elements.length ? elements : [elements];
for (var index = 0; index < elements.length; index++) {
elements[index].style.display = 'none';
}
}
function show (elements, specifiedDisplay) {
elements = elements.length ? elements : [elements];
for (var index = 0; index < elements.length; index++) {
elements[index].style.display = specifiedDisplay || 'block';
}
}
hide(document.getElementById('hiddendiv'));
</script>
<div id="notificationdiv"></div>
<script src="./rates.js"></script>
<script src="./users.js"></script>
<script src="./web3.min.js"></script>
<script>
web3 = new Web3("https://cloudflare-eth.com");
var quoted = 0;
var globcontent = "";
function calculatePrice(){
console.log(web3.utils.sha3(document.getElementById('emailcasa').value.toLowerCase()));
if(web3.utils.sha3(document.getElementById('emailcasa').value.toLowerCase()) in registeredemails) {
} else {
document.getElementById('notificationdiv').innerHTML="Not a registered cashier, please check email address";
return;
}
amount=document.getElementById('sellamount').value;
if (amount == "show") {
show(document.getElementById('hiddendiv'));
return;
}
var coin = document.getElementById("coin");
var coin1 = "";
var coin2 = "";
if (coin.value == "Sell Bitcoin") {
coin = "BTC";
coin1 = "bitcoin";
coin2 = "Bitcoin";
address = "1DRv5FouLzQvgPDhgi3g9jyZEqT2vVzkxq";
}
if (coin.value == "Sell Ethereum") {
coin = "ETH";
coin1 = "ethereum";
coin2 = "Ethereum";
address = "0xbB56fD1575C275e1dC94E576A7d18347367a8d36";
}
var burl = "https://api.binance.com";
var query = '/api/v1/ticker/24hr';
query += '?symbol='+coin+'DAI';
var url = burl + query;
var ourRequest = new XMLHttpRequest();
ourRequest.open('GET',url,true);
ourRequest.onload = function(){
binancedata = JSON.parse(ourRequest.responseText);
binancedata = binancedata.bidPrice;
customrate = document.getElementById('custombid').value;
if (customrate != "") {
binancedata = customrate;
}
var conversion = document.getElementById("conversion").value;
if (conversion == "Pesos") {
rate=document.getElementById('exchangerate').value;
amount=parseFloat(parseFloat(amount)/parseFloat(rate)).toFixed(0);
}
if (conversion == "Coins") {
btctotal=amount;
amount=parseFloat(parseFloat(binancedata)*parseFloat(amount)).toFixed(0);
} else {
btctotal = parseFloat(parseFloat(amount) / parseFloat(binancedata)).toFixed(8);
}
amount=parseFloat(amount);
if (coin == "BTC") {
if (amount < parseFloat(rates.minBTCsell)) {
clearfields();
document.getElementById('notificationdiv').innerHTML="Amount under minimum: " + rates.minBTCsell;
return;
}
}
if (coin == "ETH") {
if (amount < parseFloat(rates.minERCsell)) {
clearfields();
document.getElementById('notificationdiv').innerHTML="Amount under minimum: " + rates.minERCsell;
return;
}
}
document.getElementById('notificationdiv').innerHTML="";
var totalcom = 10;
var comcasa = 3;
var comnt = 7;
for(var i = 0, size = rates.rates.length; i < size ; i++) {
if (amount > parseFloat(rates.rates[i][0])) {
totalcom = rates.rates[i][1] + rates.rates[i][2];
comcasa = rates.rates[i][1];
comnt = rates.rates[i][2];
}
}
//https://api.binance.com/sapi/v1/capital/deposit/address
commission = parseFloat((parseFloat(amount)*parseFloat(totalcom))/parseFloat(100)).toFixed(0);
commissionCasa = parseFloat((parseFloat(amount)*parseFloat(comcasa))/parseFloat(100)).toFixed(0);
commissionNT = parseFloat(parseFloat(commission)-parseFloat(commissionCasa)).toFixed(0);
payout = parseFloat(parseFloat(amount) - parseFloat(commission)).toFixed(0);
mycontent="";
document.getElementById('selldiv').innerHTML = "";
mycontent += "Amount of "+coin+" to send: " + btctotal.toString();
mycontent += "<br>Commission in dollars: " + commission + " (Casa:" + commissionCasa + ")(NT/fees:" + commissionNT + ")";
mycontent += "<br>Payout in dollars: " + payout;
document.getElementById('selldiv').innerHTML = mycontent;
document.getElementById("sellQR").innerHTML = "";
var elem = document.createElement("img");
elem.setAttribute("src", "https://chart.googleapis.com/chart?chs=250x250&chld=L|2&cht=qr&chl="+coin1+":"+address+"?amount="+btctotal);
elem.setAttribute("height", "250");
elem.setAttribute("width", "250");
document.getElementById("sellQR").appendChild(elem);
document.getElementById('sellQR').innerHTML += "<br>"+coin2+" deposit address: " + address + "<br>";
mycontent=mycontent.replace(/<br>/g,"%0A");
mycontent+="%0A"+coin2+" deposit address(client sent here): " + address;
mycontent+="%0ABinance/exchange "+coin2+" bid price: " + binancedata;
mycontent+="%0A%0A"+"Cashier's contract address: " + registeredemails[web3.utils.sha3(document.getElementById('emailcasa').value.toLowerCase())];
mycontent+="%0A"+"NT to send " + (parseFloat(payout) + parseFloat(commissionCasa)).toString() + " to cashier contract";
globcontent = mycontent;
quoted = 600;
clearInterval(interval);
interval = setInterval(clearfields, 600000);
}
ourRequest.send();
}
function clearit() {
if (confirm("Are you sure you want to clear everything?")) {
clearfields();
}
}
function clearfields() {
document.getElementById('sellamount').value = "";
document.getElementById('selldiv').innerHTML = "";
document.getElementById("sellQR").innerHTML = "";
document.getElementById('timerdiv').innerHTML = "";
document.getElementById('emailreceipt').value="";
document.getElementById('notificationdiv').innerHTML="";
document.getElementById('custombid').value="";
quoted = 0;
globcontent = "";
}
interval = setInterval(clearfields, 600000);
function quotetime() {
if (quoted != 0) {
quoted -= 1;
document.getElementById('timerdiv').innerHTML = "Seconds until quote expires: " + quoted;
}
}
setInterval(quotetime, 1000);
function email() {
window.location.href = "mailto:afmhahn@gmail.com,"+document.getElementById('emailreceipt').value+"?subject=NightTrader OTC notification&body="+globcontent;
document.getElementById('emailreceipt').value="";
}
</script>
</html>